Besides font-size and breakpoints, I’ve also extended Tailwind utilities in the following ways to aid my work.
Border
Tailwind uses the following values for border-width by default:
| Size | Output |
|---|---|
border-1 |
1px |
border-2 |
2px |
| And so on… |
I don’t like this because 1px, 2px and 3px are very easy to write with arbitrary values. We don’t need shorthand for them at all!
So I choose to attach --spacing values for vertical rhythm to border-* instead. This overrides Tailwind defaults and might be a breaking change for some sites!
@utility border-* { border-width: --spacing(--value(number)); border-width: --value([length]);}Border Radius
Tailwind has border radii that go from xs to 4xl. I don’t agree with their scale because it sounds arbitrary and inconsistent.
| Size | Output | Increment |
|---|---|---|
xs |
2px | — |
sm |
4px | +2px |
md |
6px | +2px |
lg |
8px | +2px |
xl |
12px | +4px |
2xl |
16px | +4px |
3xl |
24px | +8px |
4xl |
32px | +8px |
I prefer to treat border-radius like padding and margin where we can simply use the --spacing numbers. That’s because:
- It’s tied to something that is consistent.
--spacingis related to the rhythm that we use on our site
So I extended the border radius utility to include spacing numbers.
@utility rounded-* { border-radius: --spacing(--value(number));}I also extended all utilities for the 4 corners and shorthand utilities for the 4 sides.
@utility rounded-t-* { border-top-left-radius: --spacing(--value(number)); border-top-right-radius: --spacing(--value(number));}
@utility rounded-b-* { border-bottom-left-radius: --spacing(--value(number)); border-bottom-right-radius: --spacing(--value(number));}
@utility rounded-l-* { border-top-left-radius: --spacing(--value(number)); border-bottom-left-radius: --spacing(--value(number));}
@utility rounded-r-* { border-top-right-radius: --spacing(--value(number)); border-bottom-right-radius: --spacing(--value(number));}
@utility rounded-tl-* { border-top-left-radius: --spacing(--value(number));}
@utility rounded-tr-* { border-top-right-radius: --spacing(--value(number));}
@utility rounded-bl-* { border-bottom-left-radius: --spacing(--value(number));}
@utility rounded-br-* { border-bottom-right-radius: --spacing(--value(number));}Finally, I added a utility that adjusts the --radius property that my border-scaffold uses.
@utility radius-* { --radius: --spacing(--value(number));}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