Bootstrap - Vertical rule



This chapter discusses about vertical rule. The custom vertical rule helper creates vertical dividers in common layouts, like the <hr> element.

  • The vertical rule class is denoted as .vr

  • It is 1px wide

  • It has minimum-height of 1em

  • Its color is set using currentColor and opacity

You can customize the verical rules with additional styles as per your requirement.

The example given below shows the usage of .vr class:

Example

You can edit and try running this code using the Edit & Run option.

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Bootstrap Helper - Vertical rule</title>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
        <link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet">
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
    </head>
    <body>
        <h4>Vertical rule example</h4>
        <div class="container">
          <div class="row">
          <div class="col-md-3 text-bg-light">
            <p>Text on the left side of vertical divider.</p>
          </div>
          <div class="col-md-1">
            <hr class="vr">
          </div>
          <div class="col-md-3 text-bg-light">
            <p>Text on the right side of vertical divider.</p>
          </div>
          </div>
        </div>
    </body>
</html>

In flex layouts, the height of vertical rule adjusts automatically based on the size of its container.

Let's see an example where the height of vertical rule is based on the flex layout:

Example

You can edit and try running this code using the Edit & Run option.

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Bootstrap Helper - Vertical rule</title>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
        <link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet">
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
    </head>
    <body>
        <h4>Vertical rule with flex</h4>
        <div class="d-flex flex-row">
          <div class="flex-grow-1">
            <p>Content on the left</p>
          </div>
          <div class="d-flex flex-grow-1" style="height: 200px;">
            <div class="vr"></div>
          </div>
          <div class="flex-grow-1">
            <p>Content on the right</p>
          </div>
        </div>
    </body>
</html>

Vertical rule with stacks

Vertical rule can also be used in stacks, to separate the different values.

Let's see an example where the vertical rule is used in stacks:

Example

You can edit and try running this code using the Edit & Run option.

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Bootstrap Helper - Vertical rule</title>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
        <link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet">
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
    </head>
    <body>
        <h4>Vertical rule with stacks</h4>
        <div class="hstack gap-1">
          <div class="p-3 text-bg-info">First item</div>
          <div class="vr"></div>
          <div class="p-3 text-bg-primary">Second item</div>
          <div class="vr"></div>
          <div class="p-3 text-bg-warning">Third item</div>
        </div>
    </body>
</html>
Advertisements