shoelace/docs/tokens/color.md

49 KiB

Color Tokens

Color tokens help maintain consistent use of color throughout your app. Shoelace provides palettes for theme colors and primitives that you can use as a foundation for your design system.

Usage

Color tokens are referenced using the --sl-color-{name}-{n} CSS custom property, where {name} is the name of the palette and {n} is the numeric value of the desired swatch.

All color tokens are defined as a set of RGB integers, eg. 113 113 122. CSS doesn't understand this format, however, so you need wrap them in the rgb() function.

.example {
  color: rgb(var(--sl-color-neutral-500));
}

This may seem a bit verbose, but it gives us a super power — we can adjust the alpha channel of any color token!

Adjusting Alpha Channels

By default, color tokens produce an opaque color. With this syntax, you can easily adjust alpha channels.

.example-with-alpha {
  color: rgb(var(--sl-color-neutral-500) / 50%);
}

The browser evaluates this to rgb(113 113 122 / 50%), where 50% is the alpha value. Note the required / delimiter after the color token. Alternatively, you can use a decimal such as 0.5 in lieu of a percentage.

This syntax may not look familiar, but it's perfectly valid per the CSS Color Module Level 4 and well-supported by modern browsers.

Theme Tokens

Theme tokens give you a semantic way to reference colors in your app. The primary palette is typically based on a brand color, whereas success, neutral, warning, and danger are used to visualize actions that correspond to their respective meanings.

Primary
--sl-color-primary-{n}
50
100
200
300
400
500
600
700
800
900
950
Success
--sl-color-success-{n}
50
100
200
300
400
500
600
700
800
900
950
Warning
--sl-color-warning-{n}
50
100
200
300
400
500
600
700
800
900
950
Danger
--sl-color-danger-{n}
50
100
200
300
400
500
600
700
800
900
950
Neutral
--sl-color-neutral-{n}
50
100
200
300
400
500
600
700
800
900
950
Black & White
--sl-color-neutral-{n}
0
1000

?> Looking for an easy way to customize your theme? Try the color token generator!

Primitives

Additional palettes are provided in the form of color primitives. Use these when you need arbitrary colors that don't have semantic meaning. Color primitives are derived from the fantastic Tailwind color palette.

Blue Gray
--sl-color-blue-gray-{n}
50
100
200
300
400
500
600
700
800
900
950
Cool Gray
--sl-color-cool-gray-{n}
50
100
200
300
400
500
600
700
800
900
950
Gray
--sl-color-gray-{n}
50
100
200
300
400
500
600
700
800
900
950
True Gray
--sl-color-true-gray-{n}
50
100
200
300
400
500
600
700
800
900
950
Warm Gray
--sl-color-warm-gray-{n}
50
100
200
300
400
500
600
700
800
900
950
Red
--sl-color-red-{n}
50
100
200
300
400
500
600
700
800
900
950
Orange
--sl-color-orange-{n}
50
100
200
300
400
500
600
700
800
900
950
Amber
--sl-color-amber-{n}
50
100
200
300
400
500
600
700
800
900
950
Yellow
--sl-color-yellow-{n}
50
100
200
300
400
500
600
700
800
900
950
Lime
--sl-color-lime-{n}
50
100
200
300
400
500
600
700
800
900
950
Green
--sl-color-green-{n}
50
100
200
300
400
500
600
700
800
900
950
Emerald
--sl-color-emerald-{n}
50
100
200
300
400
500
600
700
800
900
950
Teal
--sl-color-teal-{n}
50
100
200
300
400
500
600
700
800
900
950
Cyan
--sl-color-cyan-{n}
50
100
200
300
400
500
600
700
800
900
950
Sky
--sl-color-sky-{n}
50
100
200
300
400
500
600
700
800
900
950
Blue
--sl-color-blue-{n}
50
100
200
300
400
500
600
700
800
900
950
Indigo
--sl-color-indigo-{n}
50
100
200
300
400
500
600
700
800
900
950
Violet
--sl-color-violet-{n}
50
100
200
300
400
500
600
700
800
900
950
Purple
--sl-color-purple-{n}
50
100
200
300
400
500
600
700
800
900
950
Fuchsia
--sl-color-fuchsia-{n}
50
100
200
300
400
500
600
700
800
900
950
Pink
--sl-color-pink-{n}
50
100
200
300
400
500
600
700
800
900
950
Rose
--sl-color-rose-{n}
50
100
200
300
400
500
600
700
800
900
950