DEV Community

Cover image for TailwindCSS vs Tachyons
Brian Neville-O'Neill
Brian Neville-O'Neill

Posted on • Originally published at blog.logrocket.com on

TailwindCSS vs Tachyons

Written by Anjolaoluwa Adebayo-Oyetoro✏️

Frontend development involves architecting the markup, style, and behavior of web pages. Knowledge of CSS is one of the most important skills needed to build for the web and it isn’t exactly the easiest skill to acquire.

CSS frameworks were developed to make styling web content easier and done more efficiently while solving cross-browser compatibility concerns. CSS frameworks have become a norm and they have come to stay.

In this article, we will take a look at the strengths and weaknesses of two of the most popular utility-first CSS frameworks out there — TailwindCSS and Tachyons.

What is utility-first CSS?

For a library to be considered utility-first, it means it offers no pre-configured styles and components to build with, rather it offers you a set of unopinionated building blocks known as utility/helper classes to help you style your components. This helps with creating custom designs without having to override unwanted styles.

Utility-first CSS frameworks are often called functional or atomic CSS.

Prerequisites

This tutorial assumes the reader has the following:

LogRocket Free Trial Banner

What is Tachyons?

According to the documentation:

A tachyon /ˈtæki.ɒn/ or tachyonic particle is a hypothetical particle that always moves faster than light. The word comes from the Greek αχύς or tachys, meaning “swift, quick, fast, rapid”.

Tachyons CSS however, is a functional CSS framework for humans built for designing and creating fast-loading, highly readable, and 100% responsive interfaces with as little custom CSS as possible.

What is Tailwind?

According to its official documentation:

Tailwind CSS is a highly customizable, low-level CSS framework that gives you all of the building blocks you need to build bespoke designs without any annoying opinionated styles you have to fight to override.

Installation and usage

Tailwind and Tachyons can be made available in a project either by installation via package managers or using the CDN build.

Installing and using Tailwind

You can get started with using Tailwind in your project by simply pulling in the latest default configuration build via CDN:

<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
Enter fullscreen mode Exit fullscreen mode

Note: Many features of Tailwind CSS are not available using the CDN build. To get the most out of Tailwind, you really should install it using a package manager.

Using a package manager

To install Tailwind with the Yarn package manager, type in the following command in your terminal:

yarn add tailwindcss
Enter fullscreen mode Exit fullscreen mode

Next, proceed to create a default configurations scaffold, this helps to customize your Tailwind installation using the Tailwind CLI utility included when you install the tailwindcss package:

npx tailwind init --full
Enter fullscreen mode Exit fullscreen mode

This command creates a tailwind.js file in your project’s base directory, the file houses all of Tailwind’s default configuration.

Next, create a tailwind.css file where we would be importing Tailwind’s base styles and configurations, type in the following command:

touch tailwind.css
Enter fullscreen mode Exit fullscreen mode

Use the @tailwind directive to inject Tailwind’s base, components, and utilities styles into your CSS, place the following content in your tailwind.css file:

@tailwind base;

@tailwind components;

@tailwind utilities;
Enter fullscreen mode Exit fullscreen mode

Compile and build the styles generated from your tailwind.css file with the Tailwind CLI utility tool, run this command:

npx tailwindcss build tailwind.css -o styles.css
Enter fullscreen mode Exit fullscreen mode

Then proceed to import your styles.css file into your app. Either in your JavaScript file like this:

import 'styles.css';
Enter fullscreen mode Exit fullscreen mode

or as a link in your HTML like this:

<link href="tailwind.css" rel="stylesheet">
Enter fullscreen mode Exit fullscreen mode

Installing and using Tachyons

To add the CDN build in your project, copy the line of code below and paste it in the head of the HTML file(s) you want to include Tachyons in:

<link rel="stylesheet" href="https://unpkg.com/tachyons@4/css/tachyons.min.css">
Enter fullscreen mode Exit fullscreen mode

Using a package manager

To install Tachyons using the Yarn package manager, type the following command in your terminal:

