By Eikern


2009-12-22 13:39:08 8 Comments

I've tried checking other answers, but I'm still confused — especially after seeing W3schools HTML 5 reference.

I thought HTML 4.01 was supposed to "allow" single-tags to just be <img> and <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.

Is it <br>, <br/> or <br />?

25 comments

@PythonMaster202 2019-12-25 11:19:11

It is just <br>, as it doesn't have a closing tag - search google this question: 'does<br> have a closing tag?'

@Kmeixner 2014-01-16 17:43:42

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.

@jmarkmurphy 2018-03-22 13:33:33

Well formed HTML is not XHTML.

@Kmeixner 2018-03-23 14:44:59

XHTML is well-formed HTML by definition. XHTML follows the rules of XML, according to w3schools "XML is a markup language where documents must be marked up correctly (be "well-formed")... ...By combining the strengths of HTML and XML, XHTML was developed. XHTML is HTML redesigned as XML." (see w3schools.com/html/html_xhtml.asp)

@jmarkmurphy 2018-03-23 19:32:30

HTML can be well formed, but not be valid XML. W3Schools isn't always the most authoritative reference.

@Kmeixner 2018-03-23 19:50:30

The professor of the university computer science course on web programming I took in 1997 also made the claim that xhtml is well-formed html. I am not sure where you are getting your information from, can you cite any official sources online to backup your claim?

@jmarkmurphy 2018-03-23 20:10:04

<br> and <hr> are perfectly valid and well formed HTML. They are not valid XML tags. The HTML specs under HTML syntax says that void elements (like <br> or <hr>) may have a / character immediately preceding the final >. But it has no effect. It is ignored if it is there. If the / was a preferred piece of the syntax, the standard would say should rather than may.

@Kmeixner 2018-03-26 14:35:19

@jmarkmurphy, I think that maybe you are unfamiliar with the term "well-formed" being a technical jargon term to refer to the requirement to the standards of XML and XHTML that all tags must have closing tags and must be nested in the proper order. <hr> and <br> do not meet the requirements of XML and XHTML because they do not have closing tags, eg: <br /> or <br></br> are valid, <br> is not valid XHTML or XML. HTML, of course, does not have the well-formed requirement so <br> and <hr> are valid in HTML only.

@Daan 2009-12-22 13:44:51

I think this quote from the HTML 5 Reference Draft provides the answer:

3.2.2.2 Void Elements

The term void elements is used to designate elements that must be empty. These requirements only apply to the HTML syntax. In XHTML, all such elements are treated as normal elements, but must be marked up as empty elements.

These elements are forbidden from containing any content at all. In HTML, these elements have a start tag only. The self-closing tag syntax may be used. The end tag must be omitted because the element is automatically closed by the parser.

HTML Example:
A void element in the HTML syntax. This is not permitted in the XHTML syntax.

<hr>

Example:
A void element using the HTML- and XHTML-compatible self-closing tag syntax.

<hr/>

XHTML Example:
A void element using the XHTML-only syntax with an explicit end tag. This is not permitted for void elements in the HTML syntax.

<hr></hr>

@Eikern 2009-12-22 13:51:54

So, the answer is to code preferably without slash and space, but having the slash (with or without the space)--is optional?

@Matt Ellen 2009-12-22 14:02:26

I love the way the specification isn't particularly specific (on this point) "meh, do what you want!"

@BrunoLM 2010-07-13 12:12:00

Since it's optional, I like more the /> because it is good for the readability.

@Syntax Error 2011-03-03 04:49:47

I like explicitly closing my tags for no reason other than it feels right and makes sense when I'm reading/writing code. I'm pleased that the HTML5 Reference Draft agrees with me.

@William Denniss 2011-04-06 09:17:30

Seems quite specific to me. <br> and <br /> are both legal HTML5.

@1j01 2016-09-16 19:12:00

@Knickerless-Noggins "Differences Between HTML and XHTML: In HTML, the <br> tag has no end tag." That's not a difference though. That's true for both.

@Basil Bourque 2018-08-05 00:48:32

