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’s utility system

7m:4s

Understanding Tailwind’s built-in utilities is an important precursor to knowing how Tailwind works. But it can be a ton of work since there’s hundreds of utilities (and with hundreds of CSS properties).

So this lesson (and the next) is here to help you get up to speed quickly.

Keyword and Value Pairs

Most built-in Tailwind utilities can be better understood as a keyword and value pair. Here’s a quick example:

<div class="p-4">...</div>

In this case:

  • p is the keyword
  • 4 is the value

In this lesson, we’ll cover essential things you need to know about the keyword. Then in the next lesson, we’ll talk about values.

Tailwind Keywords

Tailwind has a unique keyword mechanism that helps you map a keyword to a CSS property quite intuitively. Most of these keywords are short-form of the longer CSS property.

Here are some examples:

Tailwind Keyword Created CSS Property
p padding
m margin
w width

Tailwind’s keyword can also create different properties based on the value attached to them. Here are some examples:

Tailwind Keyword Created CSS Property
border Can be:
- border-width
- border-style
- border-colour
bg Can be:
- background
- background-color
- background-image
- background-position
- background-size
- …

I categorize Tailwind’s keywords into these 7 groups for easier recall:

  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

This category houses utilities that alter the display property. Most of these properties don’t contain the display keyword. But the keyword themselves are a CSS value.

Here are the ones you should know:

Tailwind utility CSS declaration
hidden display: none
block display: block
inline-block display: inline-block
inline display: inline
grid display: grid
flex display: flex

These values are nothing surprising. Like I said, Tailwind’s keywords and values are quite intuitive if you already know CSS.

I also place keywords that go with the above display properties in this category since they’re “display-related”. Examples of these include:

Tailwind keyword CSS Property
grid-cols-* grid-template-cols: *
grid-rows-* grid-template-rows: *
gap-* gap: *
justify-* justify-content: *
items-* align-items: *

* is a placeholder for a value. Find out more about values in the next lesson.

Width and Height

This is the second set of keywords I deem important — I use them quite a bit with the Unorthodox Tailwind methodology.

They’re also pretty straightforward:

Tailwind keyword CSS property
w width
min-w min-width
max-w max-width
h height
min-h min-height
max-h max-height

Tailwind also contains the size keyword that lets you set the width and height to the same value simultaneously.

Margin and Padding

margin and padding are pretty straightforward:

  • m is for margin
  • p is for padding

Like CSS Properties, you can also set margin and padding on one or two sides.

Tailwind Keyword CSS Property
mt margin-top
mb margin-bottom
ml margin-left
mr margin-right
my margin-block
mx margin-inline
ms margin-inline-start
me margin-inline-end

There are a couple of interesting things to regarding the keywords for logical properties:

  • mx is used for margin-inline probably because x is the horizontal axis. It’s much easier to recognize that mh. (Map hack, anyone?).
  • my is used for margin-block because y is the vertical axis. my is better than mv for the same reason. (mv = move?!).
  • ms: s stands for start.
  • me: e stands for end.

Unexpectedly, there’s no keyword for margin-block-start and margin-block-end so use mt or mb instead.

Padding follows the same keywords patterns as margin. So just substitute m with p.

Borders

Borders are slightly more complex keywords in Tailwind because it can represent three different CSS properties:

  1. border-width
  2. border-style
  3. border-colour

To specify borders for a specific side, you can follow the same keyword patterns used for margin and padding, except you use border instead of m or p.

Tailwind Keyword CSS Property
border-t border-top
border-b border-bottom
border-l border-left
border-r border-right
border-y border-block
border-x border-inline
border-s border-inline-start
border-e border-inline-end

We’ll talk about border-colour in a bit, and border-style in the next lesson.

Border radius

Tailwind chose the keyword rounded to signify border-radius. This keyword is so different from the CSS property, you’ll find it difficult to get used to at first.

To specify the border-radius for a single corner, you can use rounded plus the corner keyword.

Tailwind Keyword CSS Property
rounded-tl border-top-left-radius
rounded-tr border-top-right-radius
rounded-bl border-bottom-left-radius
rounded-br border-bottom-right-radius

If you want to round both corners on one side (like top-left and top-right at the same time), you can just specify the side.

Tailwind Keyword CSS Property
rounded-t border-top-left-radius: *;
border-top-right-radius: *
rounded-b border-bottom-left-radius: *;
border-bottom-right-radius: *
rounded-l border-top-left-radius: *;
border-bottom-left-radius: *
rounded-r border-top-right-radius: *;
border-bottom-right-radius: *

You can also use s and e if you want to create borders with logical properties for the left and right corners.

Tailwind Keyword CSS Property
rounded-s border-start-start-radius: *;
border-end-start-radius: *
rounded-e border-start-end-radius: *;
border-end-end-radius: *

That’s pretty much it for border-radius

Font-related keywords in Tailwind is tricky. They don’t really have a consistent pattern. For example:

  • font-size use the text keyword
  • line-height use the leading keyword
  • font-family use the font keyword
  • font-weight use the font keyword
  • letter-spacing use the tracking keyword
  • font-style use either italic or not-italic words
  • text-align use the text keyword
  • text-decoration use words (like underline, overline, etc).

So there are no quick guidelines for font-related keywords. The best approach is to simply check Tailwind’s documentation and get familiar with the ones you normally use.

Colours

When it comes to colours, we’re often interested in just three things.

  • background-color
  • text color
  • border-color

The keywords Tailwind chose for these three types of color are relatively straightforward.

Tailwind CSS declaration
bg-<color>-* background-color: *
text-<color>-* color: *
border-<color>-* border-color: *

Gradients

Tailwind provides you with keywords for the three kinds of gradients we can create with CSS. Each time has a keyword extension that is relevant to that type of gradient

Tailwind keyword Gradient Type
bg-linear Linear Gradient
bg-radial Radial Gradient
bg-conic Conic Gradient

Each gradient can have up to three colours, defined by the from, via and to keywords. from and to are compulsory. via is optional.

Tailwind keyword What it’s for
from-<color> Starting colour
via-<color> Intermediary colour (optional)
to-<color> Ending colour

To be honest, I think Tailwind gradients are kinda complex. So I prefer using the custom gradient utility. I’ll talk about this later in the theming chapter.

Other groups

Once you know the above keywords, the rest of the Tailwind keywords become relatively straightforward.

Just check Tailwind’s documentation and you should be able to find what you’re looking for — without being alarmed or surprised at how intuitive (or unintuitive) the keyword (or value) is.

That’s it for now. In the next lesson we’ve dive deeper into Tailwind values.

I hope you’re loving this breakdown of Tailwind utilities.