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 Styles and Unorthodox Tailwind.

On this page, you’ll find a basic guide on using Tailwind with Splendid Styles.

What we use Tailwind for

In Splendid Layouts, we use Tailwind for two things:

  1. Adjusting layouts on the fly
  2. Responsive variants

Adjusting layouts on the fly

Tailwind utilities are great for adjusting layouts without additional CSS customization. One example is using vertical with items-* utilities to adjust the alignment of items.

<div class="vertical"> ... </div>
<div class="vertical items-start"> ... </div>
<div class="vertical items-center"> ... </div>
<div class="vertical items-center"> ... </div>

Tailwind also contains utilities that let you adjust the following values easily:

  • 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.

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

Tailwind’s default 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…

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: Instead of using spacing values, Tailwind’s border utilities creates borders in pixels.

ClassProperties
border-0border-width: 0px;
border-1border-width: 1px;
border-2border-width: 2px;
border-3border-width: 3px;
……

We find this unintuitive, so we fixed this in our layouts 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)

Unfortunately, Tailwind has decided to use rather unintuitive values for border-radius:

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…

So we added utilities that use spacing values to adjust the border radius.

ClassEffect
rounded-1border-radius: 0.25rem
rounded-2border-radius: 0.5rem
rounded-3border-radius: 0.75rem
rounded-*And so on…

Responsive variants

Tailwind’s responsive variants are amazing for creating responsive layouts without additional CSS customization. This can be useful for one-time layouts.

Here’s an example that creates a 1-column layout on mobile and 2-column layout on tablet viewports.

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

By default, Tailwind provides you with the following responsive 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 default responsive variants are insufficient as they box you into device breakpoints. We believe we shouldn’t use device breakpoints, but we should adjust the layout based on when the content requires it, so we included variants from 100px to 2000px with the bp variant.

Each integer here represents a breakpoint at 100px.

VariantEffect
bp1@media (min-width: 100px) { ... }
bp1.5@media (min-width: 150px) { ... }
bp2@media (min-width: 200px) { ... }
bp2.5@media (min-width: 250px) { ... }
bp3@media (min-width: 300px) { ... }
bp3.5@media (min-width: 350px) { ... }
bp4@media (min-width: 400px) { ... }
bp4.5@media (min-width: 450px) { ... }
bp5@media (min-width: 500px) { ... }
bp5.5@media (min-width: 550px) { ... }
bp6@media (min-width: 600px) { ... }
bp6.5@media (min-width: 650px) { ... }
bp7@media (min-width: 700px) { ... }
bp7.5@media (min-width: 750px) { ... }
bp8@media (min-width: 800px) { ... }
bp8.5@media (min-width: 850px) { ... }
bp9@media (min-width: 900px) { ... }
bp9.5@media (min-width: 950px) { ... }
bp10@media (min-width: 1000px) { ... }
……

The same bp* variant works with container modifiers too. Just use @bp* as the variant instead.

Unorthodox Tailwind

We believe in using Tailwind and CSS in a synergistic manner — leveraging the strengths of both systems — instead of littering your DOM with utility classes. This mini-tailwind guide here scratches the surface of what we wrote in Unorthodox Tailwind.

Give that a try if you’re interested in learning more!