logoalt Hacker News

phyzix5761today at 1:51 PM6 repliesview on HN

I'm curious if the spec actually says you can only wrap it with a div because I like to do semantic html and name my elements specific to my domain.


Replies

notnullorvoidtoday at 4:16 PM

As others have noted only the div is allowed. This isn't a unique situation either, the HTML spec despite being lenient in syntax is quite restrictive in behavior. It's unfortunate that XHTML (and XML parsing) didn't become the default as it's the opposite, more restrictive syntax, but lenient behavior.

For example in XHTML you can use custom elements as table rows or cells (provided you give them the correct role and CSS display property). This is because XHTML does not modify the tree during parsing, unlike HTML which will hoist out custom element children of the table to the table's parent.

philo23today at 1:54 PM

Yep, I was a little surprised about that too, seem like it is valid though https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/...

wonger_today at 1:57 PM

Seems like div is the only recommended wrapper element:

https://html.spec.whatwg.org/multipage/grouping-content.html...

https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/...

EDIT everyone replied at once lol. I'm surprised too about div.

Also, screen reader support: https://a11ysupport.io/tech/html/dl_element

moron4hiretoday at 3:14 PM

Custom-named elements are divs.

show 3 replies