Really not so complicated: The slash character closing the single tag is proper syntax in XML. If you want to treat your HTML as XML, such as when using XML tooling, include the slash. If you don’t care about XML strictness, the slash is optional.

@Stephen J 2019-01-14 05:51:19

This is the only answer that brings up "what it does", and I think that's the right way to think about this. <br> is a leaf node on a tree that goes to the renderer through a parser. The HTML spec exists for translation of these things into a graphics-rendering. Therefore it just needs to know "enough" to create a breaking-line. Until breaking-lines do more than just indicate an infinite-small point to go to next line, it really doesn't matter if it has / or not, because the fact it is a leaf won't have ambiguity. We focus too much on specs, and forget "what it does" as coders.

@Michael Krelin - hacker 2009-12-22 13:42:04

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 (<br/>) 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/> or <br />, whichever pleases your aesthetics.

To sum it up: all three are valid with the first one (<br>) 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:

  1. A "<" character.
  2. The element’s tag name.
  3. Optionally, one or more attributes, each of which must be preceded by one or more space characters.
  4. Optionally, one or more space characters.
  5. Optionally, a "/" character, which may be present only if the element is a void element.
  6. A ">" character.

@tloach 2009-12-22 13:46:45

HTML is not actually XML, just pretty close to it.

@Michael Krelin - hacker 2009-12-22 13:48:43

Yes, it's not. But / is a common denominator here. HTML5 specifically allows the use of /: "Optionally, a "/" character, which may be present only if the element is a void element".

@helloworlder 2009-12-22 13:49:00

HTML is an actual markup language but XML isn't. You use XML to create languages such as RSS. Am I right? :P

@helloworlder 2009-12-22 13:49:50

You mean the XML specification is similar to the HTML specification?

@Michael Krelin - hacker 2009-12-22 13:50:49

helloworlder, I'd say that HTML5 specification is close to being XML-conformant.

@John Vincent 2014-09-27 09:27:59

I'd just like to add that on both XML and HTML the ML stands for Markup Language. The reason there is so much overlap between them is that they were both originally defined using SGML (Standardised Generalised Markup Language) but not many people remember it now...

@Benny Neugebauer 2015-03-10 20:09:43

I really like this answer here (and <br />). Imagine you have to write a regex or do a search within a HTML document, then it makes your life a lot more easier if all tags open and close properly.

@Michael Krelin - hacker 2015-03-11 07:35:14

@BennyNeugebauer, If you're using regex to parse html you are more or less left to rely on your luck rather than properly closed tags ;-)

@Basil Bourque 2018-08-05 00:52:14

@tloach HTML5 absolutely can be strictly-conforming XML if you so choose. See the HTML5 FAQ.

@krupal 2014-03-16 13:34:42

<br> is sufficient but in XHTML <br /> is preferred according to the WHATWG and according to the W3C.

To quote Section 8.1.2.1 of HTML 5.2 W3C Recommendation, 14 December 2017

Start tags must have the following format:

  1. 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 §8.1.2.3 Attributes below.)

  2. 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 <br />.

To validate your HTML file on W3C see : http://validator.w3.org/

@Basil Bourque 2018-08-05 01:23:52

@Julix Indeed, why the down-votes? Tthis is one of the few correct Answers on this page. HTML5 absolutely is XML conforming, optionally, and in XML syntax, a single tag must be closed with the slash. How can such simple facts be so misconstrued when written in black-and-white in the spec.

@Bhavin Solanki 2016-09-26 11:31:22

Most of the cases in HTML, the tags are in pair. But for a line break you don't need a pair of tags. Therefore to indicate this, HTML uses <br/> format. <br/> is the right one. Use that format.

<br> tag has no end tag in HTML In XHTML, the <br> tag must be properly closed, like this: <br />

In XML every tag must be closed. XHTML is an extension of XML, hence all the rules of XML must be followed for valid XHTML. Hence even empty tags (nodes without child nodes) like
should be closed. XML has a short form called self closing tags for empty nodes. You can write <br></br> as <br />. Hence in XHTML <br /> is used.

