by codedokode · 2y ago · 0 comments
<link rel="stylesheet" href="base.css" />
I often see such code and it seems that people simply don't know HTML and copy random garbage they found on the Internet. In the example above, the slash is simply ignored, but in this example the code will be parsed not as intended: <div/>
This is why you should read proper documentation or specification instead of blindly copying garbage code from Internet.MDN link: https://developer.mozilla.org/en-US/docs/Glossary/Void_eleme...
It is supported in HTML5.
https://html.spec.whatwg.org/multipage/syntax.html#start-tag...
> ... if the element is one of the void elements ... then there may be a single U+002F SOLIDUS character (/) (at the end of the element, before the closing bracket)
https://html.spec.whatwg.org/multipage/syntax.html#void-elem...
> Void elements: area, base, br, col, embed, hr, img, input, link, meta, source, track, wbr
--
> This is why you should read proper documentation or specification instead of blindly copying garbage code from Internet.
Physician, heal thyself :)
<div/>
And it will be interpreted as <div>, not as a pair of <div></div>.HTML just ignores the slash character, it doesn't support XML-style self-closing tags. HTML is not XML.
Self-closing tags with the trailing slash are absolutely supported by HTML5, in some circumstances.
Quoting the spec [1]:
> Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/), which on foreign elements marks the start tag as self-closing. On void elements, it does not mark the start tag as self-closing but instead is unnecessary and has no effect of any kind. For such void elements, it should be used only with caution — especially since, if directly preceded by an unquoted attribute value, it becomes part of the attribute value rather than being discarded by the parser.