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

Understanding Tailwind values

7m:15s

You already know that each Tailwind utility has a keyword and a value. We spoke about keywords in the previous lesson, so we’re going to focus on values here.

Categorization

Values can be largely grouped into the following five categories:

  1. Words
  2. Length values
  3. T-shirt sizes
  4. Colours
  5. Custom properties
  6. Arbitrary values

The easiest way to understand how these values work is to place them in context with the keyword groupings we’ve identified in the previous lesson. Once again, the keyword groupings are:

  1. display related
  2. width and height
  3. margin and padding
  4. border and border-radius
  5. Font-related
  6. Colours and gradients
  7. Others

Words

Words are the most common type of value you’ll find — simply because words are commonly used as CSS values.

Here are some examples:

Tailwind CSS Declaration
grid display: grid
flex display: flex
bg-cover background-size: cover
border-solid border-style: solid

Don’t worry about remembering these values. You might check Tailwind’s docs a couple of times in the beginning, but you’ll quickly grasp the common keywords/values you use.

Length values

Length values are used to properties that accept a CSS <length> value. These are properties that accept units like px, em, rem, ch, and lh.

Tailwind provides the following values for each property that can take a length value:

  • px — literally 1px
  • auto — literally auto
  • A spacing value
  • A custom property
  • An arbitrary value

Spacing values are numbers you attach to a <length> related keyword. By default, each spacing integer represents 0.25rem.

Tailwind Utility CSS Property
m-4 margin: 1rem
p-8 padding: 2rem
w-12 width: 3rem
h-10 height: 2.5rem

You may ask: Why perform complicated math when you can simply write 1rem? Well, what I’ve realized is:

  • For values below 3rems: Tailwind’s spacing values provide a huge convenience. (It’s easier to write m-3 than margin: 0.75rem).
  • For values from 3rem to 5rem: Sometimes I use Tailwind’s spacing values; sometimes I don’t.
  • For values above 5rem: Calculating spacing values here slow me down so I simply use CSS values by writing arbitrary values.

Width and Height

width and height properties have a couple of extra values they can use:

  • full
  • fractions
  • container sizes
  • And a couple more (like dvw and dvh) that you will probably never use.

Full sets it to 100%.

Fractions let you write percentages easily without calculating the percentages yourself.

Tailwind CSS
w-1/2 Width: 50%
w-3/4 width: 75%

Container sizes are values that are defined in Tailwind’s container theme values. The default sizes are listed here.

At the time of writing, the default values are:

@theme {
--container-3xs: 16rem;
--container-2xs: 18rem;
--container-xs: 20rem;
--container-sm: 24rem;
--container-md: 28rem;
--container-lg: 32rem;
--container-xl: 36rem;
--container-2xl: 42rem;
--container-3xl: 48rem;
--container-4xl: 56rem;
--container-5xl: 64rem;
--container-6xl: 72rem;
--container-7xl: 80rem;
}

We’ll talk about customizing these values later.

Inset

inset, the shorthand for top, bottom, left, and right, can use the following values along with its longhand counterparts:

  • full
  • fractions

Negative Values

Certain utilities can have negative values — like inset and margin. To use a negative value, add - before the utility.

Tailwind CSS
-m-4 margin: -1rem
-l-4 left: -1rem

These are often length or angle related utilities

Borders

Although border-width can take a length value, Tailwind has decided to implement a very different unit system for it.

For borders, you can use these values:

  1. Numbers
  2. Arbitrary values
  3. Custom properties

Numbers do not represent spacing values in borders. Instead they represent the literal number of pixels.

Tailwind CSS
border-1 border-width: 1px
border-2 border-width: 2px
border-3 border-width: 3px

I dislike this system, so I customized it. We’ll talk about that in detail later.

T-shirt sizes

Tailwind has a number of t-shirt sizes littered around its default values. Here are a couple of examples:

Container Sizes:

@theme {
--container-3xs: 16rem;
--container-2xs: 18rem;
--container-xs: 20rem;
--container-sm: 24rem;
--container-md: 28rem;
--container-lg: 32rem;
--container-xl: 36rem;
--container-2xl: 42rem;
--container-3xl: 48rem;
--container-4xl: 56rem;
--container-5xl: 64rem;
--container-6xl: 72rem;
--container-7xl: 80rem;
}

Font-sizes:

@theme {
--text-xs: 0.75rem;
--text-sm: 0.875rem;
--text-base: 1rem;
--text-lg: 1.125rem;
--text-xl: 1.25rem;
--text-2xl: 1.5rem;
--text-3xl: 1.875rem;
--text-4xl: 2.25rem;
--text-5xl: 3rem;
--text-6xl: 3.75rem;
--text-7xl: 4.5rem;
--text-8xl: 6rem;
--text-9xl: 8rem;
}

Box shadows:

@theme {
--shadow-2xs: 0 1px rgb(0 0 0 / 0.05);
--shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
--shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
--shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
--shadow-lg:
0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
--shadow-xl:
0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
--shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.25);
}

I don’t like using T-shirt sizes because they’re generally unintuitive to me:

  • It takes effort to change sm to 3xl because these values are so different
  • 3xl makes it seem it’s SUPER SUPER SUPER large (based on actual T-shits), but it’s only 1.875rem (or 30px) for font sizes… that seems completely out of proportion

So I use another system for these t-shirt sized values. We’ll talk about this in further detail later.

Color

Tailwind uses a numbered system for colours which range from 50 to 950.

  • 50 means ultra light
  • 950 means ultra dark

Each colour is divided into the following values:

  • 50
  • 100
  • 200
  • 300
  • 400
  • 500
  • 600
  • 700
  • 800
  • 900
  • 950
Note

Notice most numbers are in their hundreds (000) except for 50 and 950? Nobody knows exactly why. But I guess the original scale (100 to 900) had insufficient colours.

I think they set 0 to white and 1000 to black as they’re designing the system, so they have to force-fit everything between 0 and 1000. (This is just a guess).

I often don’t use Tailwind colours because:

  1. I find Tailwind’s darkest colours are still too bright for a dark background
  2. I don’t want my site to look like others sites created with Tailwind

So I define my own colour palette using Tailwind’s numbers as a guide. Again, we’ll talk about this later in the course.

Using a color

To use a colour, you write the keyword, followed by color, followed by the number, like this:

<div class="bg-red-500">...</div>

Custom properties

Tailwind lets you use customer properties as values.

<style>
:root {
--custom-property: some-value;
}
</style>
<div class="keyword-(--custom-property)">...</div>

I’ve never found a use for this syntax.

Arbitrary Values

This is the most useful value of all.

Tailwind lets you insert arbitrary values — which basically means you can pass in anything — when Tailwind’s built-in values don’t work for you.

To use an arbitrary value, you:

  1. Wrap the value with [square_brackets].
  2. Ensure there are no spaces (by replacing spaces_with_underscores).

Here’s are some examples:

Tailwind CSS
p-[1em] padding: 1em
grid-[auto_fr] grid-template-columns: auto 1fr
[--cols:_3] --cols: 3

Arbitrary values are great when:

  • You wanna use units like em and ch that Tailwind doesn’t provide
  • You don’t wanna do the mental multiplication for Tailwind’s spacing values.
  • You wanna set values for CSS custom properties.

As you can see from the above example, setting grid-[auto_fr] for CSS grid can be quite tedious… so we create a utility to skip that hassle. More on this later.

Likewise, we also create the grid-simple utility so you can adjust the number of columns with CSS custom properties instead of remembering Tailwind’s keywords!

<div class="grid-simple [--cols:3]">...</div>

We’ll talk about this in later chapters as well.

That’s it!

By reading through the previous lesson and this one, you’ve gotten a basic understanding of Tailwind’s utility system.

I hope this has helped you understand the docs easily and quickly without having to parse through the nitty gritty details yourself!