How to add a line break
Put <br> where you want the new line to start. It is a void element, so there is no closing tag:
The address breaks exactly at each <br>. The second paragraph stays on one line even though the source has a newline in it: HTML treats newlines, tabs and runs of spaces as a single space. That is why <br> exists.
<br>, <br/> and <br /> all produce the same element. Use whichever your project uses (JSX and XHTML require the slash).
br vs p: breaks are not spacing
A <br> ends a line inside the same paragraph. A new <p> starts a new paragraph, with space above and below it from the default margins. Stacking <br> tags to make space works, but it is fragile and says the wrong thing:
Both boxes look similar, but the first one is a single paragraph to a screen reader, and changing the spacing means editing every page. In the second, the gap is one line of CSS.
Good uses of <br>: addresses, poems and song lyrics, and lines in a signature, where the break belongs to the text. For everything else, use paragraphs, lists or headings.
Keeping the newlines in your text
When text comes from somewhere else (a comment box, a database, a script), it has real newline characters instead of <br> tags. The CSS white-space: pre-line makes the browser display those newlines as line breaks:
The same string shows on one line in the gray box and on three lines in the blue one. This is also safer than building <br> tags into user text with innerHTML, which would let users inject HTML. To keep spaces and indentation as well, use white-space: pre, covered on the HTML space page.
Letting long words break: wbr
A long word or URL with no spaces can overflow a narrow box. <wbr> marks a spot where the browser may break the line if it needs to, and does nothing otherwise:
The first path runs out of its box; the second breaks at the <wbr> points. For text you do not control, the CSS property overflow-wrap: anywhere breaks long words anywhere instead.
Stopping a line from breaking
Sometimes you want the opposite: keep "10 km" or a phone number together. Two tools:
is a space the browser will not break at, so "10" and "km" stay together. white-space: nowrap keeps a whole span on one line. Replace with a normal space, or remove the class, and at this width both split across two lines.
Common mistakes
- Pressing Enter in the source and expecting a new line. Newlines in HTML are spaces. Use
<br>, separate elements, orwhite-space: pre-line. - Stacking
<br><br><br>for spacing. Use paragraphs andmargin. - Using
<br>to build a list. Use<ul>or<ol>with<li>, which screen readers announce as a list. - Writing
</br>. It is not valid. Write<br>. - Adding
<br>to user text withinnerHTML. SettextContentand usewhite-space: pre-lineinstead.
Frequently Asked Questions
How do I add a line break in HTML?
Insert <br> where the new line should start: Line one<br>Line two. Pressing Enter in your HTML file does not work, because browsers treat newlines in the source as ordinary spaces.
Should I write <br>, <br/> or <br />?
All three work in HTML and produce the same element. <br> is the plain HTML form; the slash versions are accepted for compatibility with XHTML and JSX. </br> on its own is invalid, although browsers read it as another line break.
When should I use <br> instead of <p>?
Use <br> when the line break is part of the content itself, such as in an address or a poem. Use separate <p> elements for separate paragraphs, and CSS margin for spacing, rather than stacking <br> tags.
How do I keep line breaks from a text without adding <br> tags?
Give the element white-space: pre-line in CSS. The browser then shows every newline in the text as a line break, while still collapsing extra spaces. This is handy for user comments and text loaded with JavaScript.
How do I prevent a line break in HTML?
Wrap the text in an element with white-space: nowrap, or join two words with a non-breaking space so they always stay on the same line.