Are XHTML tags valid in HTML?

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

I know that you cannot use the above HTML tag in an XHTML document, but what about the other way around? Is <br /> valid in HTML?

+6
source share
4 answers

It depends on the version of HTML you are talking about.

In the latest stable version of HTML 4.01, the syntax means the same as <br>> , which means the same as <br>&gt; . This means that it is valid, since you can have > anywhere, you may have a line break (although <meta /> usually not valid), but it does not mean that you want. Limitations in browsers (used by the XHTML 1.0 specification) mean that it is treated as <br> , although this should not be. The clutter around this function means that it is marked as to be avoided .

HTML 5 changes the meaning and turns / into syntactic sugar. It’s completely pointless, but XML addicts are allowed to be happy.

+4
source

<br /> backward compatibility and will not cause processing problems if used in an HTML document.

Also, note that if you are not using your documents with the MIME type application/xhtml+xml , placing <br> in an XHTML document will not suppress it. This is a validation error to leave BR not closed in the XHTML document, but very minor, which is unlikely to cause any problems on its own.

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

+2
source

<br /> valid HTML. Some HTML pages can be generated by an XML engine that cannot outpout <br> , and as such it should be able to parse it.

+1
source

Yes XHTML is compatible with HTML.

I believe that in HTML5 there is one exception that handles instructions like <?xml...> are deprecated.

+1
source

Source: https://habr.com/ru/post/894638/


All Articles