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>>
. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With