Skip to main content Skip to docs navigation

Use border utilities to quickly style the border and border-radius of an element. Great for images, buttons, or any other element.

Border

Use border utilities to add or remove an element’s borders. Choose from all borders or one at a time.

Additive

Add borders to custom elements:

html
<span class="border"></span>
<span class="border-top"></span>
<span class="border-end"></span>
<span class="border-bottom"></span>
<span class="border-start"></span>

Subtractive

Or remove borders:

html
<span class="border border-0"></span>
<span class="border border-top-0"></span>
<span class="border border-end-0"></span>
<span class="border border-bottom-0"></span>
<span class="border border-start-0"></span>

Color

Border utilities like .border-* that generated from our original $context-colors Sass map don’t yet respond to color modes, however, any .border-*-subtle utility will. This will be resolved in v6.

Change the border color using utilities built on our theme colors.

html
<span class="border default-border-main"></span>
<span class="border default-border-subtle"></span>
<span class="border alternate-border-main"></span>
<span class="border alternate-border-subtle"></span>
<span class="border primary-border-main"></span>
<span class="border primary-border-subtle"></span>
<span class="border secondary-border-main"></span>
<span class="border secondary-border-subtle"></span>
<span class="border neutral-border-main"></span>
<span class="border neutral-border-subtle"></span>
<span class="border danger-border-main"></span>
<span class="border danger-border-subtle"></span>
<span class="border success-border-main"></span>
<span class="border success-border-subtle"></span>
<span class="border warning-border-main"></span>
<span class="border warning-border-subtle"></span>
<span class="border info-border-main"></span>
<span class="border info-border-subtle"></span>
<span class="border black-border-main"></span>
<span class="border black-border-subtle"></span>
<span class="border white-border-main"></span>
<span class="border white-border-subtle"></span>

Or modify the default border-color of a component:

Dangerous heading
Changing border color and width
html
<div class="mb-large">
  <label for="exampleFormControlInput1" class="form-label">Email address</label>
  <input type="email" class="form-input border-success" id="exampleFormControlInput1" placeholder="name@example.com">
</div>

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

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

Opacity

Chassis CSS border-{color} utilities are generated with Sass using CSS variables. This allows for real-time color changes without compilation and dynamic alpha transparency changes.

How it works

Consider our .border-primary utility.

.border-primary {
  border-color: oklch(from var(--cx-primary) l c h / var(--cx-border-opacity, 1)) !important;
}
.border-opacity-50 {
  --cx-border-opacity: var(--cx-opacity-50);
}

We use the --cx-primary CSS variable directly with CSS relative color syntax, and attach a second CSS variable, --cx-border-opacity, for the alpha transparency (with a default value 1). The oklch(from ...) expression derives the color from the variable and applies the opacity channel. Then, the opacity class overrides the default opacity by setting --cx-border-opacity on the element.

Example

To change that opacity, override --cx-border-opacity via custom styles or inline styles.

This is default primary border
This is 50% opacity primary border
html
<div class="border border-primary p-2xsmall mb-small">This is default primary border</div>
<div class="border border-primary p-2xsmall" style="--cx-border-opacity: .5;">This is 50% opacity primary border</div>

Or, choose from any of the .border-opacity utilities:

This is -opacity-100- primary border

This is -opacity-75- primary border

This is -opacity-50- primary border

This is -opacity-25- primary border

This is -opacity-10- primary border

This is -opacity-0- primary border

html
<p class="border border-primary border-opacity-100 p-2xsmall">This is -opacity-100- primary border</p>
<p class="border border-primary border-opacity-75 p-2xsmall">This is -opacity-75- primary border</p>
<p class="border border-primary border-opacity-50 p-2xsmall">This is -opacity-50- primary border</p>
<p class="border border-primary border-opacity-25 p-2xsmall">This is -opacity-25- primary border</p>
<p class="border border-primary border-opacity-10 p-2xsmall">This is -opacity-10- primary border</p>
<p class="border border-primary border-opacity-0 p-2xsmall">This is -opacity-0- primary border</p>

Context Border

You can directly apply a context opacity utility to match obj-* colors:

This is base-color primary border
This is cx-border-main opacity primary border
This is cx-border-subtle opacity primary border
html
<div class="border border-primary p-2xsmall mb-small">This is <code>base-color</code> primary border</div>
<div class="border border-primary border-opacity-main p-2xsmall mb-small">This is <code>cx-border-main</code> opacity primary border</div>
<div class="border border-primary border-opacity-subtle p-2xsmall mb-small">This is <code>cx-border-subtle</code> opacity primary border</div>

Width

html
<span class="border border-small"></span>
<span class="border border-medium"></span>
<span class="border border-large"></span>
<span class="border border-xlarge"></span>
<span class="border border-2xlarge"></span>

Radius

Add classes to an element to easily round its corners.

Example rounded image75x75 Example top rounded image75x75 Example right rounded image75x75 Example bottom rounded image75x75 Example left rounded image75x75 Completely round image75x75 Example pill image150x75
html
<img src="..." class="rounded" alt="...">
<img src="..." class="rounded-top" alt="...">
<img src="..." class="rounded-end" alt="...">
<img src="..." class="rounded-bottom" alt="...">
<img src="..." class="rounded-start" alt="...">
<img src="..." class="rounded-circle" alt="...">
<img src="..." class="rounded-pill" alt="...">

