<hr> Divider Styling Guide
Let's learn how to style the HTML <hr> tag with your desired design, such as color or thickness.
By applying CSS, you can design a <hr> tag with your own unique style.
Browser Default Styles
From a design perspective, most modern websites do not use the default styles as-is and often override them. This is because the default styles provided by browsers often do not match the design requirements of websites.
<hr>
Custom Styling
Refer to the most commonly used style patterns below.
Solid Line Pattern
The most straightforward and widely used approach is to set border: none, adjust the line thickness using height, and set the line color using background. The width can be controlled using width.
<hr class="solid-hr">
hr.solid-hr {
border: none; /* Remove default 3D-style border */
height: 2px; /* Line thickness */
background: gray; /* Line color */
width: 50%; /* Line width (100% by default): automatically centered */
}
Practical Example 1
<hr class="solid-hr">
hr.solid-hr {
border: none;
height: 5px;
background: orangered;
width: 50%;
}
Practical Example 2
<hr class="solid-hr">
hr.solid-hr {
border: none;
height: 5px;
background: linear-gradient(to right, orange, red);
}
Dotted and Dashed Line Patterns
In this case, to avoid overlapping borders, you can preserve only the border-top property to create a dotted (dotted) or dashed (dashed) line. When using this approach, no height is applied.
Dotted Line Pattern
<hr class="dotted-hr">
hr.dotted-hr {
border: none; /* Remove default 3D-style border */
border-top-style: dotted;
border-top-width: 2px; /* Line thickness */
border-top-color: gray; /* Line color */
width: 50%; /* Line width (100% by default): automatically centered */
}
Practical Example 1
<hr class="dotted-hr">
hr.dotted-hr {
border: none;
border-top-style: dotted;
border-top-width: 5px;
border-top-color: orangered;
width: 50%;
}
Practical Example 2
<hr class="dotted-hr">
hr.dotted-hr {
border: none;
border-top-style: dotted;
border-top-width: 5px;
border-top-color: orangered;
}
Dashed Line Pattern
<hr class="dashed-hr">
hr.dashed-hr {
border: none; /* Remove default 3D-style border */
border-top-style: dashed;
border-top-width: 2px; /* Line thickness */
border-top-color: gray; /* Line color */
width: 50%; /* Line width (100% by default): automatically centered */
}
Practical Example 1
<hr class="dashed-hr">
hr.dashed-hr {
border: none;
border-top-style: dashed;
border-top-width: 5px;
border-top-color: orangered;
width: 50%;
}
Practical Example 2
<hr class="dashed-hr">
hr.dashed-hr {
border: none;
border-top-style: dashed;
border-top-width: 5px;
border-top-color: orangered;
}
Symmetrical Divider
<hr class="symmetrical-hr">
hr.symmetrical-hr {
position: relative;
overflow: visible;
border: none;
width: 300px; /* Center bar width */
max-width: calc(33.333% - 10px); /* Ensures a responsive layout regardless of the center bar width */
height: 10px; /* Center bar thickness */
background: gray; /* Center bar color */
}
hr.symmetrical-hr:before,
hr.symmetrical-hr:after {
content: "";
position: absolute;
top: 50%;
width: 100%;
height: 1px; /* Side line thickness */
background: gray; /* Side line color */
}
hr.symmetrical-hr:before {
transform: translateX(calc(-100% - 5px)) translateY(-50%);
}
hr.symmetrical-hr:after {
transform: translateX(calc(100% + 5px)) translateY(-50%);
}
Practical Example 1
<hr class="symmetrical-hr">
hr.symmetrical-hr {
position: relative;
overflow: visible;
border: none;
width: 300px;
max-width: calc(33.333% - 10px);
height: 8px;
background: orangered;
}
hr.symmetrical-hr:before,
hr.symmetrical-hr:after {
content: "";
position: absolute;
top: 50%;
width: 100%;
height: 1px;
background: orangered;
}
hr.symmetrical-hr:before {
transform: translateX(calc(-100% - 5px)) translateY(-50%);
}
hr.symmetrical-hr:after {
transform: translateX(calc(100% + 5px)) translateY(-50%);
}
Practical Example 2
<hr class="symmetrical-hr">
hr.symmetrical-hr {
position: relative;
overflow: visible;
border: none;
width: 300px;
max-width: calc(33.333% - 10px);
height: 10px;
background: linear-gradient(to right, orange, red);
border-radius: 5px;
}
hr.symmetrical-hr:before,
hr.symmetrical-hr:after {
content: "";
position: absolute;
top: 50%;
width: 100%;
height: 1px;
background: orangered;
}
hr.symmetrical-hr:before {
transform: translateX(calc(-100% - 5px)) translateY(-50%);
}
hr.symmetrical-hr:after {
transform: translateX(calc(100% + 5px)) translateY(-50%);
}