How to Style an hr (Horizontal Rule) in CSS

By Marko Denic
Contents
  1. The reset
  2. Line styles
  3. Color and thickness
  4. Dashed and dotted
  5. Gradient line that fades out
  6. Shorter, centered line
  7. Dividers with text or an icon
  8. "or" divider with text in the middle
  9. An ornament on the line
  10. When to use hr
  11. FAQ

The <hr> element draws a horizontal line, and it’s notoriously awkward to style: browsers draw it with an inset border, not a background, so setting color or background alone does almost nothing. Reset the border first, and it becomes as easy to style as any box:

The reset

Remove the default border, then draw the line with a single border side (or a height and background).

css
hr {
  border: 0;
  border-top: 1px solid #e2e8f0;
  margin: 2rem 0;
}

Demo:







Line styles

Color and thickness

With a border line, the border width is the thickness. With a background line, use height. Use currentColor to match the surrounding text color automatically, which also adapts to dark mode.

css
hr {
  border: 0;
  border-top: 2px solid currentColor;
  opacity: 0.2;
}

/* Or a thick, rounded line */
hr.thick {
  border: 0;
  height: 4px;
  border-radius: 4px;
  background: #1d4ed8;
}

Dashed and dotted

Any border style works: dashed, dotted, double. For control over the dash length and gap, use a repeating-linear-gradient instead, the same technique as CSS stripes.

css
hr.dashed { border: 0; border-top: 2px dashed #94a3b8; }
hr.double { border: 0; border-top: 4px double #94a3b8; }

/* Custom dashes: 12px dash, 6px gap */
hr.custom {
  border: 0;
  height: 2px;
  background: repeating-linear-gradient(90deg, #94a3b8 0 12px, transparent 12px 18px);
}

Gradient line that fades out

css
hr.fade {
  border: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, #94a3b8, transparent);
}

Shorter, centered line

An hr is full width by default. Give it a width and auto side margins.

css
hr.short {
  width: 80px;
  margin: 2rem auto;
  border: 0;
  border-top: 3px solid #1d4ed8;
}

Dividers with text or an icon

"or" divider with text in the middle

An hr can’t contain text, so use an element with flexbox and two lines drawn by ::before and ::after. role="separator" keeps the meaning for screen readers.

html
<div class="divider" role="separator">or</div>

<style>
  .divider {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #64748b;
  }

  .divider::before,
  .divider::after {
    content: "";
    flex: 1;
    border-top: 1px solid #cbd5e1;
  }
</style>

An ornament on the line

Keep the real hr and add a symbol with ::after. The symbol’s background covers the line behind it.

css
hr.ornament {
  overflow: visible;
  height: 0;
  border: 0;
  border-top: 1px solid #cbd5e1;
  text-align: center;
}

hr.ornament::after {
  content: "\2726"; /* ✦ */
  position: relative;
  top: -0.8em;
  padding: 0 10px;
  background: #fff; /* match the page background */
}

When to use hr

In HTML5, <hr> means a thematic break: a change of topic or scene within a section, like a scene change in a story or a shift between parts of an article. Screen readers announce it as a separator.

For a purely decorative line (under a heading, between cards), use a CSS border on the element instead, so the markup doesn’t announce a break that isn’t there. Small semantic details like this are what these HTML tips are about.

FAQ

How do I change the color of an hr?

Remove its default border and set a new one: hr { border: 0; border-top: 1px solid #1d4ed8; }. Setting color or background-color alone won’t do it in every browser.

How do I make an hr thicker?

Increase the border width (border-top: 4px solid), or use height with a background color after resetting the border.

How do I make a vertical line in CSS?

Use a border on an element (border-left: 1px solid), or a 1px-wide element with align-self: stretch inside a flex row. The hr element is always horizontal by meaning.

Is hr a self-closing tag?

Yes, it’s a void element: write <hr>. <hr /> also works, but the slash isn’t needed in HTML.