Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 empty elements

Tags:

html

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?

like image 345
leepowers Avatar asked Nov 29 '10 02:11

leepowers


1 Answers

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.)

like image 108
ceejayoz Avatar answered Sep 27 '22 21:09

ceejayoz