HTML is very lenient in this regard, and there is no such rule. So in HTML empty nodes like <br> <hr> <meta> etc are written without the closing forward slash.

HTML

<br>
<hr>
<meta name="keywords" content="">
<link rel="canonical" href="http://www.google.com/">

XHTML

<br />
<hr />
<meta name="keywords" content="" />
<link rel="canonical" href="http://www.google.com/" />

Not all tags can be self closed. For example, a tag like <script src="jQuery.min.js" /> is not allowed by XHTML DTD.

@isar 2018-01-15 14:00:46

IMHO it is better to use the regular notation (<br />) instead of the forgiving notation (<br>) for the following reasons:

Consistency

In your HTML there is probably some SVG and SVG only support the regular notation (e.g. <rect />).

Hackability

It is not a case that frameworks like React and NativeScript use an XML notation.
Your markup code will be easier to parse.

Clarity

The regular notation is easier to read and understand, even late at night.

Specifications

Both <br> and <br /> are valid HTML tags.

Conclusion

If you use a full-fledged text editor configure it to use the regular notation (which is called XHTML by Emmet).
For instance, in Visual Studio Code you just have to add the following line to your settings:

"emmet.syntaxProfiles": {"html": "xhtml"}

@Ilya Streltsyn 2018-02-25 08:30:33

Strictly speaking, they both are short notations: the HTML short notation and the XML short notation, respectively. The complete notation is <br></br>, and it is valid in X(HT)ML, but not in HTML.

@jmarkmurphy 2018-03-22 13:40:02

HTML5 did not introduce <br>. It has always be in HTML. XHTML introduced <br/>

@Michael Kay 2018-05-15 20:57:40

To go into the history of this properly you need to delve deeply into SGML.

@Mahesh Peri 2017-11-10 12:11:50

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.

@Basil Bourque 2018-08-05 01:34:23

Incorrect. A single-tag is just as valid in HTML5 as a start-end tag pair. See the HTML 5.2 spec.

@harold ramos 2017-06-23 20:10:00

In HTML5 the slash is no longer necessary: <br>, <hr>

@Rob 2017-11-27 21:38:18

The slash has never been necessary and has never been specified in any HTML spec or even used as an example in the spec.

@Basil Bourque 2018-08-05 01:10:10

@Rob I don’t know where you get your HTML specifications, but I get mine from the WHATWG and W3C organizations. Both publish specs that clearly define strict XML conformance as an optional feature of HTML5. This specifically includes closing single tags with />. See Sections 8.1.2.1 & 2. And see the HTML vs. XHTML document at whatwg.org, and the W3C Polyglot Markup: A robust profile of the HTML5 vocabulary at W3C.

@Rob 2018-08-05 03:12:21

@BasilBourque Please read the exact specification for those tags in HTML and do not bring up XML or XHTML which are not the subject here. You will never find any written wording or examples in any specification for HTML in the history of the internet where a closing slash is used, required or even suggested.

@Basil Bourque 2018-08-05 03:44:37

@Rob All I can do is repeat: W3C published a document called HTML 5.2 where Section 8.1.2.1. Start tags plainly says a self-closing tag with or with a slash is valid, in point # 6: 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. The other documents I linked explain that if expressing your HTML5 as XML, the slash is required.

@Rob 2018-08-05 11:55:50

@BasilBourque I never said it wasn't valid. I said it has no meaning and serves no purpose as you, yourself, quoted. And, again, you are bringing up XML as a justification to use it in HTML. Don't do that! They are not the same thing! We call that "tag soup" when the HTML parser needs to interpret XML content.

@Stokely 2017-05-17 19:23:25

Ummm.....does anyone know a SINGLE vendor, user-agent, or browser maker that has ever followed the W3C Specifications 100%??? So if HTML5 says it supports all three break element versions, you can bet the vendors support the same and even more sloppier versions!

The ONLY thing that matters in this debate is to CONSISTENTLY use coding that also happens to follow XML specifications as well as HTML specifications when possible. That means you should use the correct XML version of the break tag and encourage all your team to do the same:

