Codebase 6’s color utility class system is based on using the modern CSS oklch() function and a series of interpolated lightness variables that enable the lightness level utility classes to work.
oklch()
The lightnsses for color each class are not pre-created, unlike with other CSS frameworks. E.g. if you want a light green background color, there's no bg-green-100. Instead you choose the color and lightness level separately, as bg-green bg-100. Handled this way, the stylesheet doesn’t need to be loaded with lighness classes for every color — most of which you’d never use.
bg-green-100
bg-green bg-100
The oklch() function has been baseline: widely available since March 2023. All “evergreen” browsers (Chrome, Edge, Firefox, Safari) have capability to use it (see Can I use).
In setting up the lightness utility classes, Codebase’s oklch() formulas take the hue (h) and chroma (c) values out of the base color variables, and adjusts the lightness level (l) to 50% (matching Codebase’s built-in middle lightness, i.e. --l500). This enables a perceptually uniform system of lightness levels.
--l500
The seven Codebase built-in theme colors are set using Hex # codes). But if/when you add your own in all other color system, the oklch() formulas can handle it.
#
Example using background bg-* utility classes (the background lightness is declared separately):
bg-*
bg-{lightness}
bg-100
bg-200
bg-300
bg-400
bg-500
bg-600
bg-700
bg-800
bg-900
bg-blue
bg-green
bg-amber
bg-red
bg-purple
bg-teal
bg-gray
Also available: black, white, and transparent (background only) — see other Codebase color utilities.
black
white
transparent
All colors and lightness levels are declared in variables.css.
variables.css
Color utility classes (declared in @layer color in colors.css) are prefixed acording to where the color will be applied — border b-* text t-* or background bg-*. I have named the colors according to their common names (blue, green, amber, red, gray). You can modify the root variables of these colors, and you can add your own colors.
@layer color
colors.css
b-*
t-*
b-100
b-900
hover:b-100
hover:b-900
t-100
t-900
hover:t-100
hover:t-900
hover:bg-100
hover:bg-900
Example border, text and background utilities:
<div class="b-heavy b-green"></div> <div class="t-heavy t-green t-700"></div> <div class="t-black bg-green bg-300"></div>
Example usage:
<div aria-label="Note" class="popout my-3 bl-heavy b-blue b-400 p-2 bg-blue bg-100"> ☆ Note (information) panel. </div>
The lighness modifiers *-100 through *-900, if used alone, do not provide color. But if you use them to supplement one of the base colors above, then that color class will provide the color, and the modifier will set its lightness level.
*-100
*-900
In any color model, color combinations must be chosen with care so that there is sufficient contrast between text and background colors for purposes of assessibility.
In your text and background color combinations, be careful to ensure that the text is readable — there needs to be an adequate contrast. Most organizations should to aim for WCAG level AA for accessibility requirements.
For WCAG level AA conformance, most user interface colors need to be mid-level (i.e. use *-500 up) if the text color is white, or lighter than the mid-level (i.e. use *-400 down) if the text color is black.
*-500
*-400
For your convenience, Codebase has a set of user interface color component name classes that can be used on buttons, badges, labels, form element borders, panels, etc.
Background reading on colors and accessibility:
If you want to incorporate your own colors alongside Codebase 6, to use the same lightness modifier classes, then you first need to understand how Codebase handles color. It’s a 4-step process:
The 7 baselayer colors are first declared as CSS variables:
:root { /* Codebase 6 theme base colors */ --blue: #0074d9; --green: #2ecc40; --amber: #ffdc00; --red: #ff4136; --purple: #b10dc9; --teal: #39cccc; --gray: #767676; }
The utility class lightness level suffixes go up in hundreds, from -100 to -900. The lower the number, the lighter the color, although the higher % lightness.
-100
-900
:root { --l100: 97%; /* in gray, this gives ~ #f5f5f5 */ --l200: 86.1%; --l300: 77.75%; --l400: 67.35%; --l500: 57.5%; --l600: 47.65%; --l700: 37.75%; --l800: 27.85%; --l900: 21%; /* in gray, this gives ~ #f181818 */ }
In the variables file, Codebase colors are set up using the formula. For example, in the base text color:
:root { --tc-base: oklch(from var(--gray) var(--l900) c h); }
Finally, the variable is used in a style rule:
body { color: var(--tc-base); }
You can, of course, add any colors you want, and in any format you want. But if you want to add colors in a way that integrates with the Codebase system, do this:
:root{}
@layer
Other color utilities included in Codebase cover black, white, and transparent (for background only, as an override).
Black and white are explicitly named colors in baselayer. They do not have lightness levels.
*-black
hover:*-black
*-white
hover:*-white
<div class="t-white bg-black">...</div> <div class="t-black bg-white">...</div>
If you want “lightness levels” between white and black, then use grays.
b-transparent
bg-transparent
Note: there are no text or hover states of *-transparent.
*-transparent
Example usage: transparent (“ghost”) buttons.
Button
bg-glass
bg-blur
bg-filter
You will see no effect from these classes unless you place them on a panel in front of a photo or complex pattern. Intended for use in conjunction with background colors and shades.
Examples:
bg-white
bg-black
Docs