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

Highlighting text

4m:42s

I promised, so this will start getting a bit more complex. Not because it needs to be complex, but because the complexity gives you different variations you can use.

Now, there are many ways to highlight text. Here are some examples out in the wild:

Adding a rounded box
Rotating the box
Highlight a portion of the text
Skewing the box

The first two are pretty obvious. They don’t add much visual interest so we won’t be talking about them. But the 3rd and 4th one — ooh. They’re nice.

Building the 3rd effect

Unlike text-stroke, I didn’t find good resources to build this. So I came up with an easy technique myself.

The idea is to add a linear-gradient as the background-image. Then we can control the position of the highlight by adjusting where we want the highlight to start and end.

@utility highlight {
display: inline;
background-image: linear-gradient(
transparent 0 var(--highlight-start, 0),
var(--highlight-color) var(--highlight-start, 0) var(--highlight-end, 1lh),
transparent var(--highlight-end, 1lh)
);
box-decoration-break: clone;
}

Hey There, Sexy.

If we want this utility to work across multiline text, we need to make sure it’s inline and has box-decoration-break: clone.

@utility highlight {
display: inline;
box-decoration-break: clone;
/* ... */
}

Hey There, Sexy. Now the multiline version works perfectly.

I’ll be honest. I kinda stopped here… But when I was writing this lesson, I chanced upon the skewed box and I thought it looked pretty dang cool.

Skewing the box

So I improved my highlight utility to support this.

Building the 4th effect

Vadim Makeev came up with this technique and blogged about it in A CSS Challenge: Skewed Highlight. I encourage you to read it to get a sense of what happened.

In the article, Vadim explains that you can’t skew a background, so he had to construct a 3-part background with gradients:

Note

You can skew() a pseudo element to achieve the same effect here, but pseudo elements don’t work with box-decoration-break, so we have to use Vadim’s method.

He also had to adjust the background-size and background-position to make this work. So the code ends up being a little bit complex. But the idea is simple: 3 gradients, 3 positions, 3 sizes — one set for each.

/* example from Vadim's article */
mark {
background-color: transparent;
background-image:
linear-gradient(to bottom right, transparent 50%, #f8db75 50% 100%),
linear-gradient(to right, #f8db75, #f8db75),
linear-gradient(to top left, transparent 50%, #f8db75 50%);
background-size:
0.25em 1em,
calc(100% - 0.25em * 2 + 1px) 1em,
0.25em 1em;
background-position:
left center,
center,
right center;
background-repeat: no-repeat;
}

This allows us to skew the background. In this case, Vadim set the left and right boxes to be 0.25em. But we can use a CSS variable for it.

@utility highlight {
/* ... */
margin-inline: calc(var(--highlight-skew) * -1);
padding-inline: var(--highlight-skew);
background-size:
var(--highlight-skew) 1em,
calc(100% - var(--highlight-skew) * 2 + 1px) 1em,
var(--highlight-skew) 1em;
/* ... */
}

Hey There, Sexy. The multiline version still works perfectly.

But how can we include the height adjustment from what we had before? Turns out, it’s not too hard.

Height adjustments

I still want to use --highlight-start and --highlight-end to control the size of the highlighted background. To support this, we have to adjust the background-size and background-position correspondingly.

@utility highlight {
/* ... */
--_highlight-height: calc(var(--highlight-end) - var(--highlight-start));
background-position:
left var(--highlight-start),
center var(--highlight-start),
right var(--highlight-start);
background-size:
var(--highlight-skew) var(--_highlight-height),
calc(100% - var(--highlight-skew) * 2 + 1px) var(--_highlight-height),
var(--highlight-skew) var(--_highlight-height);
}

Now we can adjust the start and end position:

Hey There, Sexy. The multiline version still works perfectly.

This is beautiful.

Then, I had another wild idea — what if we could support gradients here? That’ll be so cool!

Supporting gradients

Turns out, it’s possible.

Here we just have to set the starting gradient color and ending gradient color in the background-image rule. And we’ll fallback to highlight-color if these gradients are not found.

We can also use --gradient-angle to determine the gradient’s angle. But we have to split --gradient into gradient-start and gradient-end because we need to put them separately in the two skewed boxes.

Since we’re composing this from 3 different boxes… this gradient can be rather finicky. But it works between 45deg and 135deg.

@utility highlight {
background-image:
linear-gradient(
to bottom right,
transparent 50%,
var(--gradient-start, var(--highlight-color)) 50%
),
linear-gradient(
var(--gradient-angle, to right),
var(--gradient-start, var(--highlight-color)),
var(--gradient-end, var(--highlight-color))
),
linear-gradient(
to top left,
transparent 50%,
var(--gradient-end, var(--highlight-color)) 50%
);
}

Hey There, Sexy. The multiline version still works perfectly.

There we go! I hope you enjoyed this weird little trick to make your headings stand out even more!

Now let’s dive into shadows.