<br />

The same space-slash format should apply for the img, a, hr, and meta tags in your code. Why? Because:

  1. Its is backwards compatible with older XHTML user-agents / browsers
  2. The browser vendors support the XML version anyway so the HTML5 specification is moot.
  3. The sloppy implementations of most user-agents today, in the past, and in the future will accept it.
  4. It allows your markup to be comparable with XML standards should you need to go back to creating XHTML/XML documents from your markup.
  5. It's "good coding practice" for ALL WEB DEVELOPERS to keep using solid markup practices that follow XML, including coding in all lower case, quoted attributes, escaped XML characters, etc. etc. Why? In the future if you have to switch to XML data you automatically code and think in XML.
  6. We can only hope that in the future World Wide Web, we move away from private vendor-implemented standards and go back to solid, reliable, verified markup that parses faster, moves data over the wires faster, and make our future Internet a more standardized medium using XML.

Besides, in the robotic and machine world that's here, where robots don't have the same Human-interface coding problems HTML5 solves for us, they will gladly go back to XML data systems and parse such UI web pages much faster when converted to XML data.

@Slow Poke 2016-10-16 16:12:27

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 <br></br>

In 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

@Aravind Suresh 2016-09-02 16:30:37

<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 DOCTYPE make <br> a non-void tag, like <br></br>.

Sum up: <br> is fine. Other ones are also just fine.

@Shubham Kumar 2016-07-09 21:36:25

In HTML <br> and in XHTML <br/>.

I will suggest you to use <br/>.

@Dan Bray 2016-02-28 01:18:55

Both <br> and <br/> will do fine but I prefer <br/> because it's slightly more logical. It is logical to expect a closing tag whenever there is an opening tag. Therefore your code is slightly easier to read if you don't use an opening tag when there isn't going to be a closing tag.

All browser (except possibly some very old ones that don't matter) will display both exactly the same. However, <br> is not xHTML complient.

@Brian Campbell 2009-12-22 13:42:26

Simply <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.

@Michael Krelin - hacker 2009-12-22 13:52:42

But having a valid xml doesn't imply serving xhtml, anyway. It may be useful for all kinds of local preprocessing.

@Brian Campbell 2009-12-22 14:01:56

Yes, but you have to be very careful processing HTML as XML. They are different languages, and only a subset of each is compatible. For instance, in XML, <br/> is the same as <br></br>, but the latter is not valid HTML.

@Michael Krelin - hacker 2009-12-22 14:37:33

Brian, the idea was that you can have your html be well-formed xml, that's it. Of course when transforming one into another you have to make sure it's still valid, but is it worth mentioning? :)

@Brian Campbell 2009-12-22 14:45:05

Oh, of course. It is useful to be able to have documents that are also well-formed XML; I'm not denying that. But it's not necessary, and you need to put more effort in than just self-closing tags to make it valid, and have the same interpretation in XHTML and HTML.

@Michael Krelin - hacker 2009-12-22 15:32:41

Neither I deny it's being unnecessary ;-) And yes, there are more efforts, but those are beyond the scope of present narration ;-)

@Chuck Le Butt 2010-07-19 15:20:33

XHTML is still useful for creating "clean" HTML (properly nested elements, case sensitive, stricter syntax, etc.). The complaints about it being "harmful" are massively overblown IMO, and, contrary to the "Considered Harmful"'s recommendation, I'd use XHTML over the unfinished HTML5 spec any day (well, until the HTML 5 spec is finalised and supported anyway).

@Marco Demaio 2010-08-17 16:22:01

+1 for great answer, IMHO, XHTML is useful only to make coders crazy finding performance-inefficient ways around the great and fast Javascript document.write and innerHTML functions that can not be used anymore in XHTML.

@Marco Demaio 2011-02-17 14:58:23

@Charles Boyung: instead of being so rude you could explain your point. Moreover I said: "IMHO". I hate all those idious <br /> in XHTML document! I'm really sorry for you that HTML5 is gonna be the next web language in place of XHTML, but you can still enjoy using XHTML and go on adding 2 chars more on each <br> just to make your web files bigger.

