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

A friendlier gradient system

3m:25s

Tailwind’s linear gradients work, but there are a few things I do not like about them:

  • Linear gradients:
    • I don’t like to be limited to three colours
    • Adding colour stops bloats up the HTML with lots of utilities
    • The experience of creating a gradient is not that great
  • Radial gradients:
    • It requires a person to have to almost memorize the radial gradient syntax by heart, which is very difficult to do.

So I went ahead and created a few gradient utilities that are much easier to use.

Linear Gradient

The most common gradient is a linear gradient, so I call it gradient. I also have a linear-gradient version that does the same thing.

@utility gradient {
background-image: linear-gradient(
var(--gradient-angle) in var(--color-space) var(--hue-interpolation),
var(--gradient)
);
}

At a glance, you can see how this can work. There are only 4 variables here and they’re quite straightforward:

  • --gradient: Where we define the actual gradient
  • --gradient-angle: The gradient’s angle
  • --color-space: The color space (defaults to oklch)
  • --hue-interpolation: Changes in hue interpolation if you want — longer-hue or shorter-hue — shorter-hue by default.

Then all I have to do is:

  1. Set the gradient’s angle.
  2. Set the gradient (where I can just pick colors).
.selector {
@apply gradient;
--gradient: var(--color-blue-500), var(--color-pink-500);
--gradient-angle: 120deg;
}

You can use any number of colours — so go crazy if you want!

.selector {
@apply gradient;
--gradient:
var(--color-blue-500), var(--color-pink-500), var(--color-red-500),
var(--color-blue-500), var(--color-orange-500);
--gradient-angle: 120deg;
}

Adding colour stops is also easy with this approach because we can just add them directly next to each other.

.selector {
@apply gradient;
--gradient:
var(--color-blue-500) 20%, var(--color-pink-500) 75%, var(--color-red-500);
--gradient-angle: 120deg;
}

These can work directly in the HTML too. Just set --gradient through an inline style and you don’t have to deal with Tailwind’s underscores_to_denote_spaces syntax.

<div
class="gradient"
style="--gradient: var(--color-blue-500), var(--color-pink-500), var(--color-red-500); --gradient-angle: 120deg"
></div>

Radial gradients

I used the same ideas above to create a radial gradient as well.

@utility radial-gradient {
background-image: radial-gradient(
var(--gradient-shape) var(--gradient-size) at var(--gradient-position) in
var(--color-space) var(--hue-interpolation),
var(--gradient)
);
}

We have a few more variables here in this case:

  • --gradient-shape: The shape of the gradient, either ellipse or circle
  • --gradient-size: The size of the gradient, whose value is one of closest-side, closest-corner, farthest-side, or farthest-corner
  • --gradient-position: Which lets you determine where the center of the gradient should be positioned.

When we have this, we just need to know a few memorable chunks instead of remembering the whole radial gradient syntax. Pretty cool, huh?

.selector {
@apply radial-gradient;
--gradient: var(--color-blue-500), var(--color-red-500);
--gradient-shape: circle;
--gradient-size: farthest-corner;
--gradient-position: 25% 75%;
}

Text gradients

Strictly speaking, I consider text gradients more of an effect rather than a theming thing. But since we’re already talking about gradients, I thought it would be fitting to mention it here.

Creating these utilities is not that hard — you don’t have to be original and think up the techniques yourself, because most of the answers are already out there.

In this case, I simply used Chris Coyier’s solution for gradient text, plus my @gradient utility (and added a bugfix) to form the eventual gradient-text utility.

@utility gradient-text {
@apply gradient;
display: inline-flex;
-webkit-text-fill-color: transparent;
background-clip: text;
/* Allows multiline gradients in Safari */
box-decoration-break: clone;
}

Using this is simple too. You’ve seen everything you need from the examples above:

<h2
class="gradient-text"
style="--gradient: var(--color-blue-500), var(--color-purple-500); --gradient-angle: 120deg"
>
Gradient text
</h2>

Gradient text