Tailwind, as explained on their official website, is a utility-first CSS framework packed with classes like flex, pt-4, text-center
and rotate-90
that can be composed to build any design, directly in your markup.
As a beginner, writing pure CSS was very good since it helped in understanding and memorizing the rules needed to achieve a specific layout. I had a lot of experience in doing this, however, none brought me the satisfaction and productivity boost that TailwindCSS has. Tailwind has a very basic syntax.
Here is an example of how it looks like:
<figure class="bg-gray-100 rounded-xl">
<img class="w-32 h-32" src="/sarah-dayan.jpg" alt="" width="384" height="512">
<div class="pt-6 space-y-4">
<blockquote>
<p class="text-lg">
“Tailwind CSS is the only framework that I've seen scale
on large teams. It’s easy to customize, adapts to any design,
and the build size is tiny.”
</p>
</blockquote>
<figcaption>
<div>
Sarah Dayan
</div>
<div>
Staff Engineer, Algolia
</div>
</figcaption>
</div>
</figure>
Each class represents a CSS declaration. In the example above pt-6
represents padding-top: 1.5rem;
This will generate the following:
Tailwind has a myriad of benefits compared to custom CSS
Writing code in one place can be faster and more interesting other than jumping from file to file, this can help to focus more on the task at hand. At times this may become messy, especially when working on large projects.
Tailwind guarantees a consistent bundle size since utility class names can be shared between elements. For unused CSS, Tailwind is paired with purge CSS which removes extra classes on the codebase.
Writing Tailwind CSS is much faster compared to writing CSS or CSS-in-JS. Text editors and IDEs automatically help us with the autocomplete and formatting, however, in order to trigger the autocomplete we have to write the selectors and pieces of declarations.
In addition, variants in Tailwind have prefixes which can be added to classes, representing a specific CSS pseudo-class or custom plugins.
Also, Tailwind has a lot of pre-built classes mainly for sizing and colouring, this will reduce or completely remove the need to implement a design system.
Developers can extend or modify classes in the tailwind.config.js
file. One can tamper right into Tailwind and can also add custom plugins, changes made will be reflected in the final stylesheet.
Inside this file, one can create normal CSS classes.
When a considerate amount of classes are added to an element, it may become daunting to read.
With correct component abstractions, this can be easily solved.
Archiving complex animations is very hard.
One would have to create a class for each element in order to use plain CSS, this will end up in doing more work.
The use of libraries can also be used to solve this.
Some CSS properties are not included.
In my journey Tailwind has helped in increasing my productivity, reducing the bundle size of my apps and making me more consistent.
Although it may have worked well for me and many other developers, it doesn't mean it is the perfect solution for every project.
Us front-end developers as long as we guarantee maintainability, scalability, and performance, Tailwind is definitely the best solution considering its myriad of benefits.