Lesson 1 / 128%

Lesson 1

Introduction

10 min

Understand what Tailwind CSS is and why the utility-first approach changes the way you style a page.

Definition

Tailwind CSS is a utility-first CSS framework: instead of writing CSS rules yourself in a separate file, you style your elements directly in your HTML by combining small utility classes , each one responsible for a single visual property. For example,text-center centers the text,flex enables Flexbox andp-4 adds padding. By putting them together, you build complex interfaces without ever leaving your markup.

A different approach from classic CSS

This approach is very different from "classic" CSS, where you would write a semantic class such as .product-card and then define its style in a separate CSS file. With Tailwind, the.product-card class no longer exists: you replace it with a combination of utility classes that you can read directly in the HTML.

The term utility-first literally means "utilities come first". You always start from utility classes to build your design, and you only create your own CSS class in the rare cases where it is truly necessary. This is the opposite of the usual approach, where you write custom CSS first and only use ready-made classes as a complement.

Example: a card in classic CSS vs Tailwind
<!-- Classic CSS -->
<div class="product-card">My product</div>

<style>
.product-card {
  padding: 1rem;
  border-radius: 0.75rem;
  background-color: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
</style>

<!-- With Tailwind CSS -->
<div class="p-4 rounded-xl bg-white shadow-sm">
  My product
</div>

In this example, each Tailwind class corresponds to exactly one CSS declaration: p-4 gives padding: 1rem,rounded-xl gives border-radius: 0.75rem,bg-white gives background-color: white andshadow-sm adds a subtle shadow. You get essentially the same result, but with no CSS file to maintain and no class name to invent.

Result

Preview of the card built with Tailwind CSS in the introduction lesson

How does it work in practice?

Tailwind provides a consistent vocabulary of classes that you learn progressively. Most of them follow a simple, easy-to-remember logic: a prefix that indicates the property, followed by a value taken from a predefined scale.

  • Spacing : p-4 (padding),m-2 (margin), gap-6 (gap). The number follows a scale where 4 corresponds to 1rem, or 16px.
  • Colors : bg-blue-500 (background),text-slate-900 (text), border-red-300(border). Each color comes in shades from 50 to950.
  • Typography : text-lg (size),font-bold (weight), leading-relaxed (line height).
  • Layout : flex, grid,items-center, justify-between to align and organize your elements.

You can then add a prefix in front of a class to change its behavior depending on the context: hover: on hover,focus: on focus, dark: in dark mode, ormd: from a medium-sized screen and up.

Example: a button with states and responsive styles
<button
  class="px-4 py-2 rounded-lg bg-blue-600 text-white
         hover:bg-blue-700 focus:ring-2 focus:ring-blue-300
         dark:bg-blue-500 md:px-6 md:text-lg"
>
  Send
</button>

This single button handles its normal appearance, its hover state, its focus state, dark mode and a larger version on medium screens, all without writing a single line of CSS or a media query.

Why do so many developers adopt Tailwind?

Tailwind has become established in a great many professional projects in recent years, for several concrete reasons:

  • Development speed : no more juggling between an HTML file and a CSS file, or inventing a class name for every element. You write the style right where you write the structure.
  • No dead CSS : Tailwind scans your code and generates only the classes that are actually used, which results in very light final CSS files, often under 10 KB once compressed.
  • Visual consistency : spacing, color and font-size values are predefined in a consistent scale, which avoids "roughly right" values (14px here, 15px there).
  • Built-in responsive design and states : handling mobile, hover, focus or dark mode is done with simple class prefixes, without writing a single media query by hand.
  • No CSS specificity conflicts : since everything is made of small, low-priority classes, you avoid the specificity wars typical of classic CSS (!important everywhere).
  • Easier maintenance : changing an element affects only that element. You no longer have to fear breaking another page by changing a shared CSS rule.

Common criticisms (and their answers)

At first glance, Tailwind often comes as a surprise: it is criticized for producing "cluttered" HTML with lots of classes. This is a legitimate criticism, but it deserves some nuance:

  • "It's just inline CSS in disguise" : no. Tailwind classes let you use states (hover:), breakpoints (md:) and a design scale, which is impossible with the style attribute.
  • "The HTML becomes unreadable" : in a real project, you rarely repeat the same block. You factor it into a component (Astro, React, Vue...) and the long list of classes appears only once.
  • "You have to learn all the classes" : in practice, you quickly remember the most common ones, and your editor's autocompletion along with the official documentation do the rest.

Is Tailwind just a styled "reset"?

No, this is a common misconception. Tailwind is not a library of ready-made components like Bootstrap: it does not provide a ready-made "blue button". It provides the basic building blocks (colors, spacing, typography, layout) that you assemble yourself to create yourdesign, unique to your project. This is precisely why two sites built with Tailwind rarely look alike, unlike two Bootstrap sites.

Tailwind does include a base layer called Preflight , which normalizes the browsers' default styles (heading margins, list bullets, etc.). But this is only a clean starting point: the core of Tailwind remains its utility classes.

When to use Tailwind (and when to avoid it)?

Tailwind is a great fit for the majority of modern web projects: showcase sites, applications, dashboards, blogs, online stores. It is particularly at ease with component-based approaches, because the style stays attached to the component that uses it.

It is, however, less relevant when you have to style content you do not control (for example HTML generated by a rich-text editor), or when a team already enforces a design system based on classic CSS. In the first case, the official @tailwindcss/typography plugin and itsprose class (used on this page) let you format plain text without adding classes to every tag.

Above all, remember this: Tailwind does not replace CSS, it simplifies it. Understanding the basics (box model, Flexbox, Grid, positioning) remains essential, because every Tailwind class is just a faster way of writing a CSS property you already know.

What you will learn in this course

This course takes you step by step from installing Tailwind to building complete responsive interfaces: utility classes, colors and typography, spacing, Flexbox and Grid with Tailwind, responsive design, pseudo-classes (hover, focus, dark mode), theme customization, and finally best practices for keeping your code clean and maintainable on a real project.

To follow along comfortably, it is recommended that you know the basics of HTML and CSS (tags, selectors, notions of margins and colors). You do not need to master JavaScript: Tailwind is used simply by adding classes to your elements.

In the next lesson, you will install Tailwind in a project and write your first classes. Don't worry if the list of classes seems long for now: everything becomes natural with a bit of practice, and you will quickly recognize the patterns that keep coming back.

Before you continue

Open an existing project (or a simple HTML file) and find, in your current CSS, three very short rules (one or two properties). Try to imagine what their equivalent in utility classes would look like. For example, a rule{ margin-top: 1rem; } would probably become themt-4 class.