# How to Style an hr (Horizontal Rule) in CSS

> Style the HTML hr element with CSS: change its color and thickness, make dashed, dotted and gradient lines, add text or an icon in the middle, and use it correctly as a thematic break.

Author: [Marko Denic](https://markodenic.com/) | Published: 2026-11-06 | Updated: 2026-11-06 | Topics: CSS, HTML, Tutorial | Canonical: https://markodenic.com/css-hr/

![How to Style an hr (Horizontal Rule) in CSS](https://markodenic.com/wp-content/uploads/2026/11/og-css-hr.png)

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:

```html
<div class="hr-demo">
  <hr class="hr-demo__thin">
  <hr class="hr-demo__thick">
  <hr class="hr-demo__dashed">
  <hr class="hr-demo__dotted">
  <hr class="hr-demo__gradient">
  <div class="hr-demo__text" role="separator">or continue with</div>
  <hr class="hr-demo__icon">
</div>
```

```css
.hr-demo {
  display: grid;
  gap: 28px;
  padding: 28px 24px;
  border-radius: 16px;
  background: #fff;
  font: 14px/1.4 system-ui, sans-serif;
  color: #64748b;
}

/* :where() keeps this reset weaker than the classes below */
:where(.hr-demo) hr {
  width: 100%;
  margin: 0;
  border: 0;
}

.hr-demo__thin     { border-top: 1px solid #cbd5e1; }
.hr-demo__thick    { height: 4px; border-radius: 4px; background: #1d4ed8; }
.hr-demo__dashed   { border-top: 2px dashed #94a3b8; }
.hr-demo__dotted   { border-top: 4px dotted #3b82f6; }

.hr-demo__gradient {
  height: 2px;
  background: linear-gradient(90deg, transparent, #1d4ed8, transparent);
}

/* Text in the middle */
.hr-demo__text {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hr-demo__text::before,
.hr-demo__text::after {
  content: "";
  flex: 1;
  border-top: 1px solid #cbd5e1;
}

/* Ornament in the middle */
.hr-demo__icon {
  overflow: visible;
  height: 0;
  border-top: 1px solid #cbd5e1;
  text-align: center;
}

.hr-demo__icon::after {
  content: "\2726";
  position: relative;
  top: -0.8em;
  padding: 0 10px;
  background: #fff;
  color: #3b82f6;
  font-size: 18px;
}
```

[See the live demo](https://markodenic.com/css-hr/#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](https://markodenic.com/css-striped-background/).

```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](https://markodenic.com/css-before-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](https://markodenic.com/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.

Related: [CSS ::before and ::after](https://markodenic.com/css-before-after/), [striped backgrounds in CSS](https://markodenic.com/css-striped-background/), [HTML blockquote](https://markodenic.com/html-blockquote/) and [HTML tips](https://markodenic.com/html-tips/).
