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

Strikethrough text

3m:49s

In CSS, you can do strikethrough text with text-decoration-line. To create this in Tailwind, you can use the line-through utility.

<span class="line-through"> strikethrough </span>
strikethrough

This text decoration is quite versatile. You can control a strikethrough’s color, thickness, and style — just like a normal text decoration.

<span class="line-through decoration-wavy decoration-red-500 decoration-2">
strikethrough
</span>

strikethrough

But it cannot create a strikethrough that is commonly used in pricing cards like the one shown below.

Example of a custom strikethrough used on a pricing card

Creating a custom strikethrough

For this kind of strikethrough, we want a few things:

  1. We want to control its thickness
  2. It needs to be of a different colour from the body text
  3. It should be centered with the text.
  4. And we need to be able to rotate it.

CSS text-decoration-line can control the first three items, but it cannot do the last one. So we have to build a custom strikethrough.

I think the best place to put this strikethrough is on a pseudo-element. When we do this, we can add strikethrough to the parent element, and the strikethrough will occur.

<!-- ideal usage -->
<div class="strikethrough">$541</div>

Here’s the CSS to create this strikethrough:

@utility strikethrough {
position: relative;
display: inline-block;
&::after {
content: '';
pointer-events: none;
position: absolute;
top: 50%;
left: 0;
right: 0;
height: var(--strike-width, 0.125em);
background: var(--strike-color, currentColor);
transform: translateY(-50%) rotate(var(--strike-angle, 0deg));
transform-origin: center;
}
}

Most of the CSS is straightforward, so I shall not explain much, but here are a few things to note:

  1. position: absolute with top and translateY allows the strikethrough to be centered vertically.
  2. rotate lets it be rotated.
  3. height and background give the strikethrough the thickness and colour we desire
  4. We can use --strike-color, --strike-width and --strike-angle to adjust the strikethrough to what we want.

Once you have that utility, you can use it like this:

<span
class="strikethrough"
style="--strike-color: var(--color-red-500); --strike-width: 0.15em; --strike-angle: 10deg"
>
$541
</span>

$541

You might think it’s ugly to write CSS variables as inline styles…

I agree — especially when there are so many variables here! But I’m okay with this, since I probably only use it once for the entire site. If I want to use it on multiple pages, I can always put them into a reusable class.

Don’t forget that CSS is your friend here!

.strikethrough {
--strike-color: var(--color-red-500);
--strike-width: 0.15em;
--strike-angle: -10deg;
}

That said, we can also write functional utilities to make this easier to use if you prefer the Tailwind version.

Building functional utilities

We’re going to create 2 utilities.

  • strike-*: For width and color
  • strike-angle-*: For angle

For width, let’s say we want to use the --spacing value. We also want to take in an arbitrary length value.

As for color, we’d want to match it with --color-* and allow for [color] values. Since we’re dealing with colours, it’s best to add the alpha --modifier as well.

@utility strike-* {
/* For strike-width */
--strike-width: --spacing(--value(number));
--strike-width: --value([length]);
/* For strike-color */
--strike-color: --value(--color-*, [color]);
--strike-color: oklch(
from --value(--color-*, [color]) l c h / --modifier(number)
);
}

If the utility above looks absolutely foreign to you, I highly recommend you read the functional utility lesson again. I promise it will make sense as you go through it again.

Next, for --strike-angle, I want to write something like strike-angle-10.

We cannot use strike-* as the utility because 10 is a number, so strike-10 will create a width. This is why we don’t have much of a choice but to use a different utility name — and strike-angle describes this best.

@utility strike-angle-* {
--strike-angle: --value(number)deg;
--strike-angle: --value([angle]);
}

Lastly, we need to create an inverse strike-angle utility to support negative values for the angle.

@utility -strike-angle-* {
--strike-angle: calc(--value(number) * -1deg);
--strike-angle: calc(--value([angle]) * -1);
}

Now we can use our functional utilities like this:

<div class="strikethrough strike-0.5 strike-red-500 -strike-angle-10"></div>

$541

A little bit nicer, but I’ll say that’s not much of a difference in this context. At the very least, you got real good hands-on practice with creating functional utilities!