Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 37 ยท Getting Started

Your First Tailwind Page

Build a profile card and a small landing page with Tailwind CSS utilities, reading each class so you learn how spacing, color, type and layout fit together.

Time to build something. In this lesson you will style a profile card, then assemble a small landing page, adding utilities one group at a time. The goal is not to memorize class names but to learn how to read a Tailwind class list, because that skill carries into everything else.

Each example loads the browser build from Installing Tailwind CSS. Edit the classes freely: nothing you do here can break anything.

Start with unstyled HTML

Without Tailwind, a card is plain, stacked content. Tailwind also resets the browser defaults (a stylesheet called Preflight), so headings and paragraphs look unstyled: no bold, no margins, no bullets. This is deliberate. You decide every style explicitly.

Unstyled starting point

Notice that the h1 is the same size as the paragraph. Now we will add styling in layers.

Layer 1: the container

We want a white card on a light gray page, with rounded corners and a shadow. Wrap the markup in a page element and a card:

HTML
<div class="bg-slate-100 p-8">
  <div class="mx-auto max-w-sm rounded-2xl bg-white p-6 shadow-lg">
    ...
  </div>
</div>

Read the card's classes left to right:

  • mx-auto sets left and right margins to auto, centering a block with a width.
  • max-w-sm caps the width at 24rem (384px).
  • rounded-2xl rounds the corners generously.
  • bg-white is the background color.
  • p-6 is padding of 1.5rem on all sides.
  • shadow-lg adds a large drop shadow.

Layer 2: typography and color

Now the text. Preflight removed the heading style, so we add size and weight, and soften the secondary text with a lighter gray:

HTML
<h1 class="text-2xl font-bold text-slate-900">Mira Okafor</h1>
<p class="text-slate-500">Frontend developer</p>

text-2xl sets the font size (1.5rem) and a matching line height. font-bold is weight 700. Both text-2xl and text-slate-900 start with text-, but one is size and the other color. Tailwind tells them apart by the value.

Layer 3: the button

A link that looks like a button needs a background, padding, radius and a hover state:

HTML
<a href="#" class="mt-4 inline-block rounded-full bg-indigo-600 px-5 py-2
                   text-sm font-semibold text-white hover:bg-indigo-700">
  Follow
</a>

px-5 is horizontal padding, py-2 vertical. inline-block lets the link accept vertical padding and margin. hover:bg-indigo-700 darkens it on hover.

Put all three layers together:

The finished profile card

Try this: change max-w-sm to max-w-md, make the button rounded-md, or swap indigo for rose. Every change is local to that one element.

A small landing page

Now a bigger page: a header with a flex row, a hero section and three feature cards in a grid. You have not studied flexbox or grid yet (chapter 3 does), so read the comments for what each new class does.

A tiny landing page

How to read a class list

When you meet a long class list, scan it in this order and the pieces fall into place:

  1. Layout: flex, grid, block, hidden, relative.
  2. Sizing and spacing: w-*, max-w-*, p-*, m-*, gap-*.
  3. Typography: text-*, font-*, leading-*, tracking-*.
  4. Decoration: bg-*, border-*, rounded-*, shadow-*, ring-*.
  5. State and responsive variants: anything with a colon, like hover: or sm:.

Many people (and the Prettier plugin) order the classes the same way, so lists are easy to scan.

flowchart LR
  A["Write HTML"] --> B["Add classes<br/>for the look"]
  B --> C["Look at the result"]
  C --> D{"Happy?"}
  D -->|no| B
  D -->|yes| E["Move on"]

The Tailwind loop: edit classes, look, repeat. No stylesheet to switch to.

Common mistakes

  • Expecting browser defaults. After Preflight, h1 is not big, ul has no bullets and images are display: block. Add what you need.
  • Giving a width to an inline element. a and span ignore width and vertical margin. Use inline-block or block first.
  • Forgetting mx-auto needs a width. Centering with mx-auto only works if the element has a max-w-* or w-*.

You will study each of these groups in detail next, starting with the utility-first workflow and then spacing and sizing in chapter 2.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does mx-auto max-w-sm do to a block element?

    max-w-sm caps the width, and mx-auto turns the left and right margins into auto, which centers the block.
  2. 2. Why do headings look unstyled in a Tailwind project?

    Preflight removes default margins, sizes and weights so you control every style explicitly.
  3. 3. Which class makes an inline link accept vertical padding properly?

    Inline elements ignore vertical box-model spacing; inline-block or block makes padding and margin behave.
  4. 4. In px-5 py-2, what do px and py control?

    px is padding on the x axis (left and right), py on the y axis (top and bottom).

Summary

  • Build in layers: container, typography and color, then interactive details.
  • Read class lists in groups: layout, spacing, type, decoration, then variants.
  • Preflight removes browser defaults, so headings, lists and links need explicit styling.
  • mx-auto plus a max width centers a block; inline-block lets inline links take padding.

Next: The Utility-First Workflow