Add a box shadow to an element from the elevation scale, tint it with a context color, or apply it on hover.
Overview
Shadow utilities add or remove a box-shadow. The $enable-component-shadows Sass variable turns the shadows of components on or off; the utility classes apply their shadow whatever its value.
<div class="shadow-none rounded p-md mb-xl">No shadow</div>
<div class="shadow-sm rounded p-md mb-xl">Small shadow</div>
<div class="shadow rounded p-md mb-xl">Medium shadow</div>
<div class="shadow-lg rounded p-md mb-xl">Large shadow</div>
<div class="shadow-inset rounded p-md mb-md">Inset shadow</div>
<div class="shadow-emboss rounded p-md">Emboss shadow</div>Elevation scale
.shadow-{level} classes apply the elevation shadows of the design tokens, named by their level.
This is $cx-shadow-elevation-default-05 shadow.
This is $cx-shadow-elevation-default-10 shadow.
This is $cx-shadow-elevation-default-20 shadow.
This is $cx-shadow-elevation-default-30 shadow.
This is $cx-shadow-elevation-default-40 shadow.
This is $cx-shadow-elevation-default-50 shadow.
This is $cx-shadow-elevation-default-60 shadow.
This is $cx-shadow-elevation-default-70 shadow.
This is $cx-shadow-elevation-default-80 shadow.
This is $cx-shadow-elevation-default-90 shadow.
This is $cx-shadow-elevation-default-95 shadow.
<p class="shadow-05">...</p>
<p class="shadow-10">...</p>
<p class="shadow-20">...</p>
<p class="shadow-30">...</p>
<p class="shadow-40">...</p>
<p class="shadow-50">...</p>
<p class="shadow-60">...</p>
<p class="shadow-70">...</p>
<p class="shadow-80">...</p>
<p class="shadow-90">...</p>
<p class="shadow-95">...</p>Color shadows
An elevation shadow carries one layer whose color is the --cx-shadow-color custom property, transparent by default. A shadow color class sets that property to tint the shadow.
How it works
Each elevation class draws one of its layers in var(--cx-shadow-color, transparent). A .shadow-{context} class sets --cx-shadow-color to the context color at a low alpha, with the CSS relative color syntax, and the layer becomes visible. One color class therefore tints every elevation level, and the stylesheet holds no class per pair of color and level.
.shadow-50 {
box-shadow: 0rem 0.5rem 2rem -0.5rem rgba(0, 0, 0, 0.1), 0rem 0.25rem 1rem -0.25rem var(--cx-shadow-color, transparent), 0rem 0.25rem 1rem -0.25rem rgba(0, 0, 0, 0.1);
}
.shadow-primary {
--cx-shadow-color: oklch(from var(--cx-primary) l c h / 0.2);
}The tint is computed in CSS and is not a design token, so a change of a colored shadow in Figma does not reach it.
Color tinting
Combine an elevation class with a .shadow-{context} class to tint the shadow.
This is $cx-shadow-elevation-primary-05 shadow.
This is $cx-shadow-elevation-primary-10 shadow.
This is $cx-shadow-elevation-primary-20 shadow.
This is $cx-shadow-elevation-primary-30 shadow.
This is $cx-shadow-elevation-primary-40 shadow.
This is $cx-shadow-elevation-primary-50 shadow.
This is $cx-shadow-elevation-primary-60 shadow.
This is $cx-shadow-elevation-primary-70 shadow.
This is $cx-shadow-elevation-primary-80 shadow.
This is $cx-shadow-elevation-primary-90 shadow.
This is $cx-shadow-elevation-primary-95 shadow.
<p class="shadow-primary shadow-05">...</p>
<p class="shadow-primary shadow-10">...</p>
<p class="shadow-primary shadow-20">...</p>
<p class="shadow-primary shadow-30">...</p>
<p class="shadow-primary shadow-40">...</p>
<p class="shadow-primary shadow-50">...</p>
<p class="shadow-primary shadow-60">...</p>
<p class="shadow-primary shadow-70">...</p>
<p class="shadow-primary shadow-80">...</p>
<p class="shadow-primary shadow-90">...</p>
<p class="shadow-primary shadow-95">...</p>Hover shadows
The hover: prefix applies an elevation or shadow color class on :hover only: .hover:shadow-30, .hover:shadow-primary.
This is a hover shadow.
This is a shadow with primary hover.
<p class="shadow-30-hover p-md rounded">This is a hover shadow.</p>
<p class="shadow-primary-hover shadow-50 p-md rounded">This is a shadow with primary hover.</p>CSS
Shadow utilities are generated from Sass maps built on design token values via the utilities API.
Reference
The table lists all shadow utilities and their CSS properties.
| Class | Properties |
|---|---|
.shadow | box-shadow: var(--cx-box-shadow-md); |
.shadow-sm | box-shadow: var(--cx-box-shadow-sm); |
.shadow-lg | box-shadow: var(--cx-box-shadow-lg); |
.shadow-inset | box-shadow: var(--cx-box-shadow-inset); |
.shadow-emboss | box-shadow: var(--cx-box-shadow-emboss); |
.shadow-none | box-shadow: none; |
.shadow-95 | box-shadow: 0rem 1.25rem 5rem -1.25rem rgba(0, 0, 0, 0.1), 0rem 0.625rem 2.5rem -0.625rem var(--cx-shadow-color, transparent), 0rem 0.625rem 2.5rem -0.625rem rgba(0, 0, 0, 0.1); |
.shadow-90 | box-shadow: 0rem 1rem 4rem -1rem rgba(0, 0, 0, 0.1), 0rem 0.5rem 2rem -0.5rem var(--cx-shadow-color, transparent), 0rem 0.5rem 2rem -0.5rem rgba(0, 0, 0, 0.1); |
.shadow-80 | box-shadow: 0rem 0.875rem 3.5rem -0.875rem rgba(0, 0, 0, 0.1), 0rem 0.4375rem 1.75rem -0.4375rem var(--cx-shadow-color, transparent), 0rem 0.4375rem 1.75rem -0.4375rem rgba(0, 0, 0, 0.1); |
.shadow-70 | box-shadow: 0rem 0.75rem 3rem -0.75rem rgba(0, 0, 0, 0.1), 0rem 0.375rem 1.5rem -0.375rem var(--cx-shadow-color, transparent), 0rem 0.375rem 1.5rem -0.375rem rgba(0, 0, 0, 0.1); |
.shadow-60 | box-shadow: 0rem 0.625rem 2.5rem -0.625rem rgba(0, 0, 0, 0.1), 0rem 0.3125rem 1.25rem -0.3125rem var(--cx-shadow-color, transparent), 0rem 0.3125rem 1.25rem -0.3125rem rgba(0, 0, 0, 0.1); |
.shadow-50 | box-shadow: 0rem 0.5rem 2rem -0.5rem rgba(0, 0, 0, 0.1), 0rem 0.25rem 1rem -0.25rem var(--cx-shadow-color, transparent), 0rem 0.25rem 1rem -0.25rem rgba(0, 0, 0, 0.1); |
.shadow-40 | box-shadow: 0rem 0.375rem 1.5rem -0.375rem rgba(0, 0, 0, 0.1), 0rem 0.1875rem 0.75rem -0.1875rem var(--cx-shadow-color, transparent), 0rem 0.1875rem 0.75rem -0.1875rem rgba(0, 0, 0, 0.1); |
.shadow-30 | box-shadow: 0rem 0.3125rem 1.25rem -0.3125rem rgba(0, 0, 0, 0.1), 0rem 0.15625rem 0.625rem -0.15625rem var(--cx-shadow-color, transparent), 0rem 0.15625rem 0.625rem -0.15625rem rgba(0, 0, 0, 0.1); |
.shadow-20 | box-shadow: 0rem 0.25rem 1rem -0.25rem rgba(0, 0, 0, 0.1), 0rem 0.125rem 0.5rem -0.125rem var(--cx-shadow-color, transparent), 0rem 0.125rem 0.5rem -0.125rem rgba(0, 0, 0, 0.1); |
.shadow-10 | box-shadow: 0rem 0.125rem 0.5rem -0.125rem rgba(0, 0, 0, 0.1), 0rem 0.0625rem 0.25rem -0.0625rem var(--cx-shadow-color, transparent), 0rem 0.0625rem 0.25rem -0.0625rem rgba(0, 0, 0, 0.1); |
.shadow-05 | box-shadow: 0rem 0.0625rem 0.25rem -0.0625rem rgba(0, 0, 0, 0.1), 0rem 0.03125rem 0.125rem -0.03125rem var(--cx-shadow-color, transparent), 0rem 0.03125rem 0.125rem -0.03125rem rgba(0, 0, 0, 0.1); |
.shadow-default | --cx-shadow-color: oklch(from var(--cx-default) l c h / 0.2); |
.shadow-alternate | --cx-shadow-color: oklch(from var(--cx-alternate) l c h / 0.2); |
.shadow-primary | --cx-shadow-color: oklch(from var(--cx-primary) l c h / 0.2); |
.shadow-secondary | --cx-shadow-color: oklch(from var(--cx-secondary) l c h / 0.2); |
.shadow-neutral | --cx-shadow-color: oklch(from var(--cx-neutral) l c h / 0.2); |
.shadow-warning | --cx-shadow-color: oklch(from var(--cx-warning) l c h / 0.2); |
.shadow-success | --cx-shadow-color: oklch(from var(--cx-success) l c h / 0.2); |
.shadow-danger | --cx-shadow-color: oklch(from var(--cx-danger) l c h / 0.2); |
.shadow-info | --cx-shadow-color: oklch(from var(--cx-info) l c h / 0.2); |
.shadow-black | --cx-shadow-color: oklch(from var(--cx-black) l c h / 0.2); |
.shadow-white | --cx-shadow-color: oklch(from var(--cx-white) l c h / 0.2); |
Sass variables
The base shadows .shadow, .shadow-sm, and .shadow-lg take three levels of the elevation scale; the inset and emboss shadows are defined in Sass.
$box-shadow-md: $shadow-default-20;
$box-shadow-sm: $shadow-default-05;
$box-shadow-lg: $shadow-default-50;
$box-shadow-inset: inset 0 .125rem .25rem #{to-opacity($black, .125)};
$box-shadow-emboss: inset 0 .0625rem 0 #{to-opacity($white, .15)};
// $box-shadow: $box-shadow-md;Sass maps
Shadow utilities are generated from two maps in scss/maps/_shadows.scss: $base-shadows for the named classes and $default-shadows for the elevation levels.
$base-shadows: (
null: var(--box-shadow-md),
"sm": var(--box-shadow-sm),
"lg": var(--box-shadow-lg),
"inset": var(--box-shadow-inset),
"emboss": var(--box-shadow-emboss),
none: none,
);$default-shadows: (
"95": $shadow-default-95,
"90": $shadow-default-90,
"80": $shadow-default-80,
"70": $shadow-default-70,
"60": $shadow-default-60,
"50": $shadow-default-50,
"40": $shadow-default-40,
"30": $shadow-default-30,
"20": $shadow-default-20,
"10": $shadow-default-10,
"05": $shadow-default-05,
);Design tokens
Shadow utilities consume design tokens from Chassis Tokens with the $cx- prefix. — See the design tokens page.
$shadow-default-95: $cx-shadow-elevation-default-95;
$shadow-default-90: $cx-shadow-elevation-default-90;
$shadow-default-80: $cx-shadow-elevation-default-80;
$shadow-default-70: $cx-shadow-elevation-default-70;
$shadow-default-60: $cx-shadow-elevation-default-60;
$shadow-default-50: $cx-shadow-elevation-default-50;
$shadow-default-40: $cx-shadow-elevation-default-40;
$shadow-default-30: $cx-shadow-elevation-default-30;
$shadow-default-20: $cx-shadow-elevation-default-20;
$shadow-default-10: $cx-shadow-elevation-default-10;
$shadow-default-05: $cx-shadow-elevation-default-05;Utilities API
Shadow utilities are declared in scss/utilities/_index.scss using the utilities API. The elevation utility passes each shadow through a function that turns one of its layers into the --cx-shadow-color layer.
"base-shadow": (
property: box-shadow,
class: shadow,
values: $base-shadows
),"elevation-shadow": (
property: box-shadow,
class: shadow,
state: hover,
enabled: $enable-elevation-shadows,
values: map-loop($default-shadows, make-color-shadow, "$value")
),
"shadow-color": (
property: --shadow-color,
class: shadow,
state: hover,
enabled: $enable-elevation-shadows,
values: map-loop($context-colors, make-shadow-color, "$key")
)