Vibe coding with Claude Code course ยท Module 2: A Next.js project with Claude Code
Tailwind CSS: read the classes Claude writes
In this lesson9
The project stands but the page still looks like a Next.js template. Time for the first section of Kraken's Call. Claude Code will write it, in Tailwind CSS, and you will learn to read what it wrote.
Problem: a button with nine classes
Claude will hand you a button with a long string of classes. If you do not read them, you do not know whether the button is legible on a phone, whether the text stands out from the background, and whether the agent used syntax from two years ago. You do not have to remember hundreds of classes: it is enough that you recognise a few families, and you check the rest in the cheat sheet below or on tailwindcss.com.
Tailwind in one paragraph
Tailwind CSS is a utility-first CSS framework: instead of writing your own CSS rules, you compose the look from small ready-made classes, each of which does one thing. The wizard from the previous lesson installed it right away. This is what a red button looks like in plain CSS:
.button {
background-color: #dc2626;
color: white;
padding: 12px 24px;
border-radius: 8px;
}The rule sits in a separate CSS file, and in the HTML only the name button stays, so to know what the button looks like, you open two files. A similar button in Tailwind fits in one line:
<button class="bg-red-600 text-white px-6 py-3 rounded-lg">Join the crew!</button>Each class is one sail: bg-red-600 gives a red background, text-white white text, px-6 and py-3 inner spacing, and rounded-lg rounded corners. In plain HTML the attribute is called class, and in the .tsx files of a Next.js project it is className, because class is a reserved word in JavaScript. The classes themselves are identical.
Request for Claude Code
Start the server from the previous lesson (npm run dev in a second terminal) and give this request in the session in the krakens-call folder:
Request for Claude Code:
Replace the contents of @app/page.tsx with a hero section for Kraken's
Call: a black background across the full screen height, the content
centered vertically and horizontally, a red heading "Kraken's Call", one
sentence describing the game and a gold button "Join the crew" that gets
darker on hover. Tailwind classes only, no new CSS files and no new
packages. At the end run npm run build and npm run lint and show the
result.The request describes the look in words, not in classes: Claude picks the classes, and you check them. The constraint "Tailwind classes only" guards against a separate CSS file appearing, and the two checks at the end give proof that the code builds and passes the linter.
What Claude wrote
Open app/page.tsx in Cursor and read from the top, piece by piece. First the container, that is the <main> element that wraps the whole section:
<main className="flex min-h-screen items-center justify-center bg-black px-6">flex turns on flexbox, a layout in which the children of an element line up in a row. items-center centers them vertically, and justify-center horizontally. min-h-screen gives a height of at least the whole screen, without it the vertical centering would not be visible. bg-black is the black background, and px-6 leaves a gap from the edge of the phone. None of these classes changes the text color: that is done by the classes on the heading and the description.
Inside there is a <div> with the classes max-w-xl text-center, which limits the width of the content and centers the text. In it, the heading and the description:
<h1 className="text-4xl font-bold text-red-600 md:text-6xl">
Kraken's Call
</h1>
<p className="mt-4 text-lg text-gray-300">
A pirate browser game: gather a crew and face the kraken.
</p>text-4xl is the size of the title, and md:text-6xl enlarges it on wider screens, more about that in a moment. font-bold makes it bold, text-red-600 colors it red, mt-4 adds 16 pixels of space above the description, and text-gray-300 gives light gray text on the black background. ' is an apostrophe written in JSX: on the page it looks like a plain ' character, but the linter will not report it.
At the end the button, the longest string in the file:
<button className="mt-8 rounded-lg bg-yellow-500 px-6 py-3 font-semibold text-black transition-colors hover:bg-yellow-600">
Join the crew
</button>mt-8 moves the button 32 pixels away from the description, px-6 and py-3 give 24 pixels of spacing at the sides and 12 at the top and bottom, rounded-lg rounds the corners, font-semibold makes the label bold, and text-black on bg-yellow-500 gives black text on a gold background. hover:bg-yellow-600 changes the background to a darker one when the cursor hovers over it, and transition-colors does it smoothly. The button does nothing yet: it will get its action later.
Cheat sheet for reading classes
Tailwind classes fall into families. When you come across an unknown one in Claude's code, find its family:
- Colors:
bg-is the background,text-the text,border-the border, for examplebg-red-600,text-white,bg-black. Shades are numbered from 50 (lightest) to 950 (darkest), sohover:bg-red-700next tobg-red-600means a darker background on hover. - Spacing:
p-is padding, the inner space, andm-is margin, the outer space. The unit is 4 pixels:p-1is 4px,p-28px,p-416px,p-832px. The letter afterpormchooses the sides:pxleft and right,pytop and bottom,pttop,prright,mt-8a top margin of 32px.mx-autosets automatic side margins and centers a block of limited width. - Text: the sizes from the smallest are
text-xs,text-sm,text-base(16px),text-lg,text-xl, thentext-2xland bigger. Weight from the thinnest:font-light,font-normal,font-medium,font-semibold,font-bold. Alignment:text-left,text-center,text-right. - Layout:
block,inline,flexandgridchoose how an element is displayed, andhiddenhides it (display: none). In flexboxflex-rowis the horizontal direction (the default),flex-colthe vertical one, andgap-4gives 16 pixels of space between children. - Dimensions:
w-fullis a width of 100%,w-1/2a half,max-w-mda maximum width of 448px.h-screenis a height of exactly the whole screen (100vh), andmin-h-screenat least the whole screen. - Borders and corners:
borderis a 1px border,border-22px,border-red-500its color.roundedrounds by 4px (in Tailwind 4 the same value also has the namerounded-sm),rounded-lgmore strongly, androunded-fullto the maximum: a button becomes a pill and a square becomes a circle.
Do not learn this list by heart. Read Claude's code with it at hand, and after a few sections the families will start to recognise themselves.
Responsiveness: phone first
Tailwind is designed from the smallest screen up, that is mobile first. A class without a prefix always works, and a class with a breakpoint prefix works only from the given screen width upwards:
sm:from 640px;md:from 768px, for example a tablet held upright;lg:from 1024px, a small laptop;xl:from 1280px, a monitor;2xl:from 1536px, a large monitor.
In the heading Claude wrote text-4xl md:text-6xl: on a phone the title has size 4xl, and from 768px upwards 6xl. You will see the same pattern in card layouts:
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">On a phone the cards stand in one column, from 768px in two, and from 1024px in three. Change the width of the preview in the editor below and watch how the number of columns and the size of the text change:
Code for this lesson: index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tailwind Responsiveness</title>
<!-- Tailwind CSS 4 from the CDN: a version for learning, not for production -->
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
</head>
<body class="bg-gray-100 p-8">
<h1 class="text-3xl font-bold mb-8 text-center">
Responsiveness in Tailwind
</h1>
<!-- Mobile: 1 column, Tablet: 2 columns, Desktop: 3 columns -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<div class="bg-blue-500 text-white p-6 rounded-lg">
<h2 class="text-xl font-bold mb-2">Card 1</h2>
<p>Resize the window to see responsiveness!</p>
</div>
<div class="bg-purple-500 text-white p-6 rounded-lg">
<h2 class="text-xl font-bold mb-2">Card 2</h2>
<p>Mobile: 1 column<br>Tablet (md): 2 columns<br>Desktop (lg): 3 columns</p>
</div>
<div class="bg-pink-500 text-white p-6 rounded-lg">
<h2 class="text-xl font-bold mb-2">Card 3</h2>
<p>Breakpoints:<br>sm: 640px<br>md: 768px<br>lg: 1024px</p>
</div>
</div>
<!-- Responsive text -->
<div class="mt-8 bg-white p-6 rounded-lg shadow">
<p class="text-sm md:text-base lg:text-lg xl:text-xl">
This text has different sizes:<br>
Mobile: text-sm (14px)<br>
Tablet: text-base (16px)<br>
Laptop: text-lg (18px)<br>
Desktop: text-xl (20px)
</p>
</div>
</body>
</html>The last prefix you will meet in Claude's code is dark:. A class with it works only when the user's system has dark mode turned on:
<div class="bg-white text-black dark:bg-gray-900 dark:text-white">Treasure map</div>In light mode the div has a white background and black text, and in dark mode a dark gray background and white text. By default Tailwind checks this through the system setting (prefers-color-scheme), and the starter page from the wizard uses this prefix in many places, for example dark:bg-black.
Where Tailwind lives in the project
Tailwind in a new project works from the first minute: the wizard with the --tailwind flag configured everything and you do not have to install anything. In Tailwind 4 the configuration lives in CSS. The first line of the app/globals.css file is:
@import "tailwindcss";This single line loads the whole of Tailwind. Lower in this file there is a @theme inline block, in which the project sets its own colors and fonts. Tailwind is hooked into the build by the Turbopack rule in next.config.ts, which you read in the previous lesson.
The project has no tailwind.config.js file and no postcss.config.mjs. The directives @tailwind base, @tailwind components and @tailwind utilities and the tailwind.config.js file are version 3 syntax, and Tailwind 4 no longer detects such a file by itself. If Claude proposes any of them, it is writing from memory of the old version.
Captain's review
Before you approve a change, check in the diff and in the browser:
- Version 4 syntax. The code has no classes removed in Tailwind 4, such as
bg-opacity-50(todaybg-black/50),flex-grow-*(todaygrow-*) oroverflow-ellipsis(todaytext-ellipsis), and no newtailwind.config.jsfile. - A narrow screen. Narrow the browser window to the width of a phone: the heading must fit, and the text must not touch the edge.
- Legibility. The text stands out clearly from the background: the light gray description on black and the black label on the gold button read without effort.
- Hover is an extra. In Tailwind 4
hover:works only on devices that have a cursor, so on a phone the button will not darken. No important information may appear only on hover.
A typical agent mistake: it mixes Tailwind 3 and 4 syntax, or despite the ban adds its own CSS file. Another one, common in JSX: a bare apostrophe in "Kraken's Call". npm run build lets it through, but npm run lint reports the react/no-unescaped-entities error. That is why the request had both checks.
Next step
One fix per request. Ask for example: "In @app/page.tsx increase the space between the description and the button, nothing else". In the diff one class should change, mt-8 to a bigger one, for example mt-12. When the diff suits you, ask for a commit. In the editor below the same section waits in plain HTML: change the classes and watch what each sail does.
Remember: a Tailwind class is an order for a single sail; read them one by one and you will see the whole ship.
Code for this lesson: index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kraken's Call - hero section</title>
<!-- Tailwind CSS 4 from the CDN: a version for learning, not for production -->
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
</head>
<body>
<!-- The same section Claude wrote in app/page.tsx. In HTML we write class instead of className -->
<main class="flex min-h-screen items-center justify-center bg-black px-6">
<div class="max-w-xl text-center">
<h1 class="text-4xl font-bold text-red-600 md:text-6xl">
Kraken's Call
</h1>
<p class="mt-4 text-lg text-gray-300">
A pirate browser game: gather a crew and face the kraken.
</p>
<button class="mt-8 rounded-lg bg-yellow-500 px-6 py-3 font-semibold text-black transition-colors hover:bg-yellow-600">
Join the crew
</button>
<!-- Try it: change mt-8 to mt-12, bg-yellow-500 to bg-red-600, and hover:bg-yellow-600 to hover:bg-red-700 -->
</div>
</main>
</body>
</html>Spotted a mistake in this lesson?
Check yourself
Answer the questions from this lesson. Pick an answer to see right away whether it is correct.
1. What is Tailwind CSS?
2. Which Tailwind class sets a red background?
3. Which Tailwind prefix applies a style from a screen width of 768px up?
4. Which Tailwind class horizontally centers items inside a flexbox?
5. What does the hover:bg-red-700 class do in Tailwind?
6. Which Tailwind class sets the element's width to 100%?
7. What do you need to do to use Tailwind in Next.js if you chose Tailwind CSS (or the recommended defaults) when creating the project?
8. What does the dark: prefix do in a Tailwind class (e.g. dark:bg-gray-900)?
9. Which Tailwind class sets the height to the full screen (100vh)?
10. Which Tailwind class centers a block using automatic left and right margins?
11. Which Tailwind class hides an element (display: none)?
Hands-on tasks in the game
- Code editor
Create a div with a black background (bg-black), white text (text-white) and 16px padding (p-4). Put any text inside it.
- Click in order
Build the Tailwind class that sets white text color:
- Vertical ordering
Arrange the Tailwind padding classes from smallest to largest:
- Code editor
Create a div with the classes flex, items-center, justify-center and h-screen, and put an element with text inside it, e.g. <p>. The element should sit in the middle of the screen, vertically and horizontally.
- Vertical ordering
Arrange the Tailwind breakpoints from the smallest screen to the largest:
- Horizontal ordering
Arrange the code of a red Tailwind button (left to right):
- Code editor
Build a pirate <button>: red background (e.g. bg-red-600), white text (text-white), padding (e.g. px-6 py-3), rounded corners (e.g. rounded-lg) and a darker background on mouse hover (e.g. hover:bg-red-700).
- Click in order
Build the Tailwind class that rounds corners with a larger radius:
- Horizontal ordering
Arrange the parts of the Tailwind class for a red background (left to right):
- Vertical ordering
Arrange the Tailwind font-weight classes from thinnest to boldest:
- Vertical ordering
Arrange the Tailwind text-size classes from smallest to largest:
- Vertical ordering
Arrange the classes needed to center an element vertically and horizontally with Tailwind:
- Horizontal ordering
Arrange the parts of the Tailwind class for a 32px top margin (left to right):
- Vertical ordering
Arrange the steps of changing the look of the page with Claude Code:
- Click in order
Build the Tailwind class for extra large text:
- Click in order
Build the Tailwind class that sets the vertical flexbox direction:
Tasks after this lesson
- QuestionQuiz: Tailwind CSS
- QuestionQuiz: Tailwind colors
- Coding taskPractice: Tailwind padding
- QuestionQuiz: Tailwind responsiveness
- Click in orderOrdering: White text class
- Put in orderOrdering: Tailwind padding scale
- Coding taskPractice: Tailwind flexbox
- QuestionQuiz: Tailwind flexbox
- Put in orderOrdering: Tailwind responsive classes
- Put in orderOrdering: Building a Tailwind button
- Coding taskPractice: Pirate button
- QuestionQuiz: Tailwind hover
- Click in orderOrdering: Rounded corners class
- QuestionQuiz: Tailwind width
- Put in orderOrdering: Red background class
- Put in orderOrdering: Tailwind font weight
- Put in orderOrdering: Tailwind text sizes
- QuestionQuiz: Next.js + Tailwind
- Put in orderOrdering: Flexbox centering classes
- QuestionQuiz: Tailwind dark mode
- Put in orderOrdering: Tailwind margin class
- QuestionQuiz: Tailwind screen height
- Put in orderOrdering: Styling from Claude Code
- QuestionQuiz: Tailwind margin centering
- Click in orderOrdering: Full text-size class
- QuestionQuiz: Tailwind display classes
- Click in orderOrdering: Vertical flexbox direction