skip to content
VA Logo

Flex divided line by CSS

Create divided line by CSS. Using data attributes or child text element & background-color

Using data attributes

HTML layout and hr with data attribute data-text:

You can use any other naming for data attribute: data-*

	<p>You can divide with any text</p>
	<hr class="hr-text" data-text="START" />
	<hr class="hr-text" data-text="OR" />
	<hr class="hr-text" data-text="END" />

CSS styles:

.hr-text {
	line-height: 1em;
	position: relative;
	outline: 0;
	border: 0;
	color: black;
	text-align: center;
	height: 1.5em;
	opacity: 0.5em;
.hr-text::before {
	content: "";
	background: linear-gradient(to right, transparent, #818078, transparent);
	position: absolute;
	left: 0;
	top: 50%;
	width: 100%;
	height: 1px;
.hr-text::after {
	content: attr(data-text);
	position: relative;
	display: inline-block;
	color: black;
	padding: 0 0.5em;
	line-height: 1.5em;
	color: #818078;
	background-color: #fff;

Using child text element

HTML layout with a child text element:

<div class="container">
	<p>SOME TEXT</p>

CSS styles:

.container p {
	display: flex;
	align-items: center;
.container p::before,
.container p::after {
	content: "";
	height: 2px;
	flex-grow: 1;
.container p::before {
	margin-right: 10px;
	background: linear-gradient(to left, #818078, transparent);
.container p::after {
	margin-left: 10px;
	background: linear-gradient(to right, #818078, transparent);

Live result

You can play with it.

See the Pen Flex divided line by CSS by vladimir-vo (@vladimirvo) on CodePen.