Bootstrap 4 offers a predefined CSS style for the standard HTML horizontal divider <hr />
, making it easy to use.
If you need to adjust margins, Bootstrap provides handy spacing utilities such as mt
for margin top, mb
for margin bottom, and my
for both top and bottom margins. The numerical values from 1
to 5
represent different levels of spacing, from small to large. Here's an example:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<hr class="mt-2 mb-3"/>
<!-- OR -->
<hr class="my-12"/>
<!-- This is similar to -->
<hr class="mt-3 mb-3"/>
In the past, I used to create a custom div
with border-top
like this:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<div class="border-top my-3"></div>
However, this approach was cumbersome and could lead to issues. It's much simpler and more effective to just use <hr />
.