html - mdn - what does<br/> mean
HTML 5: Is it<br>,<br/>, or<br/>? (16)
If you are outputting HTML on a regular website you can use
<br/>, both are valid anytime you are serving HTML5 as text/html.
If you are serving HTML5 as XHTML (i.e. content type application/xhtml+xml, with an XML declaration) then you must use a self closing tag like so:
If you don't the some browsers may flat out refuse to render your page (Firefox in particular is very strict about rendering only valid xhtml+xml pages).
As noted in 1.
<br/>is also valid for HTML5 that happens to be generated as XML but served as a regular text/html without an XML declaration (such as from an XSL Transform that generates web pages, or something similar).
To clear up confusion: Putting a space before the slash isn't required in HTML5 and doesn't make any difference to how the page is rendered (if anyone can cite an example I'll retract this, but I don't believe it's true - but IE certainly does a lot of other odd things with all forms of
The excellent validator at http://validator.w3.org is really helpful for checking what's valid (although I'm not sure you can rely on it to also check content-type).
I thought HTML 4.01 was supposed to "allow" single-tags to just be
<br>. Then XHTML came along with
<img /> and
<br /> (where someone said that the space is there for older browsers).
Now I'm wondering how I'm supposed to format my code when practicing HTML 5.
<br /> render differently in some browsers, so choosing either over the other isn't going to hurt your project, but do expect a bulk find..replace to affect the page render in some browsers, which may result in extra work for yourself or even embarrassment should the change affect nothing in your test browser, but break it in the preferred browser of your clients'.
<br> since it is what I have used since Erwise and Netscape Navigator (early web browsers), but there's no reason not to choose
<br /> instead. It may be useful for some preprocessing, comparability, etc.
Even if your choice boils down to preferring the look of one over the other, or you (or your favourite HTML editor e.g. Dreamweaver) might like your code to be xml compliant. It's up to you.
A quick side note:
Not to be confused with
br, but in addition you may also consider using
wbr tags in your HTML: A word break opportunity tag, which specifies where in a text it would be ok to add a line-break.
For further reading, please have a read of the HTML5 spec.
To quote Section 126.96.36.199 of HTML 5.2 W3C Recommendation, 14 December 2017
Start tags must have the following format:
After the attributes, or after the tag name if there are no attributes, there may be one or more space characters. (Some attributes are required to be followed by a space. See §188.8.131.52 Attributes below.)
Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/). This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.
If you use Dreamweaver CS6, then it will autocomplete as
To validate your HTML file on W3C see : http://validator.w3.org/
<br> works just fine. The stricter versions like XHTML require you to add the closing, and really old versions of HTML that do not include a
<br> a non-void tag, like
<br> is fine. Other ones are also just fine.
As many others have covered, both
<br/> are acceptable.
I guess the tradeoff is the better readability and backward compatibility of
<br/> versus sending one less character to the end users with
And since Google uses
<br> so will I.
(Of course keep in mind that they might be serving me
<br> because I'm using Chrome which they know supports it. In IE they might still be serving
<br /> are acceptable in HTML5, but in the spirit of HTML,
<br> should be used. HTML5 allows closing slashes in order to be more compatible with documents that were previously HTML 4.01 and XHTML 1.0, allowing easier migration to HTML5. Of course,
<br/> is also acceptable, but to be compatible with some older browsers, there should be a space before the closing slash (
I think this quote from the HTML 5 Reference Draft provides the answer:
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
<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.
<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.)
I would recommend using <br /> for the following reasons:
1) Text and XML editors that highlight XML syntax in different colours will highlight properly with <br /> but this is not always the case if you use <br>
2) <br /> is backwards-compatible with XHTML and well-formed HTML (ie: XHTML) is often easier to validate for errors and debug
3) Some old parsers and some coding specs require the space before the closing slash (ie: <br /> instead of <br/>) such as the WordPress Plugin Coding spec: http://make.wordpress.org/core/handbook/coding-standards/html/
I my experience, I have never come across a case where using <br /> is problematic, however, there are many cases where <br/> or especially <br> might be problematic in older browsers and tools.
If you're interested in comparability (not compatibility, but comparability) then I'd stick with
<br> is fine.
In HTML5 the slash is no longer necessary:
<br> and in XHTML
I will suggest you to use
In validation, of this question, it really depends on what
!DOCTYPE you are trying to get verification through.
My personal favorite is
4.01 Trans where I just use the
<br/> and it clears the warnings and errors that may have popped up during validation
Strict is a much more complicated beast, It HATES
"SHORTTAGS" and quite literally only wants the
HTML5 or the "LAX" of the code world, there really isn't a right answer because it
detects every example you put up there as correct......
In the end, I think all that matters
is what validation YOU PREFER or
the person that you are working for prefers... with the
lackadaisical movement in code strictness in
html5 we are seeing some VERY LAZY CODERS
<br> is sufficient.
The other forms are there for compatibility with XHTML; to make it possible to write the same code as XHTML, and have it also work as HTML. Some systems that generate HTML may be based on XML generators, and thus do not have the ability to output just a bare
<br> tag; if you're using such a system, it's fine to use
<br/>, it's just not necessary if you don't need to do it.
Very few people actually use XHTML, however. You need to serve your content as
application/xhtml+xml for it to be interpreted as XHTML, and that will not work in old versions of IE - it will also mean that any small error you make will prevent your page from being displayed in browsers that do support XHTML. So, most of what looks like XHTML on the web is actually being served, and interpreted, as HTML. See Serving XHTML as text/html Considered Harmful for some more information.
The elements without having end tags are called as empty tags. In html 4 and html 5, end tags are not required and can be omitted.
In xhtml, tags are so strict. That means must start with start tag and end with end tag.
Well all I know is that
<br /> gives a break with a white line and
<br> just gives a break in some cases. This happened to me when I was setting up an IPN-script (PHP) and sent mails and checked the inbox for it. Dont know why but I only got the message to look neat using both
<br /> and <br>
Have a look at the mail here: http://snag.gy/cLxUa.jpg
The first two sections of text is seperated by
<br />, hence the whitespace lines, the last three rows of text in the bottom and the last section is seperated by
<br> and just gives new row.
XML doesn't allow leaving tags open, so it makes
<br> a bit worse than the other two. The other two are roughly equivalent with the second preferred for compatibility with older browsers. Actually, space before
/ is preferred for compatibility sake, but I think it only makes sense for tags that have attributes. So I'd say either
<br />, whichever pleases your aesthetics.
To sum it up: all three are valid with the first one being a bit less "portable".
Edit: Now that we're all crazy about specs, I think it worth pointing out that according to dev.w3.org:
Start tags consist of the following parts, in exactly the following order:
- A "<" character.
- The element’s tag name.
- Optionally, one or more attributes, each of which must be preceded by one or more space characters.
- Optionally, one or more space characters.
- Optionally, a "/" character, which may be present only if the element is a void element.
- A ">" character.