@Michael0x2a 2012-03-03 15:44:06

@Marco I don't think document.write is terribly fast in comparison to actual (x)html (because it has to be executed). In any case, Javascript isn't necessarily available on all computers so websites that excessively rely on them aren't very flexible. Also, html doesn't have functions.

@Marco Demaio 2012-03-05 19:06:13

@Deflect: I didn't say document.write is faster than XHTML I don't know and never thought to compare them for performance. I just want to go on using document.write and simple <br> and from my understanding of XHMTL I can not. Beside the fact that a site that uses document.write can't be called a site that excessively relies on JS, in nowadays thinking at a webapp w/o using JS is like thinking to use a a car w/o the engine.

@Michael0x2a 2012-03-06 08:01:31

@Marco: Huh, I didn't know document.write doesn't work in xhtml -- thanks for sharing. I agree that it'd be silly for webapps to try and do anything without Javascript, but I was trying to say that websites that rely almost 100% percent on Javascript are more brittle and can fail when users disable javascript (or are using older phones or something)

@WonderWorker 2014-05-22 13:21:55

Please cite your source for 'Very few people actually use XHTML': Every single web designer and programmer that I know conforms to XHTML.

@Marco Alka 2014-05-24 16:07:59

@Knickerless-Noggins: Take a look around the www! A lot of pages use XHTML, a lot of pages use HTML(4). But recently, most pages I visit use HTML5 without XHTML flavor. Imo, the XHTML flavor is dying because of HTML5's "don't care". It's easier and less typing to do it the HTML way and will still look the same. But honestly, why do you even care? It's a matter of preference nowadays, nothing more. Me as a web developer can read both. You should be able to, too. No problem w/e.

@WonderWorker 2014-06-11 11:46:23

@Marco Alka I'm not sure why your argument is directed at me, because I do read both. Furthermore, I already use HTML5, but it doesn't mean that it's what everyone uses. I am privileged enough to use a modern Visual Studio that doesn't automatically replace <br> with <br />. Not everyone is and that's why they stick to what they know.

@Marco Alka 2014-06-11 22:15:29

@Knickerless-Noggins it is directed at you because you said that everyone you know uses XHTML. Side note: I prefer NetBeans although I own a VS2013 Ultimate. NB doesn't do anything on it's own - just the way it should be for a good editor :)

@Brian Campbell 2014-06-11 23:06:28

@Knickerless-Noggins As I specified in my answer, in order for a page to be interpreted as XHTML by browsers, you must send it with Content-Type: application/xhtml+xml. That didn't work in IE 8 and earlier (which was the latest IE when I wrote this answer 5 years ago), so anyone who did that would have a site that didn't work in IE. That means that they weren't actually using XHTML; they were writing pages that used the intersection of XHTML and HTML, and having them interpreted as HTML, so for all practical purposes they are using HTML.

@Sawtaytoes 2016-02-03 16:21:03

Which versions of IE count as "old versions of IE" where xhtml+xml won't work?

@Brian Campbell 2016-02-04 05:15:47

@Sawtaytoes IE 8 and earlier, according to caniuse.com

@Miguel Felipe Guillen Calo 2017-08-31 10:39:03

When inserting html tags in strings for localization, it's best to use <br />. But only if your localization is stored in an xml formatted file, in my current case, xtb.

@Franz D. 2018-04-24 14:38:23

That "considered harmful" essay is funny. There's the author saying "In the main, however, it often seems that “considered harmful” essays get written simply because an author can’t think of a better way to express his point of view. This is a sad commentary on both the authors in question and the level of debate most often present in our societies." And there he is writing his 'considered harmful' essay xD

@WonderWorker 2014-03-17 13:19:35

<br> and <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'.

I prefer <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.

@kevinji 2014-06-20 02:11:39

See the HTML5 spec, which clearly states that "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) character. [emphasis added]" <br>, of course, is a void element, as you can see in the link in the quote.