Sizes

Use the scaling classes for larger or smaller rounded corners. Sizes range from 0 to 5 including circle and pill, and can be configured by modifying the utilities API.

Example non-rounded image75x75 Example extra small rounded image75x75 Example small rounded image75x75 Example default rounded image75x75 Example large rounded image75x75 Example larger rounded image75x75 Example extra large rounded image75x75 Example extra extra large rounded image75x75 Completely round image75x75 Rounded pill image150x75
html
<img src="..." class="rounded-zero" alt="...">
<img src="..." class="rounded-xsmall" alt="...">
<img src="..." class="rounded-small" alt="...">
<img src="..." class="rounded-medium" alt="...">
<img src="..." class="rounded-large" alt="...">
<img src="..." class="rounded-xlarge" alt="...">
<img src="..." class="rounded-2xlarge" alt="...">
<img src="..." class="rounded-3xlarge" alt="...">
<img src="..." class="rounded-circle" alt="...">
<img src="..." class="rounded-pill" alt="...">
Example small rounded image75x75 Example default left rounded image75x75 Example right completely round image75x75 Example left rounded pill image75x75 Example extra extra large bottom rounded image75x75
html
<img src="..." class="rounded-bottom-xsmall" alt="...">
<img src="..." class="rounded-start-medium" alt="...">
<img src="..." class="rounded-end-circle" alt="...">
<img src="..." class="rounded-start-pill" alt="...">
<img src="..." class="rounded-2xlarge rounded-top-0" alt="...">

CSS

This component can be customized using CSS variables, allowing for styles to be modified dynamically on the page. These CSS variables are part of Chassis CSS's design token system, giving design teams control over component appearance. See the design tokens page for more details.

Variables

These CSS variables control the component's appearance and can be modified dynamically on the page. Components use cascading variables, allowing seamless variations in size, color, and style without redundant style declarations through component inheritance and the context class system.

--#{$prefix}border-width: #{$border-width};
--#{$prefix}border-style: #{$border-style};
--#{$prefix}border-color: #{$border-color};
--#{$prefix}border-radius: #{$border-radius};

Sass variables

These Sass variables are also exposed as CSS custom properties using the --cx- prefix. A Sass variable $variable-name becomes available as --cx-variable-name in CSS, allowing for styles to be modified dynamically on the page. See the context components page for more details.

$border-width:                $border-width-medium;
$border-color:                $default-border-main;
$border-style:                solid;
$border-width-zero:         $cx-border-width-context-zero;
$border-width-small:        $cx-border-width-context-small;
$border-width-medium:       $cx-border-width-context-medium;
$border-width-large:        $cx-border-width-context-large;
$border-width-xlarge:       $cx-border-width-context-xlarge;
$border-width-2xlarge:      $cx-border-width-context-2xlarge;
$border-radius-zero:        $cx-border-radius-context-zero;
$border-radius-xsmall:      $cx-border-radius-context-xsmall;
$border-radius-small:       $cx-border-radius-context-small;
$border-radius-medium:      $cx-border-radius-context-medium;
$border-radius-large:       $cx-border-radius-context-large;
$border-radius-xlarge:      $cx-border-radius-context-xlarge;
$border-radius-2xlarge:     $cx-border-radius-context-2xlarge;
$border-radius-3xlarge:     $cx-border-radius-context-3xlarge;
$border-radius-round:       $cx-border-radius-context-round;

Sass maps

$border-widths: (
  zero:          $border-width-zero,
  small:         $border-width-small,
  medium:        $border-width-medium,
  large:         $border-width-large,
  xlarge:        $border-width-xlarge,
  2xlarge:       $border-width-2xlarge,
);
$border-radiuses: (
  zero:               $border-radius-zero,
  xsmall:             $border-radius-xsmall,
  small:              $border-radius-small,
  medium:             $border-radius-medium,
  large:              $border-radius-large,
  xlarge:             $border-radius-xlarge,
  2xlarge:            $border-radius-2xlarge,
  3xlarge:            $border-radius-3xlarge,
  circle:             50%,
  round:              $border-radius-round,
  pill:               $border-radius-round,
);

Color mode adaptive border colors are also available as a Sass map:

Sass mixins