yarn add tachyons
Enter fullscreen mode Exit fullscreen mode

Next, create a tachyons.css file, like this:

touch tachyons.css
Enter fullscreen mode Exit fullscreen mode

Copy the content of the minified version of Tachyons. This file is located at node_modules/tachyons/css/tachyons.min.css to your tachyons.css file:

cp node_modules/tachyons/css/tachyons.min.css tachyons.css
Enter fullscreen mode Exit fullscreen mode

Then, proceed to import your tachyons.css file into your app. Either in your JavaScript file:

import 'tachyons.css';
Enter fullscreen mode Exit fullscreen mode

or as a link in your HTML:

<link href="tachyons.css" rel="stylesheet">
Enter fullscreen mode Exit fullscreen mode

Alternatively, we can install Tachyons by grabbing all the source files and build it locally.

First, clone the source repository:

git clone git@github.com:tachyons-css/tachyons.git
Enter fullscreen mode Exit fullscreen mode

Next, change the directory to the cloned project:

cd tachyons
Enter fullscreen mode Exit fullscreen mode

Then proceed to install the necessary packages and build the styles:

npm install && npm start
Enter fullscreen mode Exit fullscreen mode

You should see both an unminified and a minified CSS file to the /css directory.

Ease of use

Although both libraries set out to achieve similar goals and using them is straightforward. The process of installing Tachyons is not quite straightforward and seamless.

Documentation is another factor that helps with the usage of a library. The documentation for Tailwind is rich and quite extensive, it does a great job of introducing and onboarding users to the library. With Tachyons, on the other hand, one might be left confused after reading the documentation as it takes a bland approach to onboard and introduces new users of the library.

Community

Despite it being launched almost a year after Tachyons, Tailwind has amassed 21.8k stars on GitHub and it is being used by 38,749 repositories and has over a 100 contributors, it also has 73,791 weekly downloads on NPM.

tailwind css github

tailwinds additions and deletions

Tachyons has 9.7k stars on GitHub, has 64 contributors, and has 26,384 weekly downloads on NPM.

tachyons github

tachyons additions and deletions

Both libraries GitHub code frequency also shows Tailwind CSS is being actively worked on thereby ensuring it stays up to date with the latest standards and improvements to the web.

Tailwind has also managed to build a community around the tool, with resources such as Screencasts and other assets that aid the usage of the framework. Tailwind has also been adopted by big companies like Algolia and Mozilla and used to build new startups like RightMessage and PingPing.

Tachyons also has a collection of resources and a tutorial to aid development with the framework it is also being used by some pretty huge companies such as Font Awesome, NPM, and Hugo. Tachyons also has backers and sponsors who donate to support the development of the framework.

Size and performance

Size is one of the most important things developers consider when exploring a framework and that is one comparison Tachyons excels at.

Tachyons original file size is 111.7kb but is 14kb when minified and gzipped.

Using the default configuration, Tailwind CSS comes in at 78.0kb minified and gzipped and has an original size of 783.5kb and offers a handful of file reduction strategies:

Framework Original size Minified Gzip Brotli
Tachyons 111.7kb 71.8kb 13.4kb 7.5kb
Tailwind 783.5kb 603.3kb 78.0kb 22.6kb

Using the CSS Stats tool, we can see a bit more about the minified files for both frameworks.

Tailwind uses 14,445 rules and 14,505 selectors while Tachyons has 2,113 rules and 2,349 selectors that means Tailwind comes with more defaults, while Tachyons contains fewer rules than Tailwind and it is not as flexible either.

You can see more stat details for Tailwind and for Tachyons.

Developer experience

Plugins

One of the advantages of Tailwind over Tachyons is the fact that its configuration uses JavaScript. This gives you all the power of JavaScript and makes it easy to extend Tailwind’s capabilities with third-party plugins or building your own utilites, custom variants, and components as plugins.

Components and naming

