简体   繁体   中英

Are XHTML tags valid in HTML?

I understand a line break in HTML is <br> and the XHTML equivalent is <br /> .

I know that you cannot use the above HTML tag in a XHTML document, but what about vice versa? Is <br /> valid in HTML?

It depends which version of HTML you are talking about.

In the latest stable version, HTML 4.01 , the syntax means the same as <br>> which means the same as <br>&gt; . This means it is valid, since you can have a > anywhere you can have a line break, (although <meta /> usually isn't valid) but doesn't mean what you want. Limitations in browsers (exploited by the XHTML 1.0 spec) mean that it gets treated as <br> even though it shouldn't be. The mess around this feature means it is marked as to be avoided .

HTML 5 changes that and turns the / into syntactic sugar. Utterly meaningless but allowed so the XML junkies are kept happy.

<br /> is backwards compatible and will not cause rendering problems if used in an HTML document.

Also, note that unless you are serving your documents with the MIME type application/xhtml+xml , putting a <br> in an XHTML document won't cause it to choke. It is a validation error to leave a BR unclosed in an XHTML document, but a very minor one which is unlikely to cause any problems by itself.

EDIT: Oh yes, and in HTML5 the closing / is once again officially optional.

<br /> is valid HTML. Some HTML pages may be generated by an XML engine that can't outpout <br> , and as such it must be able to parse it.

Yes XHTML is compatible with HTML.

I believe there is one exception in HTML5 which is processing instructions like <?xml...> have been deprecated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM