Most people think Tailwind is simply a substitute for traditional CSS.
It’s not.
Tailwind is three things combined into one:
- A design system
- A styling system
- A build system
If you only think of Tailwind as a CSS substitute, you will not be able to see how Tailwind complements CSS. But you are not to be blamed for thinking that way, because Tailwind proponents market Tailwind as such.
It takes considerable courage, skill, and energy to go beyond what others say to establish rules based on principles.
People who defy what’s established in the world are often seen as madmen — but this is also where all inventions and progress happen.
Well, you can think of me as a lunatic that way. And since you’re digging into this course, I think it’s safe to categorize you as one of us too.
Let’s move on.
A Design System
Tailwind comes with design tokens that force you to define CSS variables in a particular way:
-colour-*: Defines colours—font-*: Defines fonts—spacing-*: Defines spaces
This gives you a system to define your design tokens so you don’t have to start from scratch. It’s a good start, but we can do way better.
A Styling System
Styling System refers to how you style your stuff. Examples of such “hows” include: Normal CSS, Sass, CSS Modules, Tailwind, etc.
Tailwind brings CSS directly to your HTML through its utilities:
<div class="p-4 border-2 rounded-sm">Card</div>And Tailwind can bring its utilities to your CSS too. (This feature is actually a superpower when used right. More on this below).
.selector { @apply p-4 border-2 rounded-sm;}A Build System
Tailwind’s build system does a couple of useful things for us automatically without any configuration:
- We can
@importsmaller CSS files - Use
autoprefixerwithout configuring it - It’s ultra fast (because it uses Lightning CSS under the hood)
Those things help. But what Tailwind truly brings to the picture is its utility system. You can use this to create and use Tailwind utilities on the fly.
@utility vertical { display: flex; flex-direction: column;}Once the vertical utility is defined, you can use it in the HTML directly, or in CSS via the @apply keyword.
<div class="vertical">...</div>/* What you write */.some-selector { @apply vertical;}
/* Output CSS */.some-selector { display: flex; flex-direction: column;}Like good old Sass mixins, Tailwind’s utility system unlocks a ton of possibilities. The difference is Tailwind’s utilities are a lot more convenient to create (and use) than Sass’s mixins.
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