Docsity

Tailwind CSS Cheat Sheet, Cheat Sheet of Programming Languages

Toggle sidebar
bg1
Tailwind CSS Cheat Sheet
Quick reference for Tailwind CSS utility classes (v3 and v4). Utilities are composed
directly in your markup.
Setup
# v4 (Vite)
npm install tailwindcss @tailwindcss/vite
/* v4: main CSS file */
@import "tailwindcss";
/* v4: theme customization in CSS */
@theme {
--color-brand: #c9a227;
--font-display: "Inter", sans-serif;
}
// v3: tailwind.config.js
module.exports = {
content: ["./src/**/*.{js,ts,jsx,tsx,html}"],
theme: { extend: { colors: { brand: "#c9a227" } } },
plugins: [],
};
/* v3: main CSS file */
@tailwind base;
@tailwind components;
@tailwind utilities;
Spacing Scale
One unit = 0.25rem (4px). p-4 = 1rem (16px), p-8 = 2rem (32px).
Class
Effect
p-4
padding on all sides
Tailwind CSS Cheat Sheet
Page 1 of 7
pf3
pf4
pf5

Partial preview of the text

Download Tailwind CSS Cheat Sheet and more Cheat Sheet Programming Languages in PDF only on Docsity!

Tailwind CSS Cheat Sheet

Quick reference for Tailwind CSS utility classes (v3 and v4). Utilities are composed

directly in your markup.

Setup

v4 (Vite)

npm install tailwindcss @tailwindcss/vite

/* v4: main CSS file */ @import "tailwindcss";

/* v4: theme customization in CSS */ @theme { --color-brand: #c9a227; --font-display: "Inter", sans-serif; }

// v3: tailwind.config.js module.exports = { content: ["./src/*/.{js,ts,jsx,tsx,html}"], theme: { extend: { colors: { brand: "#c9a227" } } }, plugins: [], };

/* v3: main CSS file */ @tailwind base; @tailwind components; @tailwind utilities;

Spacing Scale

One unit = 0.25rem (4px). p-4 = 1rem (16px), p-8 = 2rem (32px).

Class Effect

p-4 padding on all sides

Sizing

Layout: Flexbox

Class Effect

px-4 / py-2 horizontal / vertical padding

pt-2 pr-2 pb-2 pl-2 individual sides

m-4 ,^ mx-auto ,^ -mt-2 margin, centering, negative margin

space-x-4 /^ space-y-4 gap between child elements

gap-4 gap in flex/grid

p-[13px] arbitrary value

Class Effect

justify-start / center / end / between / around / evenly

main axis

items-start / center / end / stretch / baseline

cross axis

self-center , self-end align a single item

Colors

Pattern: {property}-{color}-{shade} with shades 50, 100, 200 ... 900, 950.

Borders, Radius, Shadow & Rings

Responsive Design (mobile first)

Unprefixed utilities apply to all sizes; prefixes apply at that breakpoint and up.

Class Effect

tracking-tight / wide / widest letter spacing

truncate single-line ellipsis

line-clamp-3 clamp to 3 lines

font-sans serif mono font family

Prefix Min width

sm: 640px

md: 768px

State Variants

...

...

Dark Mode

By default it follows the OS setting. For a manual toggle: in v3 set darkMode: "class" in

the config; in v4 use @custom-variant dark (&:where(.dark, .dark *)); and add the

dark class to .

Transitions & Animation

Prefix Min width

lg: 1024px

xl: 1280px

2xl: 1536px

v3 vs v4 Quick Notes

v4 configures the theme in CSS ( @theme ) instead of tailwind.config.js.

v4 uses a single @import "tailwindcss"; instead of the three @tailwind directives.

Some utilities were renamed in v4 (for example bg-gradient-to-* became bg-

linear-to-* ,^ shadow-sm became^ shadow-xs ); check the upgrade guide when

migrating.

Common Pitfalls

Building class names dynamically ( bg-${color}-500 ): Tailwind can't detect them.

Use full class names.

Forgetting to include template paths in content (v3), so classes get purged.

Fighting mobile-first: write the base style first, then add md: and lg: overrides.

Overusing arbitrary values instead of extending the theme.