Development

5 min read

Learning UX Design with Tailwind

Broadleaf

Written by Broadleaf

Published on Oct 14, 2019

Tailwind CSS

I have been developing software to help eCommerce companies support their customers for years now, and one of the areas I have consistently failed to grow in is UX design. I have always been envious of those who have a natural ability for it and can quickly hack out a nice-looking user interface like it was nothing. That’s changed recently, as I work more and more on the frontend, and so I decided to start taking learning this skill set more seriously.

In comes Tailwind CSS to the rescue, a utility-first CSS framework that has made me rethink the way I look at design and helped me to learn the basics. As a developer and system-oriented person, it gives me a methodology that allows me to create my own custom interfaces. Since I lack the natural intuition towards design, having a consistent design system helps ease the anxiety that comes with design while slowly growing the muscles needed to do so effectively.

What is Tailwind?

Tailwind CSS is a utility-first CSS framework for rapidly building custom designs:

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.
— TailwindCSS

This framework provides you with low-level utility classes that let you build completely custom designs quickly. It is not focused on verbose out-of-box components, but rather a methodology that allows you to build custom, "bespoke" components yourself, quickly.

Why is it different that other frameworks?

Tailwind CSS stands out to me from other CSS frameworks because it seems to be focused on being a design system rather than providing a set of pre-defined out-of-box components. From my experience using other frameworks such as Bootstrap, I usually start with these out-of-box components, but then I shortly after need to customize them. This customization usually ends up being inconsistent, hack-y, and counter-productive. Rather than trying to fight with opinionated out-of-box components, Tailwind gives me the confidence to design my own custom components without getting in my way.

My overall favorite part about Tailwind CSS is that it helps me learn to make design decisions more quickly and consistently than before. Much of this boils down to the Utility First Philosophy, which limits your choices, so rather choosing between a padding-right between 1px and 200px, I choose between a few different fixed increments of padding. While this definitely makes my design far more consistent, it also helps me to make decisions more quickly, because I have to choose between a handful options, not 200 pixels worth of them. As I make more and more decisions using this philosophy, I find the decisions coming more quickly, and I feel more confident when making them.

Tailwind CSS differs from other frameworks because it doesn’t strive to provide the most amazing set of out-of-box components, but instead focuses on you, the developer, and how you can be the person that creates those awesome designs.

How can I start using Tailwind myself?

Tailwind CSS is pretty easy to get started with as they describe within their installation documentation. Depending on your frontend environment, you might need to do more or less than what is within the documentation. Personally, I use React often and so I find Create React App to be a good starting point.

Setting Up Create React App

If you want to get started with Create React App, then I will help get you started with that. First things first, be sure you have NodeJS and NPM (or Yarn) installed on your system, then run the following to set up your application:

# Using NPM
npx create-react-app tailwind-react
# Using Yarn
yarn create react-app tailwind-react
view raw setup.sh hosted with ❤ by GitHub

Setting Up Tailwind CSS

Next, we need to move into the tailwind-react directory and install the tailwindcss dependency:

# Using NPM
npm install tailwindcss --save-dev
# Using Yarn
yarn add tailwindcss --dev
view raw setup.sh hosted with ❤ by GitHub

Now that tailwind is installed, initialize the tailwind.config.js file under ./src/styles, which is where you will manage the theme, plugins, or other customizations to Tailwind:

# make the styles folder
mkdir ./src/styles
# Using NPM
npx tailwind init ./src/styles/tailwind.config.js
# Using Yarn
yarn tailwind init ./src/styles/tailwind.config.js
view raw setup.sh hosted with ❤ by GitHub

Setting Up PostCSS

At this point we need to set up PostCSS, and so we need to add a couple more dependencies:

# Using NPM
npm install postcss-cli autoprefixer --save-dev
# Using Yarn
yarn add postcss-cli autoprefixer --dev
view raw setup.sh hosted with ❤ by GitHub

Note
PostCSS is a tool for transforming css using JS plugins. tailwindcss is a plugin for PostCSS. autoprefixer is another plugin used to add or remove browser-specific vendor prefixes.

Now that we have those dependencies, we can set-up our postcss.config.js file at the root of our project:

touch postcss.config.js
view raw setup.sh hosted with ❤ by GitHub

And fill it with this content:

module.exports = {
plugins: [
require('tailwindcss')('./src/styles/tailwind.config.js'),
require('autoprefixer')
]
};

Creating the Tailwind CSS File

Now that we have PostCSS setup, we need to create the index.css file under src/styles with the following content:

@tailwind base;
@tailwind components;
@tailwind utilities;
view raw tailwind.css hosted with ❤ by GitHub

Running PostCSS

Now we can update your scripts within package.json with a script to run the PostCSS tool and updating the other scripts to run this command before startup. The following will result in a file outputted at ./src/tailwind.css (be sure to add to .gitignore):

{
"scripts": {
"build:tailwind": "postcss src/styles/index.css -o ./src/tailwind.css",
"prebuild": "yarn build:tailwind",
"prestart": "yarn build:tailwind",
"build": "react-scripts build",
"start": "react-scripts start"
}
}
view raw postcss.json hosted with ❤ by GitHub

Note
Be sure to change commands for prebuild/prestart if using NPM!

You can now run this command and see the tailwind.css file created:

# Using NPM
npm run build:tailwind
# Using Yarn
yarn build:tailwind
view raw setup.sh hosted with ❤ by GitHub

Adding CSS to the Application

We can finally add the CSS to the application by adding this line to src/index.js:

import './tailwind.css';
view raw css.js hosted with ❤ by GitHub

Replacing App with Tailwind Markup

Before starting up, let’s replace the content with App.js with something using tailwind styles (example from TailwindCSS documentation):

<div class="md:flex">
<div class="md:flex-shrink-0">
<img class="rounded-lg md:w-56" src="https://images.unsplash.com/photo-1556740738-b6a63e27c4df?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=448&q=80" alt="Woman paying for a purchase">
</div>
<div class="mt-4 md:mt-0 md:ml-6">
<div class="uppercase tracking-wide text-sm text-indigo-600 font-bold">Marketing</div>
<a href="#" class="block mt-1 text-lg leading-tight font-semibold text-gray-900 hover:underline">Finding customers for your new business</a>
<p class="mt-2 text-gray-600">Getting a new business off the ground is a lot of hard work. Here are five ideas you can use to find your first customers.</p>
</div>
</div>
view raw tailwind.html hosted with ❤ by GitHub

Starting Up

Finally, you can start up your application and see the results at https://localhost:3000:

# Using NPM
npm start
# Using Yarn
yarn start
view raw startup.sh hosted with ❤ by GitHub

Closing Thoughts

Tailwind CSS is a pretty impressive CSS framework that adds a ton of value for those looking to learn how to create beautiful, bespoke designs. I hope this blog gives a good introduction to TailwindCSS and makes you more excited to learn and grow as a designer!

Related Resources