CodeBerry logo
CodeBerry Pie
frontend

Tailwind CSS : A Comprehensive Get Starter Guide

Tailwind CSS : A Comprehensive Get Starter Guide
0 views
2 min read
#frontend

Tailwind CSS is a utility-first CSS framework that lets you build custom designs without writing a single line of traditional CSS. It’s fast, flexible, and ideal for developers who want to stay in their HTML without bouncing between files.

Whether you're new to Tailwind or looking to level up, this guide has you covered — from setup to layout, components, and pro tips.


Why Tailwind CSS?

  • Utility-first: Compose your UI with atomic class names
  • No context switching: Stay in your markup — no jumping to CSS files
  • Customizable: Fully extendable with tailwind.config.js
  • Responsive-first: Built-in support for breakpoints and variants

1. Setting Up Tailwind CSS

Using CDN (for quick prototyping)

<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
  <div class="text-2xl font-bold text-blue-600">Hello Tailwind!</div>
</body>
</html>

Install Tailwind via npm:

npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p

Update your tailwind.config.js:

module.exports = {
  content: ['./src/**/*.{html,js,jsx,ts,tsx}'],
  theme: {
    extend: {},
  },
  plugins: [],
}

Add the Tailwind directives to your CSS:

@tailwind base;
@tailwind components;
@tailwind utilities;

Run Tailwind CLI:

npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch

2. Basic Utility Classes

Typography

<h1 class="text-4xl font-bold">Hello World</h1>
<p class="text-gray-600">Tailwind makes styling easy.</p>

Layout

<div class="grid grid-cols-3 gap-4">
  <div class="bg-blue-100 p-4">1</div>
  <div class="bg-blue-200 p-4">2</div>
  <div class="bg-blue-300 p-4">3</div>
</div>

Buttons

<button class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">
  Click Me
</button>

3. Responsive Design with Tailwind

<div class="text-sm md:text-lg lg:text-xl">
  Responsive text size
</div>

You can apply different styles per screen size using prefixes:

PrefixScreen size
sm:≥ 640px
md:≥ 768px
lg:≥ 1024px
xl:≥ 1280px
2xl:≥ 1536px

4. Dark Mode Support

Enable dark mode in your config:

// tailwind.config.js
module.exports = {
  darkMode: 'class',
  ...
}
<body class="dark">
  <div class="text-white bg-black dark:text-yellow-400">
    Dark mode text
  </div>
</body>

5. Extending Tailwind

Customize themes, add plugins, or extend utilities:

// tailwind.config.js
module.exports = {
  theme: {
    extend: {
      colors: {
        brand: '#ff3e00'
      }
    }
  }
}
<div class="bg-brand text-white p-4">Custom Color</div>

6. Useful Tailwind Plugins

  • @tailwindcss/forms — Better default form styling
  • @tailwindcss/typography — For prose content
  • @tailwindcss/aspect-ratio — Responsive media embeds
npm install @tailwindcss/forms @tailwindcss/typography @tailwindcss/aspect-ratio

7. Tips for Pro Tailwind Devs

  • Use Tailwind Play to prototype fast
  • Combine Tailwind with component libraries like ShadCN, DaisyUI
  • Consider class composition tools (e.g. clsx, cva, tailwind-variants)
  • Use @apply for reusable style blocks in component files
  • Learn JIT mode — it's the default now, but worth understanding deeply

Final Thoughts

Tailwind is more than a CSS framework — it's a development philosophy. Once you get the hang of utility-first thinking, building UIs becomes faster, more consistent, and surprisingly enjoyable.

So go ahead — ditch your hundreds of lines of CSS and embrace the Tailwind breeze.