@MindStalker 2009-12-22 13:45:54

If you're interested in comparability (not compatibility, but comparability) then I'd stick with <br />.

Otherwise, <br> is fine.

@Josiah 2015-09-04 20:56:15

Someone should roll this back. The meaning is changed.

@tuxayo 2017-06-29 15:21:19

What is meant by comparability? I don't get it.

@Dimitris 2014-06-25 14:08:30

As many others have covered, both <br> and <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 <br>.

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/>)

@JackDev 2013-12-30 05:40:35

In HTML (up to HTML 4): use <br>

In HTML 5: <br> is preferred, but <br/> and <br /> is also acceptable

In XHTML: <br /> is preferred. Can also use <br/> or <br></br>

Notes:

  • <br></br> is not valid in HTML 5, it will be thought of as two line breaks.
  • XHTML is case sensitive, HTML is not case sensitive.
  • For backward compatibility, some old browsers would parse XHTML as HTML and fail on <br/> but not <br />

Reference:

@JackDev 2014-06-12 05:14:59

checked the link, the preferred approach is <br>, but where does it say <br/> it is not acceptable?

@Basil Bourque 2015-03-13 04:05:49

To clarify, for XML-compliant syntax, <br/> and <br /> (with a SPACE) are equal, with no preference for either. See the XML 1.0 spec. Whitespace (SPACE, tab, or LINE FEED) before the /> is optional, with no preference.

@Basil Bourque 2018-08-05 00:57:01

Can you cite a reference for the non-XML syntax being preferred in HTML5? That is news to me. Optional support for strict XML conformance was a founding goal of HTML5 as I recall. Perhaps I missed something on the HTML vs. XHTML document at whatwg.org, or the W3C Polyglot Markup: A robust profile of the HTML5 vocabulary at W3C.

@Rob 2018-08-05 03:19:06

@BasilBourque To re-iterate what I said elsewhere to you. Read the actual specification in HTML5 for the tags and elements and you will never, EVER find any recommendation or suggestion to require or suggest to use a closing slash for those tags. If you want to use XML or XHTML, then you aren't using HTML and that's a different story. Do NOT use a closing slash for those HTML tags. Elsewhere, the spec says you can put one there but it means nothing, does nothing and browsers are instructed to ignore it. So it is pointless and useless making any use of it just as pointless and useless.

@Basil Bourque 2018-08-05 04:13:27

@Rob So Section 8.1.2.1. Start tags of Section 8. The HTML syntax of the document, HTML 5.2 W3C Recommendation, 14 December 2017, published by the W3C is not the actual specification of HTML? Please advise.

@Rob 2018-08-05 11:53:41

@BasilBourque Like most people, instead of looking at the exact specification for those tags as I instructed you to do, you instead you scrambled in vein to pull up the exceptions to make them the rule and ignored what I said earlier and also ignored the part in your link that the slash has no effect. Over 15 years I've pointed this out to people, even had W3C and WHATWG editors and authors like Martin Fowler and Ian Hixie back me up, but this is always an uphill battle for no known reason.

@tvanfosson 2009-12-22 13:44:16

According to the spec the expected form is <br> for HTML 5 but a closing slash is permitted.

@Emanuel Olsson 2013-04-30 15:59:53

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.

@Dave Burton 2014-05-02 17:51:56

What browser was that?

@Iain Collins 2013-01-28 16:44:51

  1. If you are outputting HTML on a regular website you can use <br> or <br/>, both are valid anytime you are serving HTML5 as text/html.

  2. 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: <br/>.

    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 <br> tags).

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).

@amwinter 2013-03-20 07:00:49

wait, text/html mimetype is strict XML?

@Iain Collins 2013-03-20 10:49:57

You shouldn't serve it with an XML declaration if using text/html, but the content can be otherwise valid XML (e.g. generated from something that outputs XML, like XSLT output or an object that serializes to XML).

@amwinter 2013-03-20 16:10:08

Still not understanding: if text/html should have a <br />, when should I use unclosed <br>?

