Essential CSS
JavaScript Roadmap
Learn JavaScript
Mastering Web Typography
Practical Astro
Understanding Async JS
Unorthodox Tailwind
API Masterclass
Build and Deploy
The Beginner Freelancer
Real World Node
Profile Billing Logout
Unorthodox Tailwind
Lesson Plan
  1. Introduction
    1. Introduction
    2. What Tailwind brings to the table
    3. Tailwind: The Good and The Bad
    4. The First and Most Important Step
    5. Simple Unorthodox System
    6. The System I Use
  2. Tailwind Fundamentals
    1. Introduction
    2. Installing Tailwind
    3. Using Tailwind utilities
    4. Understanding Tailwind’s utility system
    5. Understanding Tailwind values
    6. Understanding Tailwind variants
  3. Unorthodox Fundamentals
    1. Introduction
    2. Making Simple Tailwind Utilities
    3. Components vs Utilities
    4. Specificity, Cascade, and CSS Layers
    5. Debugging Tailwind Styles
    6. Composable Utility System
    7. Create lots of components
  4. Layouts System
    1. Tailwind is great for layouts
    2. Four Types of Layouts
    3. Building Shell Layouts
    4. Building Macro Layouts
    5. Better Responsive Variants
    6. A collection of maximum widths
    7. A note on grid wrappers
    8. Working with sections
    9. Building Micro Layouts
    10. Positioning Layouts
  5. Typography System
    1. Introduction
    2. A system for using multiple typefaces
    3. Tailwind's font-size system
    4. Finding your font-size system
    5. My font-size system
    6. A simple responsive typography system
    7. The main body
    8. Vertical rhythm
  6. Theming System
    1. Introduction
    2. Tailwind's colour system
    3. The pigment system
    4. Tailwind's gradient system
    5. A friendlier gradient system
    6. Handling SVG fill and stroke
    7. Improving Tailwind's colour palette
    8. A simple way to theme
  7. Useful Tools
    1. Introduction
    2. Making functional utilities
    3. Custom variants
    4. Scaffolding tools
    5. Extending Tailwind
  8. Effects System
    1. Introduction
    2. Vertical text
    3. Strikethrough text
    4. Text stroke
    5. Highlighting text
    6. Nicer shadows
    7. Transitioning shadows
    8. Drop shadows
    9. Dark mode tricks
    10. Gradient borders
    11. More effects to explore
  9. Putting Everything Together
    1. The Unorthodox Tailwind process
    2. The 4 systems combined
    3. Create components liberally
    4. Advanced tips
    5. My CSS Structure
    6. A Cheatsheet
    7. Consolidating your thoughts
    8. Parting words

The pigment system

3m:10s

How great would it be if we no longer had to type :hover, :focus, and :active pseudo-classes for each element we want to have an interactive state?

This concept was not even possible in the past. But it’s possible today because we have CSS variables.

Imagine this:

.button {
--bg-color: var(--blue-300);
--text-color: black;
--border-color: var(--color-blue-300);
--bg-hover: var(--color-blue-700);
--text-hover-color: white;
--border-hover-color: var(--color-blue-700);
--bg-active-color: var(--color-blue-800);
--border-active-color: var(--color-blue-800);
}

Versus this:

.button {
background-color: var(--color-blue-300);
color: black;
border: 1px solid var(--color-blue-300);
&:hover,
&:focus {
background-color: var(--color-blue-700);
color: white;
border-color: var(--color-blue-700);
}
&:active {
background-color: var(--color-blue-800);
border-color: var(--color-blue-800);
}
}

We can make this possible by creating a utility that encompasses the logic needed to create the actual CSS properties.

I call this utility pigment.

The Pigment utility

Here’s a simplified version of what it looks like:

@utility pigment-scaffold {
--_bgc: var(--bg-color);
--_tc: var(--text-color, currentcolor);
--_bc: var(--border-color, currentcolor);
border-color: var(--_bc, currentcolor);
color: var(--_tc);
background: var(--_bgc);
&:hover {
--_bgc: var(--bg-hover-color, var(--bg-color));
--_tc: var(--text-hover-color, var(--text-color));
--_bc: var(--border-hover-color, var(--border-color));
}
&:focus {
--_bc: var(
--border-focus-color,
var(--border-hover-color, var(--border-color))
);
--_tc: var(--text-focus-color, var(--text-hover-color, var(--text-color)));
--_bgc: var(--bg-focus-color, var(--bg-hover-color, var(--bg-color)));
}
/* ... continue for active, selected, aria-selected, and other selectors */
}

Does this look like overkill? Yes!

But watch what happens when we use it in practice.

Using Pigment in practice

In every design system, you have buttons of different variations. For example:

  • a primary button for most things
  • a secondary cancel button
  • a big red warning button
  • a button that doesn’t have any background until you interact with it.
  • a button with borders but no background
  • a button with borders and some background, but lightly coloured…

Now that is a lot of different types of buttons. It is a nightmare to try and classify them with semantic names, because you can’t tell which is which!

/* what color is this?
* what style?
* nobody knows */
.button-secondary {
/* ... */
}

But we can classify all of these buttons into four major categories:

  • heavy: saturated background
  • light: light background, possibly with borders
  • outline: borders only, no background
  • ghost: no borders, no background, until you interact with it
Four button variants: heavy, light, outline, and ghost

Then creating the variations of buttons suddenly becomes clear and easy — we can just use CSS variables and the pigment system to style each of these states.

@utility pigment-pink-heavy {
--bg-color: var(--color-pink-600);
--bg-hover-color: var(--color-pink-800);
--text-color: white;
--text-hover-color: white;
--border-color: transparent;
}
@utility pigment-neutral-light {
--bg-color: var(--color-neutral-100);
--bg-hover-color: var(--color-neutral-800);
--text-color: black;
--text-hover-color: var(--color-neutral-50);
--border-color: transparent;
}
@utility pigment-pink-outline {
--bg-hover-color: var(--color-pink-200);
--color: var(--color-pink-600);
--border-color: var(--color-pink-600);
}
@utility pigment-neutral-ghost {
--bg-color: transparent;
--bg-hover-color: var(--color-neutral-200);
--border-color: transparent;
}

Tada!

Notice we never needed to style the focus state?

I’ve realized that for most sites, we can just use the same state for hover, focus and active. So when I designed pigment, I made focus and active inherit from hover, mostly for convenience.

If you want to kick it up a notch, you can always style the focus, active, selected, or even check states.

.your-pigment {
/* focus states */
--bg-focus-color: '#B4D4SS';
--text-focus-color: '#B4D4SS';
--border-focus-color: '#B4D4SS';
/* active states */
--bg-active-color: '#B4D4SS';
--text-active-color: '#B4D4SS';
--border-active-color: '#B4D4SS';
/* selected states */
--bg-selected-color: '#B4D4SS';
--text-selected-color: '#B4D4SS';
--border-selected-color: '#B4D4SS';
}

The nice thing about the selected state is that it also works together with ARIA attributes such as aria-pressed, aria-selected, aria-expanded and aria-current.

The full code

The full code for the pigment utility can be found at Splendid Styles. Check it out if you’re interested!