Which tags are can be self closing and which ones must have a closing tag in XHTML 1.0 Strict?
Which tags are c开发者_JS百科an be self closing and which ones must have a closing tag in XHTML 1.0 Strict?
Example:
<br/>
<input />
Are there certain tags that must have a closing tag, can be self closing, or eigther way works in XHTML 1.0 Strict?
Every element, that’s content model is EMPTY
in the XHTML 1.0 Strict DTD (i.e. <!ELEMENT element-name EMPTY>
), is an empty element and “must either have an end tag or the start tag must end with />
.” Namely it’s base
, meta
, link
, hr
, br
, param
, img
, area
, and input
. Every other element must have an end tag.
You are asking about "EMPTY Elements" including <hr /> <input /> <img /> <meta /> <link />
which can all be closed in a single tag. Non-empty elements which should contain text or sub-elements could technically be closed this way if they have no child or text but you are not supposed to do it. For example <p></p>
should not be <p />
but that could pass strict validation.
http://www.w3.org/TR/xhtml1/#guidelines
精彩评论