Skip to content
Tutorials Center
My learning

Topics

Lesson 21 of 58 ยท Utilities

Borders, Radius and Shadows

Add borders, change their color and width, round corners with rounded-* and rounded-pill, and lift elements with shadow-sm, shadow and shadow-lg in Bootstrap 5.

Borders, rounded corners and shadows are the finishing touches that make a flat page feel like an interface. A card gets a soft outline, an avatar becomes a circle, a dialog floats above the page. In plain CSS you would write a border, a border-radius and a box-shadow rule for each. Bootstrap turns every common choice into a short class.

This lesson covers the border utilities (sides, colors, widths, opacity), the rounded-* family including rounded-circle and rounded-pill, and the three shadow sizes. It builds on Colors and Backgrounds and Spacing Utilities.

Adding and removing borders

The class border adds a 1 px solid border on all four sides. To target one side, use border-top, border-end, border-bottom or border-start. (end and start replace "right" and "left" so layouts flip correctly in right-to-left languages.)

To take a border away, use the -0 classes: border-0 removes all of them, and border-top-0, border-end-0, border-bottom-0, border-start-0 remove one side. Removal is handy when a component already has a border you want to drop on one edge, for example the line between two stacked boxes.

Border sides

Notice the pattern in the second row: add border first, then subtract sides with border-*-0. That is often shorter than adding sides one by one.

Border colors, widths and opacity

By default a border uses a neutral gray from the theme (--bs-border-color). The color classes use the same theme names you met in the colors lesson: border-primary, border-secondary, border-success, border-danger, border-warning, border-info, border-light, border-dark and border-white. Bootstrap 5.3 also has soft variants such as border-primary-subtle and border-danger-subtle, which suit a border paired with a bg-*-subtle background.

Widths run from border-1 (1 px) to border-5 (5 px). Opacity classes go from border-opacity-10 to border-opacity-100 in steps (10, 25, 50, 75, 100) and fade the border color.

Colors, widths and opacity

The last box shows a popular design trick: a thick border on one side only, as an accent line for notes or quotes.

Width and color apply to all sides that exist. border-3 or border-danger only change a border that is there. If you write border-danger without border or a side class, nothing visible happens because the element has no border to color.

Rounded corners

The rounded class gives every corner a small radius. A numbered scale makes the size explicit:

Class Meaning
rounded-0 square corners
rounded-1 very small radius
rounded-2 the same as rounded (default)
rounded-3 larger
rounded-4, rounded-5 very large
rounded-circle 50%: a circle when the box is square
rounded-pill fully rounded ends, a capsule shape

You can also round only one side: rounded-top, rounded-end, rounded-bottom, rounded-start. Each combines with a size, such as rounded-top-3, and with -0 to square that side off. Rounding a side affects the two corners on that edge.

The rounded scale

rounded-circle only gives a circle when width and height are equal. On a wide box it makes an ellipse, so combine it with a square size, as avatars do. rounded-pill works on any width: the ends become semicircles, which is why it suits buttons, tags and search fields.

flowchart LR
  A["rounded-0<br/>square"] --> B["rounded-1 to rounded-5<br/>growing radius"]
  B --> C["rounded-pill<br/>capsule ends"]
  B --> D["rounded-circle<br/>50% radius"]

From square to round: the radius classes grow along one scale, with pill and circle at the extreme end.

Shadows

Shadows suggest height. Bootstrap offers three sizes and an off switch:

  • shadow-none removes a shadow (useful to cancel one at a breakpoint or on hover).
  • shadow-sm is a small, subtle shadow.
  • shadow is the regular one.
  • shadow-lg is a large, wide shadow.
Shadow sizes

The gray background behind the boxes matters. A shadow is hard to see on pure white, so a slightly tinted page background makes the effect clearer. The first box has a border instead of a shadow so you can still see its edge.

Use shadows sparingly. One level of shadow for cards and a bigger one for things that float, such as menus and dialogs, reads clearly. A page where everything has shadow-lg loses the sense of depth.

Putting it together

Most real components combine all three families. A profile card might be border rounded-3 shadow-sm, an avatar rounded-circle border border-2 border-white, and a tag rounded-pill border border-primary-subtle. Bootstrap's own components (cards, alerts, buttons) already use these same settings through CSS variables, so adding utility classes to them overrides the defaults for that one element.

Dark mode is handled for you: the default border color and the shadow color come from variables that change with the color mode (see Color Modes and Dark Mode). A fixed color like border-dark stays dark in both modes, which can look wrong on a dark page, so prefer the default or the -subtle variants when a border should adapt.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which class gives an element a border on only its left side in a left-to-right page?

    Bootstrap 5 uses logical names: border-start and border-end. border-left was Bootstrap 4, and border-1 sets a width on a border that already exists.
  2. 2. You wrote class="border-danger border-3" on a div and see no border. What is missing?

    Color and width classes style a border that is there; they do not create one.
  3. 3. Which classes turn a square 4rem by 4rem box into a circle?

    rounded-circle sets a 50% radius, which is a circle on a square box. rounded-pill and rounded-5 make rounded rectangles.
  4. 4. What does border-opacity-25 change?

    Opacity classes fade the border color; they need a border to act on.
  5. 5. Which class removes a shadow?

    shadow-none sets box-shadow to none. The sizes are shadow-sm, shadow and shadow-lg.

Summary

  • border adds a border; border-top/end/bottom/start add one side; border-0 and border-*-0 remove them.
  • Color (border-primary, border-primary-subtle), width (border-1 to border-5) and opacity (border-opacity-*) refine an existing border.
  • rounded, rounded-0 to rounded-5, side variants, rounded-circle and rounded-pill control corners.
  • shadow-sm, shadow and shadow-lg add depth; shadow-none removes it.
  • Prefer variables-aware classes so borders and shadows adapt to dark mode.

Next lesson: The Utility API.