13

By empty I mean the following:

<link rel="stylesheet" href="reset.css" type="text/css" />

Been using XHTML transitional for several years now - and to validate properly the trailing /> is required for elements that do not contain other elements. Is this required for a valid HTML5 document?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
leepowers
  • 37,828
  • 23
  • 98
  • 129
  • Almost-but-not-quite a dup of [Are self-closing tags valid in HTML5?](http://stackoverflow.com/q/3558119) – outis Sep 30 '13 at 18:19

1 Answers1

18

No, it is not required.

http://dev.w3.org/html5/html-author/

Some elements, however, are forbidden from containing any content at all. These are known as void elements. In HTML, the above syntax cannot be used for void elements. For such elements, the end tag must be omitted because the element is automatically closed by the parser. Such elements include, among others, br, hr, link and meta

HTML Example:

<link type="text/css" rel="stylesheet" href="style.css">

In XHTML, the XML syntactic requirements dictate that this must be made explicit using either an explicit end tag, as above, or the empty element syntax. This is achieved by inserting a slash at the end of the start tag immediately before the right angle bracket.

Example:

<link type="text/css" href="style.css"/>

Authors may optionally choose to use this same syntax for void elements in the HTML syntax as well. Some authors also choose to include whitespace before the slash, however this is not necessary. (Using whitespace in that fashion is a convention inherited from the compatibility guidelines in XHTML 1.0, Appendix C.)

Community
  • 1
  • 1
ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • Note: The section "3.2.2.2 Void Elements" of that page is also relevant; in short it specifies those tags which must be empty (`hr`, `br`, etc.) MAY use a self-closing tag (e.g. `
    `, and SHOULD NOT (though it's legal in XHTML syntax) use a separate closing tag (e.g. `
    `). It's not entirely clear to me whether "link" is a void element, though I imagine in section "3.2.2.8 HTML and XHTML Comparison", the self-closing tag would be allowed because this probably(?) qualifies as one of the "foreign content elements".
    – lindes Jul 19 '13 at 19:06