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:
1. Create an HTML text tag.
In your HTML file create anĀ h1
tag.
<h1>Learnpod Academy</h1>
<h1>This is a longer heading
</h1>
2. Adding the CSS
h1 {
overflow: hidden;
text-align: center;
}
h1:before,
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%;
}