-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allow div elements in h1, h2, h3, h4, h5, h6 elements #6503
Comments
The difference between span and div is subtle and sometimes not very principled; maybe if we were designing HTML4 over from scratch there would only be a single one. But, since there is a difference, you should use span for this: it's precisely meant for breaking up text inside of flow content like headings. Using CSS to make the span display: block is not a hack; it's just expressing that stylistically, you'd like these things on separate lines, even if semantically they are both part of the heading. |
Another standard (more descriptive) way to achieve what seems to be your original goal: <hgroup>
<h2>Beans are disgusting</h2>
<h3>This is why we forbid beans</h3>
</hgroup> The heading rank of the |
Thanks @dpk , I did understand that hgroup has poor support in assistive technology and I want to improve the experience for people with AT, and don't want to introduce new issues. (Cry!) |
@domenic Thank you for your answer! You say there is a difference, could you explain more of what it is that makes using a div in a h2 a bad idea? (Not trying to push something, I genuinely want to understand :) ) |
It's kind of by definition. The definition of "div" is "a generic container that isn't appropriate to put inside flow content like headings". Whereas the definition of "span" is "a generic container that is appropriate to put inside flow content like headings". Like I said above, it's not clear how useful this distinction is, but it does exist, so we might as well follow it. |
Okay, thank you for answering @domenic . I have to be honest, it feels a little bit like a "just because" thing and I was hoping for reasoning that explains why (and a clearer why not). I don't want to be like the ever-asking why five year old, .. but I guess I am 😂 Hoping someone else sees this and can give an answer, otherwise I'll close this (if it doesn't auto-close first) |
Historically there were inline- and block-level elements and |
Hello!
I've been having a discussion with colleagues about using
div
elements inh-elements
(h1, h2, h3...), when it makes sense to style parts of the header differently, even though the content belongs together (and should not, for good reasons, become two seperateh-elements
). Here is an example.I have just learned that a
span
within ah-element
is allowed:But, to force a line break between the two, I would either have to add a
<br />
ordisplay: block
to thespan
elements, and that feels counter-intuitive when there is a working solution already that makes those things unnecessary.I would love to hear the reasons why example A is not allowed, and why example B is! :-)
And/or, if this can be discussed to make a change in the spec.
Addendum: I got linked info about the hgroup element, which is great, but I understand it is not yet supported by assistive technology, which is why I wanted to do this in the first place. (sadface)
With the highest regards,
Anneke
The text was updated successfully, but these errors were encountered: