Skip to Content

Color

AliasCSS provides a flexible color syntax that works across plain CSS color names, hexadecimal values, color functions, CSS variables, custom colors, and token-based color systems. The goal is to let developers express color in class names without losing access to modern CSS color features.

Color by name

You can write any valid CSS color name after the property name, or in place of a color value inside compound properties.

Examples

ClassnameShorthandCompiled style
color-redc-redcolor:red
background-color-skyBluebgc-skyBluebackground-color:skyBlue
border-color-bluebc-blueborder-color:blue
background-linear-gradient-135deg-blue-skyBluebg-lg-135deg-blue-skyBluebackground:linear-gradient(135deg,blue,skyBlue)
border-1px-solid-blackb-1px-s-blackborder:1px solid black
box-shadow-0px--2px-2px-orangebxs-0px--2px-2px-orangebox-shadow:0px -2px 2px orange
accent-color-pinkNot applicableaccent-color:pink

Usage

<h1 class="color-blue font-size-3rem">Hello, World</h1>

This syntax is the easiest starting point because it stays close to regular CSS naming while still fitting the AliasCSS class model.

Color by hexadecimal

You can also use hexadecimal values without writing the leading #. AliasCSS detects the value and compiles it as a hex color.

Hex values must be 3, 6, or 8 digits.

Examples

ClassnameShorthandCompiled style
color-ff0000c-ff0000color:#ff0000
background-color-ff0000bgc-ff0000background-color:#ff0000
border-color-ff0000bc-ff0000border-color:#ff0000
background-linear-gradient-135deg-ff0000-skyBluebg-lg-135deg-ff0000-skyBluebackground:linear-gradient(135deg,#ff0000,skyBlue)
border-1px-solid-ff0000b-1px-s-ff0000border:1px solid #ff0000
box-shadow-0px--2px-2px-ff0000bxs-0px--2px-2px-ff0000box-shadow:0px -2px 2px #ff0000
accent-color-ff0000Not applicableaccent-color:#ff0000

Usage

<h1 class="color-e3e3e3 bgc-01010e55 font-size-3rem">Hello, World</h1>

The 8-digit form is especially useful when you want alpha directly in the hex value.

Color by function: rgb, rgba, hsl, hsla, hwb, hwba

AliasCSS also supports common CSS color functions by encoding the function name and arguments into the class name.

Examples

ClassnameShorthandCompiled style
color-rgb-255-0-0c-rgb-255-0-0color:rgb(255 0 0)
color-rgba-255-0-0-0.4c-rgba-255-0-0-0.4color:rgba(255 0 0 / 0.4)
background-color-hsl-0-100%-50%bgc-hsl-0-100%-50%background-color:hsl(0 100% 50%)
border-color-hwb-0-0%-0%bc-hwb-0-0%-0%border-color:hwb(0 0% 0%)
border-1px-solid-hsl-0-100%-50%-0.5b-1px-s-hsl-0-100%-50%-0.5border:1px solid hsl(0 100% 50% / 0.5)
box-shadow-0px--2px-2px-rgba-255-0-0-0.8bxs-0px--2px-2px-rgba-255-0-0-0.8box-shadow:0px -2px 2px rgba(255 0 0 / 0.8)
accent-color-rgb-255-0-0Not applicableaccent-color:rgb(255 0 0)
background-color-rgb--primary-colorbgc-rgb--primary-colorbackground-color:rgb(var(--primary-color))

Usage

<h1 class="color-rgb-255-0-0 bgc-hsl-0-100%-0-0.8 font-size-3rem"> Hello, World </h1>

This form is useful when you want precision or want to pass CSS variables into color functions.

Color by function: lab, oklab, lch, oklch

AliasCSS also supports perceptual color spaces such as lab, oklab, lch, and oklch, which are increasingly useful for modern design systems and token workflows.

Examples

ClassnameShorthandCompiled style
color-lab-54.3-106.83-40.85c-lab-54.3-106.83-40.85color:lab(54.3 106.83 40.85)
color-oklab-0.63-0.22-0.13c-oklab-0.63-0.22-0.13color:oklab(0.63 0.22 0.13)
background-color-lch-54.3-106.83-40.85bgc-lch-54.3-106.83-40.85background-color:lch(54.3 106.83 40.85)
border-color-oklch-0.628-0.2577-29.23bc-oklch-0.628-0.2577-29.23border-color:oklch(0.628 0.2577 29.23)
background-color-oklch--primary-colorbgc-oklch--primary-colorbackground-color:oklch(var(--primary-color))

Usage

<h1 class="color-rgb-255-255-225 background-color-lch-54.3-106.83-40.85 font-size-3rem"> Hello, World </h1>
🎨

oklch and related perceptual color spaces are especially useful for token-driven design systems because they make lightness and chroma adjustments more predictable than older color formats.

Custom colors

You can extend the available color library through aliascss.config.js. This is the recommended approach when your project has design tokens, brand colors, semantic UI colors, or theme variables.

aliascss.config.js
const config = { custom: { colors: { themeTextColor: 'var(--theme-text-color,#c3c3c3)', themeBgcolor: 'var(--theme-bg-color,#0e0e0e)', primary: 'rgba(124,143,234,1)', }, }, } export default config

It is safest to use camelCase for custom color names. The AliasCSS npm guide notes that using - or _ in custom color keys may cause errors.

You can read more in the advanced customization docs section for custom colors.

Built-in color systems

AliasCSS can also work with predefined tokenized color systems, which is useful when you want a consistent scale-based naming model instead of raw values. Primary Color System , ---this color system is desgned at untitled.com UI Kit

Radix UI colors

Radix Colors is an open-source, accessible color system designed for UI work. It provides 12-step color scales, matching alpha variants, automatic dark mode support, and guidance for backgrounds, borders, solid fills, and accessible text.

Visit Radix UI Colors 

ClassnameShorthandCompiled styleRemarks
color-slate1c-slate1color:#111113Base Radix scale token
color-slateA11c-slateA11color:#F1F7FEB5Alpha scale token
color-slateThemeA11c-slateThemeA11color:light-dark(#0007149f,#f1f7feb5)Theme-aware token

Radix documents that each scale has twelve steps, each scale includes transparent variants, and dark mode can be switched by applying a class to a container.

React Aria example colors

React Aria itself is style-free by default and is meant to work with any styling system. AliasCSS can expose a React Aria-inspired token system so you can use scale-based color utilities inside a headless component workflow.

Visit React Aria 

ClassnameShorthandCompiled styleRemarks
color-indigoRA100c-indigoRA100color:oklch(from var(--indigoColor,oklch(1 .25049 284.23)) 98.1187% calc(l * c * 0.5) h)RA indicates React Aria-style token naming
color-indigoRATheme100c-indigoRATheme100color:light-dark(oklch(from var(--indigoColor,oklch(1 .25049 284.23)) 98.1187% calc(l * c * 0.5) h),oklch(from var(--indigoColor,oklch(1 .25049 284.23)) 29.6725% calc(l * c * 0.5) h))Theme-aware token based on a base color variable

Usage

<h1 class="color-primary200 background-color-primary800 font-size-3rem"> Hello, World </h1>
ℹ️

React Aria does not ship styles by default. Its components accept standard className and style props, and expose state through data attributes, which makes token-driven systems like AliasCSS a natural fit for styling them.

Alpha values with /

You can also apply alpha by appending /value after a color token. This works with color names, hex values, CSS variables, and custom colors.

It does not apply to function-style colors such as rgb(...), hsl(...), or hwb(...), because those formats already carry their own function-based syntax.

AliasCSS processes this by converting the color through oklch and adjusting the alpha channel.

Examples

ClassnameShorthandCompiled style
color-red/9c-red/9color:oklch(from red l c h / 0.9)
color-red/8c-red/8color:oklch(from red l c h / 0.8)
color-red/7c-red/7color:oklch(from red l c h / 0.7)
color-red/6c-red/6color:oklch(from red l c h / 0.6)
color-red/5c-red/5color:oklch(from red l c h / 0.5)
color-red/4c-red/4color:oklch(from red l c h / 0.4)
color-red/3c-red/3color:oklch(from red l c h / 0.3)
color-red/2c-red/2color:oklch(from red l c h / 0.2)
color-red/1c-red/1color:oklch(from red l c h / 0.1)
color-ffffff/1c-ffffff/1color:oklch(from #ffffff l c h / 0.1)
color-primary600/5c-primary600/5color:oklch(from var(--primary600,#7F56D9) l c h / 0.5)
color--bg-color/7c--bg-color/7color:oklch(from var(--bg-color) l c h / 0.7)

Usage

<h1 class="color-primary200/6 background-color-blue/3 font-size-3rem"> Hello, World </h1>

This is especially handy for overlays, muted text, translucent borders, and token-based UI states.

CSS variables for complex colors

For advanced cases, CSS variables are still the best escape hatch. This is useful when you need color-mix(), relative color syntax, or custom computed values that would be too complex to express directly in an AliasCSS class.

💡

You can always use CSS variables to handle complex color values, then reference those variables from AliasCSS class names.

<h1 class="color--fg1-custom-color background--bg1-custom-color font-size-3rem" style=" --fg1-custom-color: color-mix(in srgb, red, white 20%); --bg1-custom-color: hsl(from var(--primary) h s calc(l - 20%)); " > Hello, World </h1>

Guidance

A practical way to think about color in AliasCSS is:

  • Use named colors for quick prototyping.
  • Use hex values for direct palette work.
  • Use color functions when precision matters.
  • Use oklch and tokens for design-system work.
  • Use custom colors for project-level semantics.
  • Use /alpha for quick opacity control on token-based colors.
  • Use CSS variables when the color logic becomes too dynamic for inline class syntax.

This progression keeps the API easy for beginners while still giving advanced teams access to modern color work

Last updated on