How to add horizontal lines before and after a text in HTML

This tutorial will guide you on how to add a horizontal line to the right and left side of a text as shown below:

In your HTML file create an h1 tag.

<h1>Learnpod Academy</h1>
<h1>This is a longer heading</h1>  
h1 {
  overflow: hidden;
  text-align: center;

h1:after {
  background-color: #000;
  content: "";
  display: inline-block;
  height: 1px;
  position: relative;
  vertical-align: middle;
  width: 50%;

h1:before {
  right: 0.5em;
  margin-left: -50%;

h1:after {
  left: 0.5em;
  margin-right: -50%;


Leave A Reply

Your email address will not be published. Required fields are marked *