How to add a horizontal line with HTML and CSS?

Spread the love

Sometimes, we want to add a horizontal line with HTML and CSS.

In this article, we’ll look at how to add a horizontal line with HTML and CSS.

How to add a horizontal line with HTML and CSS?

To add a horizontal line with HTML and CSS, we use a hr element.

For instance, we write

<div>Hello</div>
<hr />
<div>World</div>

to add a hr element between the divs to add a horizontal line.

Then we style it by writing

hr {
  display: block;
  height: 1px;
  border: 0;
  border-top: 1px solid #ccc;
  margin: 1em 0;
  padding: 0;
}

We add a border and set the height of the horizontal line.

Conclusion

To add a horizontal line with HTML and CSS, we use a hr element.

Leave a Reply

Your email address will not be published.