DEV Community

Cover image for Getting Started with Tailwind CSS
Neha Th
Neha Th

Posted on

Getting Started with Tailwind CSS

When it comes to styling web projects, you’ve probably heard of CSS frameworks like Bootstrap. They offer prebuilt components, but if you’ve ever found yourself struggling with overriding their styles or wanted more control, Tailwind CSS might be just what you're looking for.

Unlike traditional CSS frameworks, Tailwind doesn’t give you ready-made components. Instead, it provides utility classes that allow you to build custom designs quickly without writing a single line of CSS. Think of it as a toolkit full of small, reusable styles, like p-4 for padding, bg-blue-500 for background color, and so on. Let’s dive in!

Why Choose Tailwind?

Before we jump into the setup, let’s discuss why you should consider using Tailwind CSS:

  1. Flexibility: It doesn’t impose any specific design or style. You get total control over how your design looks.
  2. Speed: Once you get the hang of it, you’ll style your website faster than ever.
  3. No More Context Switching: You stay in your HTML, applying classes directly instead of jumping between HTML and CSS files. Now that you know why it’s awesome, let’s set it up!

Setting Up Tailwind CSS

There are two primary ways to get started with Tailwind CSS: a simple CDN for quick use or a more advanced setup using npm for larger projects.

Option 1: Using a CDN (Quick Setup)
If you’re in a hurry or working on a small project, this is the fastest way to get Tailwind up and running.

Just add the following <link> tag in your HTML file’s <head>:

<link href="https://cdn.jsdelivr.net/npm/tailwindcss@latest/dist/tailwind.min.css" rel="stylesheet">
Enter fullscreen mode Exit fullscreen mode

Yes! Tailwind is now ready to use. You can start adding classes like p-4, text-center,bg-blue-500 to your HTML elements right away.

Option 2: Using Tailwind with npm (For Full Projects)
If you’re working on a bigger project or want more customization options, you should install Tailwind via npm.

  1. Install Tailwind: Open your terminal and run:
npm install tailwindcss
Enter fullscreen mode Exit fullscreen mode
  1. Initialize Tailwind: To create a configuration file for customizing Tailwind, run:
npx tailwindcss init
Enter fullscreen mode Exit fullscreen mode

This will generate a tailwind.config.js file where you can tweak default settings like colors, fonts, and more.

  1. Set up your build process: You’ll need a tool like PostCSS to process Tailwind’s CSS. In your postcss.config.js file, include:
module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  }
}
Enter fullscreen mode Exit fullscreen mode

Now Tailwind is fully installed, and you’re ready to start using its utilities.

Tailwind CSS is a powerful tool that offers flexibility and speed in your workflow. Once you get comfortable with its utility-first approach, you’ll find yourself building custom designs faster than ever before, all without leaving your HTML file.

Whether you’re building simple websites or large-scale applications, Tailwind provides the utility classes and customizability you need to make your project stand out.

Don't forget to check out the official Tailwind CSS documentation and start experimenting with all the possibilities!

For any further queries, feel free to mail me at neha.k.thakor@gmail.com.

Top comments (0)