The quick answer
hr stands for “horizontal rule”. Put it between two blocks of content and you get a line that runs the
full width of its container, with a little space above and below.
<hr> is a void element, like <br> and <img>: it can’t hold
anything, so there’s nothing to close. Writing </hr> is a mistake (browsers drop it). The slash in
<hr /> is optional in HTML; you’ll mostly see it in older XHTML pages and in React, where JSX
needs it.
💡 Looking for a new line of text, not a drawn line? That’s <br>, or a new paragraph. The
line break tutorial covers both.
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.
What hr means: a change of topic
The name says “line”, but since HTML5 the tag has a meaning: a thematic break. It marks the spot where the content moves on to something else, like a scene change in a story or the sign-off at the end of a blog post. The line is just how browsers show that break.
Because it means something, assistive tech notices it. An hr has the built-in role
separator, and many screen readers announce it (often as “separator”) when they reach it. That’s
helpful between topics, and noise when the line is only there to look nice. For pure decoration, like a line under
every heading or around a box, use a CSS border instead. You don’t need an hr between
<section>s either: a new section with its own heading is already a break.
Why the line looks gray and 3D
Browsers don’t draw hr as a filled bar. They give it no height at all and a 1px border on every side,
in the style inset and the color gray. So what you see is two 1px borders stacked, a total of 2px, and
the inset style shades the top darker than the bottom. That gives the old-fashioned 3D groove. Make the border
thicker and it’s easy to see:
In CSS terms, the browser’s own stylesheet gives every hr roughly this:
color: gray; border: 1px inset; margin: 0.5em auto; overflow: hidden;. That’s why
background-color does nothing on its own and why margin: 20px 0 moves the line left.
Change the color of an hr
The line is made of borders, so background-color on its own changes
nothing you can see: the hr has no height, and the borders cover the background. color is hit and miss:
some browsers use it for the line, but in Chrome and Edge the line stays gray (look at the first line in the example).
border-color does reach the line, but the border is still inset, so you get two shades of
red instead of one flat line.
The fix is to remove the default border first with border: none, then draw the line yourself. Either
add one border back (border-top: 3px solid #4d7c0f) or give the hr a height and a background color.
Both look the same. The border way also lets you make the line dashed or dotted later. Need a color code? The
HTML Color Picker gives you hex, rgb and hsl.
Thickness, width and centering
The thickness is the border width (or the height, if you used the background way). For the length, set
width. You get centering for free: browsers give hr automatic left and right margins, so a
shorter line sits in the middle on its own.
The catch is in the second example. Writing margin: 20px 0 sets the left and right margins to 0, so the
automatic centering is gone and the line slides to the left. Use margin: 20px auto to keep it in the
middle. For a line on the left, set margin-left: 0; for one on the right, margin-right: 0.
The centering tutorial explains how margin: auto works.
Dashed, dotted, rounded and gradient lines
Once you draw the line with border-top, any border style works: dashed,
dotted or double (which needs at least 3px to show two lines). For rounded ends or a
gradient, the height and background way is easier: border-radius rounds a filled bar neatly, and a
background can be a gradient, which a plain border color can’t.
The fading line is a linear-gradient from transparent to a color and back, so it’s strong in
the middle and fades out at both ends. You can build gradients like that by dragging color stops in the
CSS Gradient Generator.
A line with text in the middle
You’ve seen this on sign-in forms: a line, the word “or”, and another line. An hr can’t hold text, so
use a normal element for the word and draw the two lines with CSS. Flexbox puts them side by side, and
flex: 1 makes each line take up the space that’s left.
::before and ::after add two empty boxes, one each side of the text, and their top border is
the line. Change or to Desserts and you have a centered section label.
A vertical line
There’s no vertical version of hr. For a line going up and down, use a border on the side of an element.
Between two columns, the left border of the second column does the job:
In the second example, the empty div is the line. align-self: stretch makes it as tall as
the row, and border-left draws it. These lines are decoration, so screen readers skip them, which is
usually what you want between columns.
Space above and below the line
The hr’s own margin is only half the font size (8px with 16px text). Next to paragraphs you’ll see more than that, because
vertical margins collapse: when two margins meet, you get the bigger one, not both added up. A paragraph has a 16px
margin, so that’s what you see. To space the line out, give it a bigger margin, and keep auto for left
and right.
hr or a border under a heading?
A line under a heading looks like an hr, but it’s part of the heading’s design. Use border-bottom on the
heading for that, with a bit of padding-bottom for space. An hr there would tell screen readers “new
topic” right between a heading and its own text.
- Use
<hr>when the content changes topic: the end of a story scene, the sign-off after a post, a break between two unrelated notes. - Use a border when the line belongs to something else, like a heading, a card, a table row or the top of a footer. If you’d draw it on every page in the same place, it’s probably a border.
The old size, width, color and noshade attributes
Old tutorials style the line with attributes, like <hr size="4" color="red" noshade>. They’re
obsolete in HTML5. Browsers still show them so old pages don’t break, but CSS does everything they did:
| Old attribute | What it did | Use this CSS instead |
|---|---|---|
size="4" | Thickness in pixels | border: none; height: 4px; plus a background color, or border-top: 4px solid |
width="50%" | Length of the line | width: 50%; |
color="red" | A flat line in that color | border: none; border-top: 2px solid red; |
noshade | A flat line instead of the 3D one | border-style: solid; or the border-top line above |
align="left" | Line on the left, right or center | Left: margin-left: 0; Right: margin-right: 0; Center is the default. |
A line in a dropdown menu
Newer browsers let you put an <hr> between the options of a <select>, and draw
it as a thin divider in the open menu. Open the menu below to see it. Older browsers leave the hr out, and the
menu works the same, just without the line.
If the groups need names (“Hot drinks”, “Cold drinks”), use <optgroup label="..."> instead. The
Dropdown Generator builds those for you.
When the line doesn’t show up
Most of the time it’s one of these:
- It’s inside a flex container. In a flex column the hr only gets the width it asks for, which is
nothing, so it shrinks to a 2px dot. In a flex row it turns into a short vertical line instead. Give it
width: 100%(first example below), or move it outside the flex box. - You wrote
border: noneand nothing else. That removes the whole line. Addborder-topback, or a height and a background color. - Only
background-coloris set. Without a height, there’s nothing to fill. - It’s inside a
<p>. A paragraph can’t contain an hr, so the browser ends the paragraph right before it. The text after the hr lands outside, and the</p>becomes a new, empty paragraph (second example: see the yellow strip at the bottom). - The color matches the background. A light gray line on a light gray card is there, you just can’t see it.
Paste your page into the HTML Validator to catch the paragraph mistake. The HTML Tags reference lists hr with the other block tags, if you want to see what else can’t go inside a paragraph.
Questions people ask
What does hr do in HTML?
The <hr> tag marks a thematic break: a point where the content moves on to a new topic, like a scene change in a story or the sign-off after a blog post. Browsers show it as a thin gray line across the page, with a little space above and below.
How do I make a horizontal line in HTML?
Type <hr> where you want the line, for example between two paragraphs: <p>Thanks for reading!</p> <hr> <p>Next week: sourdough.</p>. To style it, use CSS: hr { border: none; border-top: 2px solid #4d7c0f; } gives a flat green line 2px thick.
Does the hr tag need a closing tag?
No. <hr> is a void element, like <br> and <img>, so it has no content and no closing tag. <hr> and <hr /> both work in HTML. Don’t write </hr>: it’s an error and browsers ignore it.
What does hr stand for?
Horizontal rule. A rule is a printer’s word for a straight line, as in a ruler. The name is from the early days of HTML. Today the tag means a change of topic, and the line is just how browsers show it.
Why doesn’t background-color change my hr?
Because the default hr has no height. The line you see is a 1px gray border on the top and bottom, and the borders cover the background. Remove the border and give it a height: hr { border: none; height: 2px; background-color: #b91c1c; }. Or keep it simple with border: none; border-top: 2px solid #b91c1c;.
How do I make an hr thicker or shorter?
Thicker: hr { border: none; border-top: 5px solid #374151; }. Shorter: add width, for example width: 50%. It stays centered, because browsers give hr automatic left and right margins. If you also set margin, write margin: 20px auto rather than margin: 20px 0, or the line moves to the left.
Is the hr tag deprecated?
No, <hr> is valid HTML5. Only its old attributes are obsolete: size, width, color, noshade and align. Use CSS for those instead: height or border-top for the thickness, width for the length, border-top or background-color for the color, and margins for the position.
How do I make a vertical line in HTML?
There’s no vertical hr. Use a border on the side of an element instead. Between two columns, give the second one border-left: 2px solid #d1d5db; and some padding-left. For a short line between two words in a flex row, an empty div with border-left and align-self: stretch works.
How do I make a new line instead of a drawn line?
That’s a line break, not a horizontal rule. Use <br> to break a line inside the same paragraph, like in an address, or start a new <p> for a new paragraph. The line break tutorial on this site shows both.
Keep going
Tools that help
- HTML Editor Paste any example and keep building on it.
- CSS Gradient Generator Build the gradient for a fading or colorful line.
- HTML Tags Every tag with a tiny example, hr included.
- HTML Validator Finds an hr inside a paragraph, and other markup mistakes.
More tutorials
- How to Center Text, a Div or an Image in HTML & CSS
- How to Add a Line Break in HTML
- How to Add Spaces in HTML
- How to Change Text Color in HTML
- How to Change Background Color in HTML
- How to Add an Image in HTML
- What Is a URL? Meaning, Parts and Examples
- How to Redirect a Page in HTML
- How to Get an Image URL
- Canonical URL
- What Is HTML? What It Stands For and How It Works
- How to Create, Open and Run an HTML File
- How to Link CSS to HTML
- How to See the HTML Code of a Website
- How to Link JavaScript to HTML with the script Tag
- HTML Comments
- How to Make Text Bold in HTML
- HTML Font and Font Size
- All tutorials