Most modern workflows follow the DRY principle (Don’t repeat yourself), which has seen a heavy reliance on component-based architecture, where you extract recurring snippets of code into a component. One of the founding principles of Tailwind is that you can extract reusable utility classes into a CSS component (large CSS classes). While creating a new class out of a group of utility-classes is considered a Tachyons anti-pattern and more often than not you tend to repeat classes.

A button would be written like this in Tailwind:

<button class="m-10 bg-red-300 text-white px-4 py-2 text-xs shadow-lg "> Call Phone </button>
Enter fullscreen mode Exit fullscreen mode

button in tailwind

and like this in Tachyons:

<button class="ma4 bg-light-red white ph4 pv2 f6 shadow"> Message </button>
Enter fullscreen mode Exit fullscreen mode

button in tachyonsWhen there are multiple buttons that have this same combination of utility-classes, the recommended approach with Tailwind is to create an abstraction through the @apply directive, which is used for extracting components classes in your CSS file.

.red-btn{
  @apply m-10 bg-red-300 text-white px-4 py-2 text-xs shadow-lg
}
Enter fullscreen mode Exit fullscreen mode

Then the red-btn class can now be applied to the buttons:

<button class-"red-btn"> Message </button>
Enter fullscreen mode Exit fullscreen mode

With Tachyons, you have to do a rewrite of the utility classes on every button.

Tailwind also uses a very human approach to class naming which is more explicit and much easier to comprehend while Tachyons uses incredibly abbreviated and very short classes although, it has a verbose edition for people who prefer using verbose class names:


This makes Tailwind more than a set of pre-baked utility classes, it’s a framework for creating your preferred style of writing functional CSS.

Conclusion

In this article, we’ve taken a look at some of the features that stand out among both Tailwind and Tachyons, we’ve seen that although Tachyons has a smaller file size, it trades size for customizability as Tailwind is more customizable and even comes with better default fonts and color scale.

Both frameworks are almost similar with only a few fundamental differences which are largely ideological such as customization options, approach to creating components, and naming.

If the results of the State of CSS 2019 survey are anything to go by, we can see Tailwind has a better satisfaction rate and pretty nice stats for a framework that is still in version 1.

Tailwind takes the cake in this comparison as it provides a better developer experience, gives customization options, and has more resources. It even does well to onboard people new to the utility-first/atomic CSS architecture. It should be the go-to choice for building robust design systems and even rapid prototyping of any kind.

Take a look at this collection of materials by John Polacek to learn a lot more atomic/functional CSS. This repository by Do What You Love also provides a fantastic tutorial to learn Tachyons. Tailwind’s documentation and screencasts are quite enough to get you started.

Which one do you prefer and why? Let me know what your thoughts are in the comments section or if there are any other comparisons you want me to write about.


Is your frontend hogging your users' CPU?

As web frontends get increasingly complex, resource-greedy features demand more and more from the browser. If you’re interested in monitoring and tracking client-side CPU usage, memory usage, and more for all of your users in production, try LogRocket.

Alt Text

LogRocket is like a DVR for web apps, recording everything that happens in your web app or site. Instead of guessing why problems happen, you can aggregate and report on key frontend performance metrics, replay user sessions along with application state, log network requests, and automatically surface all errors.

Modernize how you debug web apps — Start monitoring for free.


The post TailwindCSS vs Tachyons appeared first on LogRocket Blog.

Top comments (3)

Collapse
 
leob profile image
leob • Edited

So what's the takeaway?

Tailwind seems to have the edge (features, community) but does come at a cost (bundle size). But I understood (from other articles) that there are tools that can be used to heavily optimize this - point is that one would normally not use the vast majority of Tailwind's classes, so these can effectively be "stripped away".

In other words, Tachyons is smaller simply because it offers less.

Collapse
 
sg1asgard profile image
George C. Antohi

We already have Bootstrap 4, and I do not say this lightly, but anything else is utterly bullshit!

Collapse
 
itsjzt profile image
Saurabh Sharma

Bootstrap is set of ui components, tailwind is just a bunch of css styling classes. Why are you comparing those two?