| ▲ | phyzix5761 6 hours ago |
| 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. |
|
| ▲ | notnullorvoid 3 hours ago | parent | next [-] |
| 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. |
|
| ▲ | philo23 6 hours ago | parent | prev | next [-] |
| 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_ 5 hours ago | parent | prev | next [-] |
| 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 |
|
| ▲ | 6 hours ago | parent | prev | next [-] |
| [deleted] |
|
| ▲ | Tomte 6 hours ago | parent | prev | next [-] |
| Yes: https://html.spec.whatwg.org/multipage/grouping-content.html... |
|
| ▲ | moron4hire 4 hours ago | parent | prev [-] |
| Custom-named elements are divs. |
| |
| ▲ | phyzix5761 4 hours ago | parent | next [-] | | They're not as you can see here[1] and here[2]. They both inherit from the HTMLElement interface but div is considered an HTMLDivElement which makes it distinct from a custom element. <my-element> != <div> [1] https://developer.mozilla.org/en-US/docs/Web/API/Web_compone... [2] https://developer.mozilla.org/en-US/docs/Web/API/HTMLDivElem... | | |
| ▲ | moron4hire 2 minutes ago | parent | next [-] | | HTMLDivElement has no properties or methods not inherited from HTMLElement. If you inspect the user-agent stylingnof div versus any non-standard named element, you'll see that they have the same styling path. The use of HTMLElement for the non-standard elements is to support future additions to the standard elements and enable subclassing down-tree instead of across-tree, which is noted in the spec. | |
| ▲ | 3 hours ago | parent | prev [-] | | [deleted] |
| |
| ▲ | jazzypants 4 hours ago | parent | prev | next [-] | | Exactly! It cracks me up when people name-check "semantic elements" when it doesn't actually mean anything in that context. Accessibility software doesn't understand the semantics of your custom elements, so there is no benefit in that situation whatsoever. Maybe it's easier for you to read and edit in the future, but that's it. Somehow, people got convinced that <div> elements are evil and should never be used no matter what. Yes, you should use a more semantic element when it makes sense, but try to remember what that phrase actually means. | | |
| ▲ | phyzix5761 4 hours ago | parent [-] | | I use it for readability and to express intention and meaning to the reader of my program. In the age of AI, perhaps, we've lost the need for that. But it was much appreciated in times before by those who came upon my code. | | |
| |
| ▲ | 4 hours ago | parent | prev [-] | | [deleted] |
|