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

Tailwind's colour system

3m:12s

Tailwind has a great colour system that is derived from Steve Schoger’s Refactoring UI.

Tailwind's full colour palette

The basic idea is that you can refer to a colour with the name (like red) and a corresponding shade number (like 500).

<p class="text-red-500">Red text</p>

Red text

Where colours can be applied

Tailwind allows you to use the colours with many utilities, but in practice I only use it on three of them.

  • bg-* - for background colour
  • text-* - for text colour
  • border-* - for border colour

Here’s the full list of utilities you can use the colour system with.

Full list of Tailwind utilities that support the colour system

I only use the three I mentioned because I have another system for SVGs, outlines and shadows. I’ll talk more about these later in the course.

Controlling opacity of colours

Tailwind has a very nice way to control the opacity of its colours. You can add a slash followed by the opacity value like (bg-red-500/25) to add the opacity to this colour.

<div class="bg-red-500/25">Red with opacity</div>
Red
Red with opacity

Doing this in CSS

If you use @apply, the color/opacity syntax also works in CSS.

.selector {
@apply bg-red-500/25; /* this works */
}

But if you want to use the CSS variable, you have to write the color-mix function yourself.

/* equivalent to the above output */
.selector {
background: color-mix(in oklab, var(--color-red-500) 25%, transparent);
}

This kind of thing is difficult to write, so I recommend you either use the Tailwind version or use a function like --alpha when CSS functions have baseline support.

@function --alpha(--color, --amount) {
result: color-mix(in oklab, var(--color) var(--amount), transparent);
}

Colours on interactive variants

These colours can also be used together with variants such as hover:, focus:, active: to change the colour when the element goes into a different state.

Here’s an example where the button turns to a different background colour and text colour on hover.

<button class="bg-blue-300 hover:bg-blue-700 text-black hover:text-white">
Button
</button>

Unfortunately, the code gets annoying, repetitive, and bloated if you want to include more states.

If you want to set the colour and background colour for this button on the standard state, hover, focus, active, you need to set eight utilities — this is hardly maintainable.

State Utility for background Utility for text
Normal bg-blue-300 text-black
Hover hover:bg-blue-700 hover:text-white
Focus focus:bg-blue-700 focus:text-white
Active active:bg-blue-800 active:text-white
<button
class="
bg-blue-300 hover:bg-blue-700 focus:bg-blue-700 active:bg-blue-800
text-black hover:text-white focus:text-white active:text-white"
>
Button
</button>

It gets way worse if you want to include a border or even handle transitional states…

I shudder to even write that code here…

<button
class="
bg-blue-300 hover:bg-blue-700 focus:bg-blue-700 active:bg-blue-800
text-black hover:text-white focus:text-white active:text-white
border border-blue-300 hover:border-blue-700 focus:border-blue-700 active:border-blue-800"
>
Button
</button>

So it’s quite clear to see that Tailwind sucks when it comes to colours and theming with interactive states — this is where CSS is much better.

.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);
}
}

But it is also tedious to keep writing hover, focus, and active states for each element — especially if you have a lot of them.

So I came up with something far better called the pigment system, and I’m going to introduce that to you in the next lesson.