/// Apply `border-radius` when `$enable-rounded-borders` is `true`.
/// Falls back to `$fallback-border-radius` when rounded borders are disabled
/// and a fallback is provided.
///
/// @param {Number|String} $radius [var(--cx-border-radius)] - Radius value
/// @param {Number|false} $fallback-border-radius [false] - Fallback radius when rounded borders are disabled
@mixin border-radius($radius: var(--#{$prefix}border-radius), $fallback-border-radius: false) {
  @if $enable-rounded-borders {
    border-radius: valid-radius($radius);
  }
  @else if $fallback-border-radius != false {
    border-radius: $fallback-border-radius;
  }
}

/// Apply `border-radius` to the top two corners (top-left and top-right).
///
/// @param {Number|String} $radius [$border-radius] - Radius value
@mixin border-top-radius($radius: $border-radius) {
  @if $enable-rounded-borders {
    border-top-left-radius: valid-radius($radius);
    border-top-right-radius: valid-radius($radius);
  }
}

/// Apply `border-radius` to the two right (end) corners (top-right and bottom-right).
///
/// @param {Number|String} $radius [$border-radius] - Radius value
@mixin border-end-radius($radius: $border-radius) {
  @if $enable-rounded-borders {
    border-top-right-radius: valid-radius($radius);
    border-bottom-right-radius: valid-radius($radius);
  }
}

/// Apply `border-radius` to the two bottom corners (bottom-right and bottom-left).
///
/// @param {Number|String} $radius [$border-radius] - Radius value
@mixin border-bottom-radius($radius: $border-radius) {
  @if $enable-rounded-borders {
    border-bottom-right-radius: valid-radius($radius);
    border-bottom-left-radius: valid-radius($radius);
  }
}

/// Apply `border-radius` to the two left (start) corners (top-left and bottom-left).
///
/// @param {Number|String} $radius [$border-radius] - Radius value
@mixin border-start-radius($radius: $border-radius) {
  @if $enable-rounded-borders {
    border-top-left-radius: valid-radius($radius);
    border-bottom-left-radius: valid-radius($radius);
  }
}

/// Apply `border-radius` to the top-left corner only.
///
/// @param {Number|String} $radius [$border-radius] - Radius value
@mixin border-top-start-radius($radius: $border-radius) {
  @if $enable-rounded-borders {
    border-top-left-radius: valid-radius($radius);
  }
}

/// Apply `border-radius` to the top-right corner only.
///
/// @param {Number|String} $radius [$border-radius] - Radius value
@mixin border-top-end-radius($radius: $border-radius) {
  @if $enable-rounded-borders {
    border-top-right-radius: valid-radius($radius);
  }
}

/// Apply `border-radius` to the bottom-right corner only.
///
/// @param {Number|String} $radius [$border-radius] - Radius value
@mixin border-bottom-end-radius($radius: $border-radius) {
  @if $enable-rounded-borders {
    border-bottom-right-radius: valid-radius($radius);
  }
}

/// Apply `border-radius` to the bottom-left corner only.
///
/// @param {Number|String} $radius [$border-radius] - Radius value
@mixin border-bottom-start-radius($radius: $border-radius) {
  @if $enable-rounded-borders {
    border-bottom-left-radius: valid-radius($radius);
  }
}

Sass utilities API

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

"border": (
  property: border,
  values: (
    null: var(--#{$prefix}border-width) var(--#{$prefix}border-style) var(--#{$prefix}border-color),
    0: 0,
  )
),
"border-top": (
  property: border-top,
  values: (
    null: var(--#{$prefix}border-width) var(--#{$prefix}border-style) var(--#{$prefix}border-color),
    0: 0,
  )
),
"border-end": (
  property: border-right,
  class: border-end,
  values: (
    null: var(--#{$prefix}border-width) var(--#{$prefix}border-style) var(--#{$prefix}border-color),
    0: 0,
  )
),
"border-bottom": (
  property: border-bottom,
  values: (
    null: var(--#{$prefix}border-width) var(--#{$prefix}border-style) var(--#{$prefix}border-color),
    0: 0,
  )
),
"border-start": (
  property: border-left,
  class: border-start,
  values: (
    null: var(--#{$prefix}border-width) var(--#{$prefix}border-style) var(--#{$prefix}border-color),
    0: 0,
  )
),
"border-color": (
  css-var: true,
  css-variable-name: border-color,
  class: border,
  values: map-loop($context-colors, opacity-var, #{"$key"}, #{"border"})
),
"border-width": (
  property: border-width,
  //css-var: true,
  class: border,
  values: map-loop($border-widths, varify, "$key", "border-width")
),
"border-opacity": (
  css-var: true,
  css-variable-name: border-opacity,
  class: border-opacity,
  values: $border-opacities
),
"rounded": (
  property: border-radius,
  class: rounded,
  values: map-merge(
    (
      null: var(--#{$prefix}border-radius)
    ),
    $border-radiuses,
  )
),
"rounded-top": (
  property: border-top-left-radius border-top-right-radius,
  class: rounded-top,
  values: map-merge(
    (
      null: var(--#{$prefix}border-radius)
    ),
    $border-radiuses,
  )
),
"rounded-end": (
  property: border-top-right-radius border-bottom-right-radius,
  class: rounded-end,
  values: map-merge(
    (
      null: var(--#{$prefix}border-radius)
    ),
    $border-radiuses,
  )
),
"rounded-bottom": (
  property: border-bottom-right-radius border-bottom-left-radius,
  class: rounded-bottom,
  values: map-merge(
    (
      null: var(--#{$prefix}border-radius)
    ),
    $border-radiuses,
  )
),
"rounded-start": (
  property: border-bottom-left-radius border-top-left-radius,
  class: rounded-start,
  values: map-merge(
    (
      null: var(--#{$prefix}border-radius)
    ),
    $border-radiuses,
  )
),