How to Create Horizontal Divider Lines with CSS

To draw a horizontal divider in CSS, add a border-top to an element. When the line marks a change of topic between paragraphs, use HTML’s <hr> element and style it with CSS. The same border properties can produce a full-width line, a short line, or a line with a diamond in the middle.

Choose a thematic break or a decorative border

Use <hr> for a change of scene or subject within an article. Assistive technologies can recognize it as a separator. If the new topic needs a heading, give it one and check whether the transition is already clear from the structure.

For a purely visual line, add a border to an existing element, such as the next paragraph. If a standalone diamond divider is decorative, an empty <div> with aria-hidden="true" works as in the demo. Keep semantic breaks and meaningful text available to assistive technologies.

HTML standard for the hr element

Try three horizontal dividers in one file

Save the complete example as dividers.html and open it in a browser. It compares all three lines in a horizontal writing mode and needs no libraries.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Horizontal CSS dividers</title>
  <style>
    body {
      max-inline-size: 38rem;
      margin: 2rem auto;
      padding-inline: 1rem;
      color: #172635;
      font: 1rem/1.6 system-ui, sans-serif;
    }

    .divider {
      border: 0;
      border-block-start: 1px solid #576776;
      margin-block: 1.5rem;
    }

    .divider-text {
      padding-block-start: 0.75rem;
    }

    .divider--short {
      inline-size: min(100%, 18rem);
      margin-inline: auto;
    }

    .divider--accent {
      position: relative;
    }

    .divider--accent::after {
      position: absolute;
      inset-block-start: 0;
      inset-inline: 0;
      margin-inline: auto;
      inline-size: 0.55rem;
      block-size: 0.55rem;
      transform: translateY(-50%) rotate(45deg);
      background-color: #285ea8;
      content: "";
    }
  </style>
</head>
<body>
  <p>Choose a divider based on the structure of the content.</p>
  <p class="divider divider-text">The rule above this paragraph provides visual separation.</p>

  <hr class="divider divider--short">

  <p>Now consider the length and alignment of the line.</p>
  <div class="divider divider--short divider--accent" aria-hidden="true"></div>
  <p>The diamond is an accent at the center.</p>
</body>
</html>

The first line spans the second paragraph. The second is shorter and centered, and the third has a blue diamond in the middle. Narrow the browser window to see the shorter lines shrink to fit the content area.

Adjust the line thickness, length and accent

border: 0 clears the browser’s default borders on <hr>. border-block-start then sets the width, style and color at the top edge in horizontal writing, like border-top. Use padding-block-start for space between a paragraph and its border, and margin-block for space outside the line.

inline-size: min(100%, 18rem) uses the smaller of the available width and 18rem. margin-inline: auto shares the leftover space between the two sides. Increase 18rem for a longer rule and check the result at a narrow viewport.

position: relative makes the line the positioning reference for ::after. The pseudo-element is an empty square centered with auto margins. Move it upward by half its size and rotate it 45 degrees to make a diamond that straddles the line. Change both size properties to the same value to scale it.

CSS specification for logical border properties

Make a dashed divider or fix a missing line

To make the second line dashed, add the rule below after .divider and append divider--dashed to the class list on the short <hr>.

.divider--dashed {
  border-block-start-style: dashed;
}

If the line is missing, inspect the element’s computed styles. Check whether its border width is zero or its style is none. With selectors of equal specificity, a later border: 0 can reset the border you set earlier.

Check that the divider is visible against the page background. If a color or a shape marks an important distinction, communicate that distinction in the text or headings too.