Using Tailwind
Tailwind has two major and opposing sentiments:
- Tailwind is the best and everyone should ditch CSS for it.
- 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:
- Adjusting layouts on the fly
- 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.
Class | Effect |
---|---|
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
):
Class | Effect |
---|---|
w-1 | width: 0.25rem |
w-2 | width: 0.5rem |
w-3 | width: 0.75rem |
w-4 | width: 1rem |
w-* | And so on… |
Margin
Tailwind uses m
to denote margins. There are three shorthands for adjusting margin values:
Class | Effect |
---|---|
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:
Class | Effect |
---|---|
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
.
Class | Effect |
---|---|
m-1 | margin: 0.25rem |
m-2 | margin: 0.5rem |
m-3 | margin: 0.75rem |
m-4 | margin: 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
.
Class | Effect |
---|---|
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
:
Class | Effect |
---|---|
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:
Class | Effect |
---|---|
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.
Class | Properties |
---|---|
border-0 | border-width: 0px; |
border-1 | border-width: 1px; |
border-2 | border-width: 2px; |
border-3 | border-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.
Class | Effect |
---|---|
rounded | Sets border-radius of all 4 corners |
rounded-t | Sets border-radius of the top 2 corners |
rounded-b | Sets border-radius of the bottom 2 corners |
rounded-l | Sets border-radius of the left 2 corners |
rounded-r | Sets border-radius of the right 2 corners |
rounded-s | Sets border-radius of the 2 corners at the start of the inline axis |
rounded-e | Sets 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.
Class | Effect |
---|---|
rounded-tl | Sets border-radius of the top left corner |
rounded-tr | Sets border-radius of the top right corner |
rounded-bl | Sets border-radius of the bottom left corner |
rounded-br | Sets border-radius of the bottom right corner |
rounded-ss | Sets border-radius of the start-start corner (top-left in ltr ) |
rounded-se | Sets border-radius of the start-end corner (top-right in ltr ) |
rounded-es | Sets border-radius of the end-start corner (bottom-left in ltr ) |
rounded-ee | Sets border-radius of the end-end corner (bottom-right in ltr ) |
Unfortunately, Tailwind has decided to use rather unintuitive values for border-radius
:
Class | Effect |
---|---|
rounded-none | border-radius: 0px |
rounded | border-radius: 0.125rem |
rounded-sm | border-radius: 0.25rem |
rounded-md | border-radius: 0.375rem |
rounded-lg | border-radius: 0.5rem |
rounded-* | And so on… |
So we added utilities that use spacing values to adjust the border radius.
Class | Effect |
---|---|
rounded-1 | border-radius: 0.25rem |
rounded-2 | border-radius: 0.5rem |
rounded-3 | border-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:
Variant | Effect |
---|---|
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
.
Variant | Effect |
---|---|
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!