Using Tailwind

Tailwind has two major and opposing sentiments:

  1. Tailwind is the best and everyone should ditch CSS for it.
  2. Tailwind is 🤢🤮.

Neither sentiment is true — we don’t have to replace style sheets with Tailwind. We also don’t have to completely ditch Tailwind either. Instead, we can use Tailwind and CSS in a synergistic way where their strengths complement each other.

The result of that synergistic exploration is Splendid Layouts and Splendid Styles (docs for Splendid Styles coming soon…).

How we will use Tailwind

We will use Tailwind for two things:

  1. Adjusting simple values on the fly
  2. Responsive variants

Adjusting Simple Values

We use Tailwind utilities to modify these properties on the fly:

  • width
  • height
  • gap
  • margin
  • padding
  • border
  • border-radius

Below is everything you need to know about adjusting these values.

Width and Height

Tailwind uses w to denote width and h to denote height. You can change Tailwind’s width and height values by using the class (w or h) with a spacing value.

Occassionally, very occasionally, you may also need to use change max-width and max-height values.

Note

We say “very occasionally” because max-width is rarely needed in Splendid Layouts. We’ve taken care of this for you by setting max-width: 100% on relevant layout classes.

ClassEffect
w-*Sets width
h-*Sets height
max-w-*Sets max-width
max-h-*Sets max-height

Tailwind’s spacing values are as follows. (Each integer represents 0.25rem):

ClassEffect
w-1width: 0.25rem
w-2width: 0.5rem
w-3width: 0.75rem
w-4width: 1rem
w-*And so on…
Note

Unfortunately, Tailwind’s spacing values use an unusual scale with gaps between values. We found this unintuitive, so we’ve extended spacing values from 0 to 100 in our layouts preset.

Margin

Tailwind uses m to denote margins. There are three shorthands for adjusting margin values:

ClassEffect
m-*Sets margin on all four sides
mx-*Sets margin-inline (for the horizontal axis)
my-*Sets margin-block (for the vertical axis)

You can also set margin values on one side with the following classes:

ClassEffect
mt-*Sets margin-top
mb-*Sets margin-bottom
ml-*Sets margin-left
mr-*Sets margin-right
ms-*Sets margin-inline-start
me-*Sets margin-inline-end

Tailwind also uses spacing values for margin.

ClassEffect
m-1margin: 0.25rem
m-2margin: 0.5rem
m-3margin: 0.75rem
m-4margin: 1rem
m-*And so on…

Padding

Tailwind denotes padding with p. Everything I have mentioned above about margin applies to padding, the only difference is you have to replace m with p.

ClassEffect
p-*Sets padding on all four sides
px-*Sets padding-inline (for the horizontal axis)
py-*Sets padding-block (for the vertical axis)
…And so on…

Border

Tailwind uses the border keyword for border-related operations. Their classes look more complex than m and p because of the keyword difference, but the same rules apply.

Here are shorthands for adjusting border-width:

ClassEffect
border-*Sets border on all four sides
border-x-*Sets border-inline on the horizontal axis
border-y-*Sets border-block on the vertical axis

If you wish to adjust borders on a single side, you can use the following classes:

ClassEffect
border-t-*Sets border-top
border-b-*Sets border-bottom
border-l-*Sets border-left
border-r-*Sets border-right
border-s-*Sets border-inline-start
border-e-*Sets border-inline-end

Here’s a significant difference: Tailwind only provides 5 border-width values.

ClassProperties
border-0border-width: 0px;
borderborder-width: 1px;
border-2border-width: 2px;
border-4border-width: 4px;
border-8border-width: 8px;

We find this unintuitive, so we fixed this in our layouts preset.

Note

We added values from 1px to 8px and also extended Tailwind spacing values to borders in the preset.

Border radius

Tailwind uses the rounded keyword for border radius. This is more complex compared to the above properties because there more variations.

Here are Tailwind’s border radius shorthands.

ClassEffect
roundedSets border-radius of all 4 corners
rounded-tSets border-radius of the top 2 corners
rounded-bSets border-radius of the bottom 2 corners
rounded-lSets border-radius of the left 2 corners
rounded-rSets border-radius of the right 2 corners
rounded-sSets border-radius of the 2 corners at the start of the inline axis
rounded-eSets border-radius of the 2 corners at the end of the inline axis

If you need to adjust only one radius, you can specify that corner or use their respective logical properties.

ClassEffect
rounded-tlSets border-radius of the top left corner
rounded-trSets border-radius of the top right corner
rounded-blSets border-radius of the bottom left corner
rounded-brSets border-radius of the bottom right corner
rounded-ssSets border-radius of the start-start corner (top-left in ltr)
rounded-seSets border-radius of the start-end corner (top-right in ltr)
rounded-esSets border-radius of the end-start corner (bottom-left in ltr)
rounded-eeSets border-radius of the end-end corner (bottom-right in ltr)

Tailwind has decided to use rather unintuitive values for border-radius as well:

ClassEffect
rounded-noneborder-radius: 0px
roundedborder-radius: 0.125rem
rounded-smborder-radius: 0.25rem
rounded-mdborder-radius: 0.375rem
rounded-lgborder-radius: 0.5rem
rounded-*And so on…

We also made this more intuitive by extending Tailwind’s spacing values to border radius in our layouts preset.

Note

Sometimes we prefer to use Tailwind’s border radius utilities, other times we prefer to write plain ol’ CSS. Your mileage may vary here. Don’t feel forced to use the utilities if you don’t like them!

Responsive variants

Tailwind’s responsive variants let you change properties and CSS variables at predefined breakpoints.

Here’s a list of built-in variants:

VariantEffect
sm@media (min-width: 640px) { ... }
md@media (min-width: 768px) { ... }
lg@media (min-width: 1024px) { ... }
xl@media (min-width: 1280px) { ... }
2xl@media (min-width: 1536px) { ... }

We feel that Tailwind’s responsive variants are insufficient since we shouldn’t use device breakpoints, so we’ve added numerious variants — from 50px to 2000px — in our layouts preset.

Note

We talked about how to use these variants in using CSS Variables. Please read that page if you need a refresher!

A note on Typography and Colours

Naturally, we’ve made our own enhancements to Tailwind’s Typography and Color utilities. These fall under Splendid Styles, so we’ll continue that discussion there if you’re interested.