Color System

Comprehensive color system including semantic colors, themes, and status indicators for Crafted UI components

Introduction

Colors are a critical aspect of our design system. Crafted UI uses a semantic color system that assigns meaning to colors beyond their visual appearance. This approach ensures consistent theming, accessibility, and maintainability across all components.

Our color system is built on three main pillars:

  • Semantic Colors: Functional color names that describe purpose rather than appearance
  • Status Colors: Specialized colors for communicating state and feedback
  • Base Colors: Standard color palette for direct color usage
  • Theme Support: Automatic adaptation between light and dark themes

Semantic Colors

Rather than using color names like “green” or “blue,” we use functional names that describe the purpose. This semantic approach allows for easy theming and ensures colors maintain their meaning across different visual styles.

Background Colors

Colors used for component and page backgrounds

b
—background
Text as text-foreground
Base container elements
m
—muted
Text as text-muted-foreground
Secondary container elements
p
—popover
Text as text-popover-foreground
Floating UI elements
c
—card
Text as text-card-foreground
Used for content containers
Foreground Colors

Colors used for text and icons

f
—foreground
Text as text-foreground
Default text color
m
—muted-foreground
Text as text-muted-foreground
Secondary text content
p
—popover
Text as text-popover-foreground
Text on popovers
c
—card
Text as text-card-foreground
Text on card elements
Action Colors

Colors used for interactive elements

p
—primary
Text as text-primary-foreground
Main action buttons
p
—primary-foreground
Text as text-primary
Main highlighted text
s
—secondary
Text as text-secondary-foreground
Alternative buttons
s
—secondary-foreground
Text as text-secondary-foreground
Secondary highlighted text
Accent & Destructive

Colors used for highlights and warnings

a
—accent
Text as text-accent-foreground
Highlighted UI elements
a
—accent-foreground
Text as text-accent-foreground
Text on highlighted areas
d
—destructive
Text as text-destructive-foreground
Destructive actions
d
—destructive-foreground
Text as text-destructive
Destructive action text

Borders & Focus Rings

—border
for component borders and dividers
<div class="border border-border rounded-md p-4">
  Element with border
</div>
—ring
for focus indicators on interactive elements
<button class="focus:ring-2 focus:ring-ring focus:ring-offset-2">
  Focusable element
</button>

Using Semantic Colors

You can access semantic colors through Tailwind utility classes:

<div class="bg-primary text-primary-foreground border border-border">
  This element uses semantic colors
</div>

Color Status Indicators

Crafted UI provides a set of specialized status colors for communicating different states and feedback to users. These colors are designed to be universally understood and accessible.

Status Colors

Colors for communicating state and feedback

—danger
Critical errors and destructive actions such as error messages and delete confirmations
Danger

Something went wrong with your request

—warning
Caution and important notices such as validation warnings and important alerts
Warning

Please review before proceeding

—success
Positive outcomes and confirmations such as success messages and completed actions
Success

Your changes have been saved

—info
Informational messages and tips such as help text and neutral notifications
Info

Here’s some helpful information

Using Status Colors

Status colors are available as Tailwind utility classes and can be used directly in your markup:

<p class="text-danger">Error message</p>
<p class="text-warning">Warning message</p>
<p class="text-success">Success message</p>
<p class="text-info">Info message</p>

Base Colors

In addition to semantic and status colors, Crafted UI supports standard base colors derived from Tailwind’s color palette. These colors can be used directly when you need a specific color rather than a semantic one.

Neutral Colors: slate, gray, zinc, neutral, stone
Warm Colors: red, orange, amber, yellow
Cool Colors: lime, green, emerald, teal, cyan, sky, blue, indigo
Vibrant Colors: violet, purple, fuchsia, pink, rose

Base colors work the same as semantic colors and are available on components that accept the clr prop. Use them when you need a specific color for visual design purposes rather than semantic meaning.

Color Themes

Crafted UI supports both light and dark themes out of the box. All color variables automatically adapt to the current theme, ensuring consistent appearance and proper contrast in both modes.

Light Theme

The light theme uses softer, more neutral colors with appropriate contrast for readability. Background colors are light with darker text, creating a clean and professional appearance suitable for most applications.

Dark Theme

The dark theme inverts the color relationships, using dark backgrounds with light text. It maintains the same semantic color relationships while providing a comfortable viewing experience in low-light environments. Status colors remain consistent but may have adjusted opacity or brightness for optimal contrast.

Theme Comparison

Light Theme
—background
—primary
—secondary
—foreground
Dark Theme
—background
—primary
—secondary
—foreground

Theme Implementation

To implement theme switching in your application, toggle the dark class on your root element:

// Toggle theme
function toggleTheme() {
  document.documentElement.classList.toggle('dark');
}

// Set theme based on user preference
function setTheme(theme) {
  if (theme === 'dark') {
    document.documentElement.classList.add('dark');
  } else {
    document.documentElement.classList.remove('dark');
  }
}

All Crafted UI components will automatically adapt to the current theme without any additional configuration.

Customizing Colors

You can customize any of the color values to match your brand or design requirements. Override the CSS variables in your global styles:

Custom Semantic Colors

:root {
  --primary: hsl(240 100% 50%);     /* Custom blue */
  --secondary: hsl(280 100% 50%);   /* Custom purple */
  --accent: hsl(320 100% 50%);      /* Custom pink */
}

:root[class~="dark"] {
  --primary: hsl(240 100% 60%);     /* Lighter blue for dark mode */
  --secondary: hsl(280 100% 60%);   /* Lighter purple for dark mode */
  --accent: hsl(320 100% 60%);      /* Lighter pink for dark mode */
}

Custom Status Colors

:root {
  --danger: hsl(0 84% 60%);         /* Custom red */
  --warning: hsl(45 93% 47%);       /* Custom orange */
  --success: hsl(120 60% 50%);      /* Custom green */
  --info: hsl(200 100% 50%);        /* Custom blue */
}

Remember to maintain proper contrast ratios for accessibility when customizing colors. Test your color combinations to ensure they meet WCAG guidelines for text contrast.