@Iain Collins 2013-03-20 22:24:28

Oh sorry, both are technically valid for HTML5 if it's via text/html. You can confirm this with the (mostly) awesome validator over at validator.w3.org. My wording above is poor I see that now, shall edit it.

@robertc 2014-07-04 16:46:37

I think it was Netscape Navigator 3 or 4 which didn't like <br/>, certainly nothing to be worried about in this day and age.

@kevinji 2011-04-21 18:50:02

Both <br> and <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 (/).

@kevinji 2014-06-20 02:07:43

@Knickerless-Noggins I'm not sure where you're reading that, but <br /> is perfectly acceptable, and W3Schools is not the spec for HTML. See the HTML5 spec, which clearly states that "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) character. [emphasis added]"

@Basil Bourque 2018-08-05 01:38:56

This Answer, like others, incorrectly downplays the legitimacy of strict XML conformance in HTML5. Support for XML is not a temporary transition or migration feature. Optional support of XML conformance was a founding goal of HTML5. It is a vital feature to people using XML tooling for working with their HTML content.

@Samuel 2010-12-01 04:27:10

<br> and <br/> render differently. Some browsers interpret <br/> as <br></br> and insert two line breaks

@Eikern 2010-12-02 10:19:34

What? Do you know which browsers?

@Samuel 2010-12-08 00:35:29

Found this when testing ie5 / ns4 era browsers. If I remember correctly it was ie in standards compliance mode. But it was a long time ago...

@Konrad Borowski 2014-05-25 18:24:29

For strict HTML4 browsers (which is practically just HTML4 validator), <br /> means <br>&gt;.

@sastanin 2009-12-22 13:48:00

XML requires all tags to have a corresponding closing tag. So there is a special short-hand syntax for tags without inner contents.

HTML5 is not XML, so it should not pose such a requirement. Neither is HTML 4.01.

For instance, in HTML5 specs, all examples with br tag use <br> syntax, not <br/>.

UPD Actually, <br/> is permitted in HTML5. 9.1.2.1, 7.

@Christian Hujer 2016-11-08 22:11:52

"HTML5 is not XML, so it should not pose such a requirement." Whether that is correct or not depends on the interpretation of the word "HTML5". If we speak of HTML5 as language, then that statement is correct. If however we speak of HTML5 as a specification, then that statement is incorrect. The HTML5 specification defines "a vocabulary and associated APIs for HTML and XHTML". I know that's a bit nitpicking, I'm not saying this answer is wrong, just giving additional information for the reader.

Related Questions

Sponsored Content

25 Answered Questions

[SOLVED] How can I set the default value for an HTML <select> element?

  • 2010-08-19 01:10:51
  • Jichao
  • 2404752 View
  • 1367 Score
  • 25 Answer
  • Tags:   html html-select

23 Answered Questions

[SOLVED] What are valid values for the id attribute in HTML?

  • 2008-09-16 09:08:52
  • Mr Shark
  • 430995 View
  • 1961 Score
  • 23 Answer
  • Tags:   html id

10 Answered Questions

[SOLVED] Does <STYLE> have to be in the <HEAD> of an HTML document?

30 Answered Questions

[SOLVED] How to create an HTML button that acts like a link?

21 Answered Questions

[SOLVED] Recommended way to embed PDF in HTML?

  • 2008-11-14 23:55:13
  • Daniel Silveira
  • 1375152 View
  • 1147 Score
  • 21 Answer
  • Tags:   html pdf

26 Answered Questions

[SOLVED] Redirect from an HTML page

9 Answered Questions

[SOLVED] Why does HTML think “chucknorris” is a color?

26 Answered Questions

[SOLVED] Retrieve the position (X,Y) of an HTML element

5 Answered Questions

[SOLVED] What is the purpose of the "role" attribute in HTML?

  • 2012-05-01 10:11:45
  • jeroen
  • 565199 View
  • 1130 Score
  • 5 Answer
  • Tags:   html

30 Answered Questions

[SOLVED] Convert HTML + CSS to PDF with PHP?

Sponsored Content