Border color

Source: https://getbootstrap.com/docs/6.0/utilities/border-color

Utilities for controlling border color and opacity.

Colors

Change the border-color using utilities built on our theme colors using .border-{color} and .border-subtle-{color}. All these border color utilities set the border-color property to a local CSS variable, --bs-bc, which has the value of the theme color. The root color tokens color values also use light-dark() to ensure sufficient contrast in both light and dark color modes.

For example, .border-primary sets the --bs-bc variable to var(--bs-primary-border):

.border-primary {
  --bs-bc: var(--bs-primary-border);
  border-color: var(--bs-bc);
}

This approach allows us to also easily support translucency with our .border-{opacity} utilities as we can use color-mix() with the CSS variable to generate the appropriate color. See the opacity section for more details.

The --bs-bc variable is registered with @property as non-inheriting (inherits: false), so border color utilities are scoped to the element they’re applied to and never cascade into nested elements or components. This is why --bs-bc is deliberately separate from the inheriting --bs-border-color design token that components resolve their default borders from.

<Example class="d-flex flex-column gap-2 bd-example-border-color-utils" code={[ ...getData('theme-colors').map((themeColor) => &lt;div class="border border-5 border-${themeColor.name}">${themeColor.name}&lt;/div> &lt;div class="border border-5 border-subtle-${themeColor.name}">${themeColor.name} subtle&lt;/div>), &lt;div class="border border-5 border-bg">bg&lt;/div> &lt;div class="border border-5 border-body">body&lt;/div> &lt;div class="border border-5 border-muted">muted&lt;/div> &lt;div class="border border-5 border-subtle">subtle&lt;/div> &lt;div class="border border-5 border-emphasized">emphasized&lt;/div> &lt;div class="border border-5 border-black">black&lt;/div> &lt;div class="border border-5 border-white">white&lt;/div> ]} />

Or modify the default border-color of a component:

&lt;label for="exampleFormControlInput1" class="form-label">Email address&lt;/label>
&lt;input type="email" class="form-control border-success" id="exampleFormControlInput1" placeholder="name@example.com">

</div>

<div class="h4 pb-2 mb-4 fg-danger border-bottom border-danger"> Dangerous heading </div>

<div class="p-3 bg-info bg-10 border border-info border-start-0 rounded-end"> Changing border color and width </div>`} />

Nested elements

Because border color utilities set the non-inheriting --bs-bc variable, parent border colors don’t affect the borders of nested elements. Below, the parent uses .border-danger while the nested .border keeps the default border color.

Parent with .border-danger
&lt;div class="border p-3 mt-3">
  Nested .border keeps the default color
&lt;/div>

</div>`} />

Opacity

Change the opacity of a border color by using any of the .border-<percentage> utilities which use color-mix() to mix the border color with transparent thanks to the CSS variable approach mentioned above. Because --bs-bc is scoped to the element, pair these opacity utilities with a .border-{color} utility on the same element—they no longer inherit a border color from an ancestor.

<Example code={&lt;div class="border border-5 border-primary p-2 mb-2">Default border&lt;/div> &lt;div class="border border-5 border-primary border-90 p-2 mb-2">90% opacity&lt;/div> &lt;div class="border border-5 border-primary border-80 p-2 mb-2">80% opacity&lt;/div> &lt;div class="border border-5 border-primary border-70 p-2 mb-2">70% opacity&lt;/div> &lt;div class="border border-5 border-primary border-60 p-2 mb-2">60% opacity&lt;/div> &lt;div class="border border-5 border-primary border-50 p-2 mb-2">50% opacity&lt;/div> &lt;div class="border border-5 border-primary border-40 p-2 mb-2">40% opacity&lt;/div> &lt;div class="border border-5 border-primary border-30 p-2 mb-2">30% opacity&lt;/div> &lt;div class="border border-5 border-primary border-20 p-2 mb-2">20% opacity&lt;/div> &lt;div class="border border-5 border-primary border-10 p-2">10% opacity&lt;/div>} />

CSS

Variables

Sass variables

Variables for setting border-color in .border-*-subtle utilities in light and dark mode:

Sass utilities API

Border color utilities are declared in our utilities API in scss/_utilities.scss. Learn how to use the utilities API.