Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

“a start tag must never be omitted if it has any attributes” #10691

Open
j9t opened this issue Oct 10, 2024 · 10 comments · May be fixed by #10752
Open

“a start tag must never be omitted if it has any attributes” #10691

j9t opened this issue Oct 10, 2024 · 10 comments · May be fixed by #10752

Comments

@j9t
Copy link
Contributor

j9t commented Oct 10, 2024

What is the issue with the HTML Standard?

§ 13.1.2.4 (optional tags) states that

[…] a start tag must never be omitted if it has any attributes.

If this refers to an esoteric use case (any that come to my mind look like like they would be treated as text), it would be helpful to give a brief example and provide more detail.

If there’s no practical way to set attributes without a start tag (which it looks like), it seems this could be skipped? (Happy to file a PR.)

@annevk
Copy link
Member

annevk commented Oct 11, 2024

I don't think this can be skipped, because the other conditions are not conditional upon the element not having attributes.

@j9t
Copy link
Contributor Author

j9t commented Oct 11, 2024

I had to read that statement a few times and am not sure I understand 🙂

Maybe taking a step back, how can one omit a start tag that has attributes, if attributes can only be set on start tags?

From going over the section it doesn’t look like it wouldn’t work without the sentence (or some rephrasing to make clear what omitting a start tag means in the context of attributes being present).

Even if this was to miss something, the spec might get clearer by explaining it to everyone.

@annevk
Copy link
Member

annevk commented Oct 11, 2024

Given this statement:

A head element's start tag may be omitted if the element is empty, or if the first thing inside the head element is an element.

It's not at all clear that this only applies when the head element has no attributes. That's what that final statement is for.

@j9t
Copy link
Contributor Author

j9t commented Oct 11, 2024

Thanks for sharing more context. I’m still not clear about the value of the sentence in question (which humbly includes I might just not get something), but if it’s important to make head element handling clear, how about adding a qualifier right there?

Like, “A head element’s start tag may be omitted if the element has no attributes, is empty, or if the first thing inside the head element is an element.” (if that’s what this is referring to)?

@annevk
Copy link
Member

annevk commented Oct 11, 2024

Sure, but then we'd have to add that clause for each element whose start tag may be omitted. Instead we use a catch-all clause at the end.

@j9t
Copy link
Contributor Author

j9t commented Oct 11, 2024

It sounded like this was just to be extra sure about the head element.

There’s still the question how authors would omit a start tag if there are attributes on it, also given that attributes can only be set on start tags.

Assuming it’s possible or likely, how about two adjustments:

  1. Rephrase the note as something more informal, like “Note that a start tag cannot and must not be omitted if it has any attributes.”

  2. Move the note up to come before the examples, and in closer proximity to the other statements (right after “A th element's end tag may be omitted…”).

If I understood you right, that could meet the spirit of the sentence while making the section a bit more easier to read.

@sideshowbarker
Copy link
Contributor

I think Jens is right: that statement as currently written isn’t correct. The actual intent of the requirement regards whether the start tag’s element has attributes — not about whether the start tag itself does. The problem with the text are currently written is the word “it”, which incorrectly refers to the start tag itself. So I’ve raised #10752 with an attempt at fixing that.

@j9t
Copy link
Contributor Author

j9t commented Nov 8, 2024

(Love the proactive PR!)

The actual intent of the requirement regards whether the start tag’s element has attributes — not about whether the start tag itself does.

More of a side note but would love to learn—have I been missing something here, am I not seeing the forest for the trees? How can an author omit a start tag—or an element—that has attributes?

Anne’s and your response both seem to indicate that it’s possible, but I don’t understand it—I’d appreciate if someone could explain, especially when I’m missing something obvious. I only see something like < attribute=value> (or, more interesting but also more esoteric, </ attribute=value>), which seems nonsensical but also sufficiently described in the spec and handled by every browser (leading to a text node, IIRC) not to warrant calling out not to do it. I feel like I’m losing my mind over this 😂

(While I conceded earlier when Anne suggested this was just about the head element, that didn’t actually make it clear to me, either.)

Thanks!

@tabatkins
Copy link
Contributor

The phrasing is a little odd, but it's talking about what transformations you can perform without changing the resulting DOM (and which ones you can't, because it would result in a change). For example, you can omit the html start tag if its first child isn't a comment, because you'll get the same DOM back (but if the first child is a comment, omitting the start tag would cause the comment to parse as a sibling of the html instead).

Similarly, you can't omit a start tag if it has attributes (because the resulting DOM will then lack those attributes).

@j9t
Copy link
Contributor Author

j9t commented Dec 7, 2024

I’ve reached out directly to three peers (some on the thread) but, unfortunately, couldn’t get to more clarity off-thread. (Still, many thanks for the feedback on and off the thread!)

Here’s the best I can currently summarize the issue:

The way the spec and previous responses put it, there are actually two readings of “[…] a start tag must never be omitted if it has any attributes”:

  1. It’s possible to remove a start tag, but retain its attributes.
  2. It’s not possible to remove a start tag without also losing its attributes.

What’s more, this could come with different motivations:

  • Related to 1., the motivation for the spec to call this out to avoid parsing issues. (This seems dramatic, and worth expanding on.)
  • Related to 2., the motivation for the spec to make clear that more would change than just removing a containing element, and that it also affects any attributes defined. (As this is observable when removing just a start tag, but not its attributes [< attribute=value>], in an HTML document, this seems trivial, and hence suggested it may be worth dropping.)

I understand the spec so that the case is 2.—but the way the sentence is phrased, it seems it’s saying 1. (which had me wonder and file this issue).

To avoid ambiguity, the wording benefits from being tweaked—it’s probably a small edit, that with some reordering (bring the statement closer to the other “may or may not be omitted” statements) could make the section clearer and easier to read.

If this is hard to explain and resolve because it’s clear to “everyone else,” I hope this shows how it can be understood differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants