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:
pis the keyword4is 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:
display-relatedwidthandheightmarginandpaddingborderandborder-radius- Font-related
- Colours and gradients
- Others
Display-related properties
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:
mis formarginpis forpadding
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:
mxis used formargin-inlineprobably becausexis the horizontal axis. It’s much easier to recognize thatmh. (Map hack, anyone?).myis used formargin-blockbecauseyis the vertical axis.myis better thanmvfor the same reason. (mv= move?!).ms:sstands forstart.me:estands forend.
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:
border-widthborder-styleborder-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
Font-related keywords in Tailwind is tricky. They don’t really have a consistent pattern. For example:
font-sizeuse thetextkeywordline-heightuse theleadingkeywordfont-familyuse thefontkeywordfont-weightuse thefontkeywordletter-spacinguse thetrackingkeywordfont-styleuse eitheritalicornot-italicwordstext-alignuse thetextkeyword- 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.
Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson