The quick answer
Pressing Enter in your HTML code doesn’t make a new line on the page. The browser turns every line break in the code into a single space. You have to ask for a break, and there are two ways to do it:
The examples run in a locked box: scripts are off, nothing is sent anywhere, and your edits go away when you reload. To keep one, copy it into the HTML Editor.
<br> or a new paragraph?
Use <br> when the break is part of the content itself: the lines of an address, a poem, song
lyrics, or a signature. Use a new <p> when you start a new thought. A paragraph gets its own space
above and below, and screen readers announce it as a separate block, so people who listen to the page can jump
from one to the next.
-
<br>has no closing tag. It’s an empty element, like<img>. You can write<br>,<br/>or<br />. The slash is optional in HTML (it’s required in XHTML and JSX). -
</br>is a mistake. Browsers forgive it and draw a break anyway, but it isn’t valid HTML. The HTML Validator points it out. - Don’t chain paragraphs with
<br>. Two<br>tags in a row to fake a paragraph gap look the same, but they lose the meaning and the spacing is harder to control.
Line breaks inside headings, buttons and cells
<br> works anywhere text flows: in a heading, a link, a button, a list item or a table cell. It’s
handy when a short title reads better on two lines, or when one cell holds two facts.
A break that looks good on a laptop can look odd on a phone, where the line already wraps. You can hide a
<br> on small screens with a class and display: none. In this example the break goes
away when the preview is narrower than 400px. Try it on your phone, make the browser window narrow, or change
400px to 800px in the code to see it here.
Keep the line breaks you typed (white-space)
When the text comes from somewhere else, like a comment box, a database or a plain text file, it already has line
breaks in it. Adding <br> tags by hand is a chore. Tell the browser to keep the breaks instead,
with the CSS white-space property:
| white-space | Line breaks | Extra spaces | Long lines wrap? |
|---|---|---|---|
normal | Become a space | Squeezed to one | Yes |
pre-line | Kept | Squeezed to one | Yes |
pre-wrap | Kept | Kept | Yes |
pre | Kept | Kept | No, they run off the side |
nowrap | Become a space | Squeezed to one | No |
pre-line is the one you want for messages and comments: it keeps the reader’s line breaks but tidies
stray spaces. pre-wrap is better for poems or text where the spacing matters. Want to turn typed text
into real <p> and <br> tags instead? The Text to HTML
converter does that for you.
Line breaks from CSS
Sometimes you can’t change the HTML, or the break is only for looks. CSS can add one in two ways. The first is
generated content: in a CSS string, \A is the line feed character (A is 10 in hex). It only breaks the
line if white-space keeps line breaks, so add white-space: pre next to it.
The second way is display: block. A block always starts on a new line, so turning a
<span> into a block puts it on its own line, as with “Name:” above. Text added with
content is only decoration: some screen readers skip it and people can’t select it, so keep real
information in the HTML.
Break long words and links
Browsers only wrap lines at spaces and a few other spots. A long email address, link or word with no spaces can stick out of a narrow box and make a phone page scroll sideways. These fix it:
-
overflow-wrap: anywherebreaks a word only when it doesn’t fit. Normal words are left alone. It’s a safe default for boxes that show user text or links.overflow-wrap: break-wordis almost the same, but a flex or grid item with it may still stay as wide as the long word. -
word-break: break-allbreaks anywhere, even inside short words that would fit. It fills each line, which suits long codes or IDs, but it’s harder to read for normal text. -
<wbr>marks a spot where the browser may break if it needs to. Nothing shows when it doesn’t break. -
­(soft hyphen) is the same idea, but it shows a hyphen at the end of the line when the word breaks there. -
hyphens: autolets the browser hyphenate words by itself. It needs alangattribute, and how well it works depends on the browser and the language, so test it.
Don’t use <br> for spacing
A row of <br> tags is a quick way to push something down, but it causes trouble later. The gap
depends on the font size and line height, so it changes from page to page. Some screen readers read each empty
line as “blank”. And to change the spacing, you have to edit every page by hand. Use margin (or
padding) in CSS instead:
To open up the lines inside a paragraph, use line-height (for example line-height: 1.6),
not extra breaks. To control the space between paragraphs, set margin on p. There’s more
about gaps in the spaces in HTML tutorial.
Line breaks in a textarea and in attributes
A <textarea> keeps every line break you type between its tags, so its starting text can span
lines. (One line break right after <textarea> is dropped, so you can start the text on the next
line of your code.) Attributes like placeholder and title keep line breaks too. A real line
break inside the quotes works, but it’s easy to miss in your code, so the clear way is to write the line feed
character as (or 
). A one-line
<input> can’t hold a line break at all. The browser removes any line break from its
value.
-
in normal text doesn’t break the line. It’s a line feed, and like any line feed in HTML it turns into a space. It only shows as a break in attributes, inside a textarea, or wherewhite-spacekeeps line breaks. - Showing what someone typed? Put it in an element with
white-space: pre-line. If you build HTML with code instead, escape the text first (<becomes<and so on) and only then swap line breaks for<br>. Swapping first lets someone slip their own tags into your page.
You’ll find , and hundreds of other codes on the
HTML Entities page, ready to copy.
Questions people ask
How do I add a line break in HTML?
Put a <br> tag where the line should break, for example Ada Lovelace<br>12 Engine Street. It has no closing tag. Pressing Enter in your code does nothing on the page, because the browser turns line breaks in the code into spaces.
What is the difference between <br> and <p>?
<br> breaks the line but keeps you in the same paragraph, which is right for addresses, poems and lyrics. <p> starts a new paragraph: it gets space above and below, and screen readers treat it as a separate block. Use <p> for a new thought and <br> only when the break is part of the content.
Should I write <br>, <br/> or <br />?
All three work the same in HTML. <br> is the shortest. The slash is needed in XHTML and in JSX for React. Don’t write </br>: browsers forgive it, but it isn’t valid HTML and validators flag it.
How do I add a blank line or more space between lines?
Use CSS rather than extra <br> tags. margin-top or margin-bottom adds space between paragraphs or other blocks, for example p { margin-bottom: 24px; }, and line-height opens up the lines inside a paragraph, for example line-height: 1.6. The gap is then exact and you can change it in one place.
How do I keep the line breaks from a textarea when I show the text on a page?
Show the text inside an element with white-space: pre-line. The browser then keeps every line break the person typed and still wraps long lines. Use pre-wrap if the extra spaces should stay too. If you build HTML with code instead, escape the text first and only then turn line breaks into <br>.
How do I break a long word or link that sticks out of its box?
Add overflow-wrap: anywhere to the box. It breaks a word only when it doesn’t fit on the line. word-break: break-all breaks anywhere, even inside short words. To choose the spots yourself, put <wbr> where a break is allowed, or ­ to show a hyphen when it breaks there.
Can I add a line break with CSS?
Yes. Use content: "\A" in a ::before or ::after rule together with white-space: pre, because \A is the line feed character in CSS. Or set display: block on an element so it starts on its own line. Keep real information in the HTML, since generated content is only decoration.
How do I put a line break in a placeholder or title attribute?
Write the line feed character as (or 
) inside the attribute, for example placeholder="Street City". A real line break inside the quotes works too, but is easier to see in your code. It works in a textarea placeholder and in title tooltips. A one-line <input> can’t show or hold a line break.
Why does not break the line in my paragraph?
is just a line feed character, and in normal text the browser turns every line feed into a space, the same as pressing Enter in your code. It only shows as a break in attributes, inside a textarea or <pre>, or where CSS white-space keeps line breaks. Use <br> in normal text.
Keep going
Tools that help
- HTML Editor Paste any example and keep building on it.
- Text to HTML Turns typed text into paragraphs and <br> tags.
- HTML Entities Codes like and , click to copy.
- HTML Validator Finds a stray </br> and other mistakes.