Tailwind CSS est un framework CSS utilitaire qui vous permet de construire des designs directement dans votre balisage. Au lieu d'ecrire du CSS personnalise, vous appliquez des classes utilitaires preconstruites. Ce memento complet Tailwind CSS couvre toutes les categories principales de classes avec leur sortie CSS.
Pourquoi Tailwind CSS et pourquoi un memento ?
Tailwind CSS possede des centaines de classes utilitaires. Bien que la convention de nommage soit intuitive, un memento rapide fait gagner du temps et ameliore la productivite.
Espacement : Padding et Margin
Tailwind utilise une echelle d'espacement coherente. Le nombre apres p- ou m- correspond a une valeur rem (multiplier par 0.25rem). Les marges negatives utilisent le prefixe -m-.
| Class | CSS Output | Value |
|---|
p-0 | padding: 0px | 0px |
p-1 | padding: 0.25rem | 4px |
p-2 | padding: 0.5rem | 8px |
p-3 | padding: 0.75rem | 12px |
p-4 | padding: 1rem | 16px |
p-5 | padding: 1.25rem | 20px |
p-6 | padding: 1.5rem | 24px |
p-8 | padding: 2rem | 32px |
p-10 | padding: 2.5rem | 40px |
p-12 | padding: 3rem | 48px |
p-16 | padding: 4rem | 64px |
p-20 | padding: 5rem | 80px |
p-24 | padding: 6rem | 96px |
p-32 | padding: 8rem | 128px |
p-40 | padding: 10rem | 160px |
p-48 | padding: 12rem | 192px |
p-64 | padding: 16rem | 256px |
p-96 | padding: 24rem | 384px |
Directional Padding & Margin
| Prefix | CSS Property | Description |
|---|
p-* | padding | All sides |
px-* | padding-left + padding-right | Horizontal |
py-* | padding-top + padding-bottom | Vertical |
pt-* | padding-top | Top |
pr-* | padding-right | Right |
pb-* | padding-bottom | Bottom |
pl-* | padding-left | Left |
m-* | margin | All sides |
mx-* | margin-left + margin-right | Horizontal |
my-* | margin-top + margin-bottom | Vertical |
-m-4 | margin: -1rem | Negative margin |
m-auto | margin: auto | Auto margin |
<!-- Spacing examples -->
<div class="p-4">padding 1rem all sides</div>
<div class="px-6 py-3">horizontal 1.5rem, vertical 0.75rem</div>
<div class="mt-8 mb-4">top margin 2rem, bottom margin 1rem</div>
<div class="mx-auto max-w-lg">centered container</div>
<div class="-mt-4">negative top margin (overlap)</div>
<div class="space-x-4">children spaced 1rem horizontally</div>
<div class="space-y-2">children spaced 0.5rem vertically</div>
Typographie
Utilitaires pour la taille de police, graisse, hauteur de ligne, espacement des lettres, alignement et couleur du texte.
Taille de police
| Class | CSS Output | Size |
|---|
text-xs | font-size: 0.75rem; line-height: 1rem | 12px |
text-sm | font-size: 0.875rem; line-height: 1.25rem | 14px |
text-base | font-size: 1rem; line-height: 1.5rem | 16px |
text-lg | font-size: 1.125rem; line-height: 1.75rem | 18px |
text-xl | font-size: 1.25rem; line-height: 1.75rem | 20px |
text-2xl | font-size: 1.5rem; line-height: 2rem | 24px |
text-3xl | font-size: 1.875rem; line-height: 2.25rem | 30px |
text-4xl | font-size: 2.25rem; line-height: 2.5rem | 36px |
text-5xl | font-size: 3rem; line-height: 1 | 48px |
text-6xl | font-size: 3.75rem; line-height: 1 | 60px |
text-7xl | font-size: 4.5rem; line-height: 1 | 72px |
text-8xl | font-size: 6rem; line-height: 1 | 96px |
text-9xl | font-size: 8rem; line-height: 1 | 128px |
Graisse de police
| Class | CSS Output |
|---|
font-thin | font-weight: 100 |
font-extralight | font-weight: 200 |
font-light | font-weight: 300 |
font-normal | font-weight: 400 |
font-medium | font-weight: 500 |
font-semibold | font-weight: 600 |
font-bold | font-weight: 700 |
font-extrabold | font-weight: 800 |
font-black | font-weight: 900 |
Hauteur de ligne
| Class | CSS Output |
|---|
leading-none | line-height: 1 |
leading-tight | line-height: 1.25 |
leading-snug | line-height: 1.375 |
leading-normal | line-height: 1.5 |
leading-relaxed | line-height: 1.625 |
leading-loose | line-height: 2 |
leading-3 | line-height: 0.75rem |
leading-6 | line-height: 1.5rem |
leading-8 | line-height: 2rem |
leading-10 | line-height: 2.5rem |
Espacement des lettres
| Class | CSS Output |
|---|
tracking-tighter | letter-spacing: -0.05em |
tracking-tight | letter-spacing: -0.025em |
tracking-normal | letter-spacing: 0em |
tracking-wide | letter-spacing: 0.025em |
tracking-wider | letter-spacing: 0.05em |
tracking-widest | letter-spacing: 0.1em |
Alignement du texte
| Class | CSS Output |
|---|
text-left | text-align: left |
text-center | text-align: center |
text-right | text-align: right |
text-justify | text-align: justify |
text-start | text-align: start |
text-end | text-align: end |
Couleur du texte
<!-- Text color examples -->
<p class="text-black">text-black → color: #000</p>
<p class="text-white">text-white → color: #fff</p>
<p class="text-gray-500">text-gray-500 → color: #6b7280</p>
<p class="text-red-600">text-red-600 → color: #dc2626</p>
<p class="text-blue-500">text-blue-500 → color: #3b82f6</p>
<p class="text-green-700">text-green-700 → color: #15803d</p>
<p class="text-transparent">text-transparent → color: transparent</p>
<p class="text-current">text-current → color: currentColor</p>
Couleurs
Tailwind utilise une echelle de couleurs numerique de 50 (le plus clair) a 950 (le plus fonce). Prefixes : bg- pour le fond, text- pour le texte, border- pour les bordures.
| Shade | bg-blue-* | Hex Value | Usage |
|---|
50 | bg-blue-50 | #eff6ff | Lightest background |
100 | bg-blue-100 | #dbeafe | Light background |
200 | bg-blue-200 | #bfdbfe | Hover states, light borders |
300 | bg-blue-300 | #93c5fd | Active states |
400 | bg-blue-400 | #60a5fa | Icons, secondary elements |
500 | bg-blue-500 | #3b82f6 | Primary brand color |
600 | bg-blue-600 | #2563eb | Primary buttons, links |
700 | bg-blue-700 | #1d4ed8 | Hover on primary |
800 | bg-blue-800 | #1e40af | Dark accents |
900 | bg-blue-900 | #1e3a8a | Darkest accent |
950 | bg-blue-950 | #172554 | Near-black backgrounds |
Color Prefixes
| Prefix | CSS Property | Example |
|---|
bg-* | background-color | bg-red-500 |
text-* | color | text-blue-600 |
border-* | border-color | border-gray-300 |
ring-* | box-shadow (ring) | ring-indigo-500 |
divide-* | border-color (dividers) | divide-gray-200 |
placeholder-* | placeholder color | placeholder-gray-400 |
from-* | gradient start | from-purple-500 |
via-* | gradient middle | via-pink-500 |
to-* | gradient end | to-red-500 |
<!-- Available color palettes -->
slate, gray, zinc, neutral, stone <!-- Grays -->
red, orange, amber, yellow <!-- Warm -->
lime, green, emerald, teal <!-- Green -->
cyan, sky, blue, indigo <!-- Blue -->
violet, purple, fuchsia, pink, rose <!-- Purple/Pink -->
<!-- Gradient example -->
<div class="bg-gradient-to-r from-blue-500 via-purple-500 to-pink-500">
Gradient background
</div>
Flexbox
Utilitaires flexbox complets pour construire des mises en page flexibles.
| Class | CSS Output |
|---|
flex | display: flex |
inline-flex | display: inline-flex |
flex-row | flex-direction: row |
flex-row-reverse | flex-direction: row-reverse |
flex-col | flex-direction: column |
flex-col-reverse | flex-direction: column-reverse |
flex-wrap | flex-wrap: wrap |
flex-wrap-reverse | flex-wrap: wrap-reverse |
flex-nowrap | flex-wrap: nowrap |
flex-1 | flex: 1 1 0% |
flex-auto | flex: 1 1 auto |
flex-initial | flex: 0 1 auto |
flex-none | flex: none |
Justify & Align
| Class | CSS Output |
|---|
justify-start | justify-content: flex-start |
justify-end | justify-content: flex-end |
justify-center | justify-content: center |
justify-between | justify-content: space-between |
justify-around | justify-content: space-around |
justify-evenly | justify-content: space-evenly |
items-start | align-items: flex-start |
items-end | align-items: flex-end |
items-center | align-items: center |
items-baseline | align-items: baseline |
items-stretch | align-items: stretch |
Gap
| Class | CSS Output |
|---|
gap-0 | gap: 0px |
gap-1 | gap: 0.25rem (4px) |
gap-2 | gap: 0.5rem (8px) |
gap-4 | gap: 1rem (16px) |
gap-6 | gap: 1.5rem (24px) |
gap-8 | gap: 2rem (32px) |
gap-x-4 | column-gap: 1rem |
gap-y-4 | row-gap: 1rem |
<!-- Flexbox layout examples -->
<!-- Centered content -->
<div class="flex items-center justify-center h-screen">
<div>Perfectly centered</div>
</div>
<!-- Navbar: logo left, links right -->
<nav class="flex justify-between items-center p-4">
<div class="text-xl font-bold">Logo</div>
<div class="flex gap-4">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Contact</a>
</div>
</nav>
<!-- Responsive cards -->
<div class="flex flex-wrap gap-4">
<div class="flex-1 min-w-[300px]">Card 1</div>
<div class="flex-1 min-w-[300px]">Card 2</div>
<div class="flex-1 min-w-[300px]">Card 3</div>
</div>
Grid
Utilitaires CSS Grid pour creer des mises en page bidimensionnelles.
| Class | CSS Output |
|---|
grid | display: grid |
grid-cols-1 | grid-template-columns: repeat(1, minmax(0, 1fr)) |
grid-cols-2 | grid-template-columns: repeat(2, minmax(0, 1fr)) |
grid-cols-3 | grid-template-columns: repeat(3, minmax(0, 1fr)) |
grid-cols-4 | grid-template-columns: repeat(4, minmax(0, 1fr)) |
grid-cols-6 | grid-template-columns: repeat(6, minmax(0, 1fr)) |
grid-cols-12 | grid-template-columns: repeat(12, minmax(0, 1fr)) |
grid-cols-none | grid-template-columns: none |
grid-rows-1 | grid-template-rows: repeat(1, minmax(0, 1fr)) |
grid-rows-3 | grid-template-rows: repeat(3, minmax(0, 1fr)) |
grid-rows-6 | grid-template-rows: repeat(6, minmax(0, 1fr)) |
Column & Row Span
| Class | CSS Output |
|---|
col-span-1 | grid-column: span 1 / span 1 |
col-span-2 | grid-column: span 2 / span 2 |
col-span-3 | grid-column: span 3 / span 3 |
col-span-4 | grid-column: span 4 / span 4 |
col-span-6 | grid-column: span 6 / span 6 |
col-span-full | grid-column: 1 / -1 |
row-span-1 | grid-row: span 1 / span 1 |
row-span-2 | grid-row: span 2 / span 2 |
row-span-3 | grid-row: span 3 / span 3 |
row-span-full | grid-row: 1 / -1 |
auto-cols-auto | grid-auto-columns: auto |
auto-cols-fr | grid-auto-columns: minmax(0, 1fr) |
auto-rows-auto | grid-auto-rows: auto |
auto-rows-fr | grid-auto-rows: minmax(0, 1fr) |
<!-- Grid layout examples -->
<!-- 3-column grid -->
<div class="grid grid-cols-3 gap-4">
<div>1</div> <div>2</div> <div>3</div>
<div>4</div> <div>5</div> <div>6</div>
</div>
<!-- Responsive grid: 1 col mobile, 2 tablet, 3 desktop -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
<div>Card 1</div>
<div>Card 2</div>
<div>Card 3</div>
</div>
<!-- Dashboard layout with spanning -->
<div class="grid grid-cols-4 gap-4">
<div class="col-span-4">Header (full width)</div>
<div class="col-span-1">Sidebar</div>
<div class="col-span-3">Main content</div>
<div class="col-span-2">Half width</div>
<div class="col-span-2">Half width</div>
</div>
Mise en page : Largeur, Hauteur et Conteneur
Utilitaires pour controler les dimensions des elements et les conteneurs.
| Class | CSS Output |
|---|
w-0 | width: 0px |
w-1 | width: 0.25rem (4px) |
w-4 | width: 1rem (16px) |
w-8 | width: 2rem (32px) |
w-16 | width: 4rem (64px) |
w-32 | width: 8rem (128px) |
w-64 | width: 16rem (256px) |
w-1/2 | width: 50% |
w-1/3 | width: 33.333% |
w-2/3 | width: 66.667% |
w-1/4 | width: 25% |
w-3/4 | width: 75% |
w-full | width: 100% |
w-screen | width: 100vw |
w-auto | width: auto |
w-fit | width: fit-content |
w-min | width: min-content |
w-max | width: max-content |
Height & Max/Min
| Class | CSS Output |
|---|
h-0 | height: 0px |
h-4 | height: 1rem (16px) |
h-16 | height: 4rem (64px) |
h-64 | height: 16rem (256px) |
h-full | height: 100% |
h-screen | height: 100vh |
h-auto | height: auto |
min-h-0 | min-height: 0px |
min-h-full | min-height: 100% |
min-h-screen | min-height: 100vh |
max-w-sm | max-width: 24rem (384px) |
max-w-md | max-width: 28rem (448px) |
max-w-lg | max-width: 32rem (512px) |
max-w-xl | max-width: 36rem (576px) |
max-w-2xl | max-width: 42rem (672px) |
max-w-4xl | max-width: 56rem (896px) |
max-w-6xl | max-width: 72rem (1152px) |
max-w-7xl | max-width: 80rem (1280px) |
max-w-full | max-width: 100% |
max-w-none | max-width: none |
container | width: 100% (responsive max-width) |
<!-- Layout examples -->
<div class="container mx-auto px-4">
Centered responsive container
</div>
<div class="max-w-2xl mx-auto">
Max-width 672px, centered
</div>
<div class="w-full h-screen">
Full width, full viewport height
</div>
<div class="min-h-screen flex flex-col">
<main class="flex-1">Content</main>
<footer>Footer always at bottom</footer>
</div>
Bordures et coins arrondis
Utilitaires pour la largeur des bordures, le style, le rayon et les effets de ring.
| Class | CSS Output |
|---|
border | border-width: 1px |
border-0 | border-width: 0px |
border-2 | border-width: 2px |
border-4 | border-width: 4px |
border-8 | border-width: 8px |
border-t | border-top-width: 1px |
border-r-2 | border-right-width: 2px |
border-b-4 | border-bottom-width: 4px |
border-l | border-left-width: 1px |
border-solid | border-style: solid |
border-dashed | border-style: dashed |
border-dotted | border-style: dotted |
border-none | border-style: none |
Border Radius
| Class | CSS Output |
|---|
rounded-none | border-radius: 0px |
rounded-sm | border-radius: 0.125rem (2px) |
rounded | border-radius: 0.25rem (4px) |
rounded-md | border-radius: 0.375rem (6px) |
rounded-lg | border-radius: 0.5rem (8px) |
rounded-xl | border-radius: 0.75rem (12px) |
rounded-2xl | border-radius: 1rem (16px) |
rounded-3xl | border-radius: 1.5rem (24px) |
rounded-full | border-radius: 9999px |
rounded-t-lg | border-top-left/right-radius: 0.5rem |
rounded-b-lg | border-bottom-left/right-radius: 0.5rem |
Ring (Outline)
| Class | CSS Output |
|---|
ring-0 | box-shadow: 0 0 0 0px ... |
ring-1 | box-shadow: 0 0 0 1px ... |
ring-2 | box-shadow: 0 0 0 2px ... |
ring-4 | box-shadow: 0 0 0 4px ... |
ring | box-shadow: 0 0 0 3px ... |
ring-inset | box-shadow: inset ... |
ring-blue-500 | ring color: #3b82f6 |
ring-offset-2 | ring offset: 2px |
ring-offset-white | ring offset color: #fff |
Ombres et effets
Utilitaires pour les ombres, l'opacite et les effets de flou.
| Class | CSS Output |
|---|
shadow-sm | box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05) |
shadow | box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1) |
shadow-md | box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1) |
shadow-lg | box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1) |
shadow-xl | box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1) |
shadow-2xl | box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25) |
shadow-inner | box-shadow: inset 0 2px 4px 0 rgb(0 0 0 / 0.05) |
shadow-none | box-shadow: 0 0 #0000 |
Opacity & Blur
| Class | CSS Output |
|---|
opacity-0 | opacity: 0 |
opacity-25 | opacity: 0.25 |
opacity-50 | opacity: 0.5 |
opacity-75 | opacity: 0.75 |
opacity-100 | opacity: 1 |
blur-none | filter: blur(0) |
blur-sm | filter: blur(4px) |
blur | filter: blur(8px) |
blur-md | filter: blur(12px) |
blur-lg | filter: blur(16px) |
blur-xl | filter: blur(24px) |
blur-2xl | filter: blur(40px) |
blur-3xl | filter: blur(64px) |
backdrop-blur-sm | backdrop-filter: blur(4px) |
backdrop-blur | backdrop-filter: blur(8px) |
backdrop-blur-md | backdrop-filter: blur(12px) |
backdrop-blur-lg | backdrop-filter: blur(16px) |
backdrop-blur-xl | backdrop-filter: blur(24px) |
Transitions et animations
Utilitaires pour les transitions CSS et les animations keyframe.
| Class | CSS Output |
|---|
transition-none | transition-property: none |
transition-all | transition-property: all |
transition | transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter |
transition-colors | transition-property: color, background-color, border-color, text-decoration-color, fill, stroke |
transition-opacity | transition-property: opacity |
transition-shadow | transition-property: box-shadow |
transition-transform | transition-property: transform |
Duration & Easing
| Class | CSS Output |
|---|
duration-75 | transition-duration: 75ms |
duration-100 | transition-duration: 100ms |
duration-150 | transition-duration: 150ms |
duration-200 | transition-duration: 200ms |
duration-300 | transition-duration: 300ms |
duration-500 | transition-duration: 500ms |
duration-700 | transition-duration: 700ms |
duration-1000 | transition-duration: 1000ms |
ease-linear | transition-timing-function: linear |
ease-in | transition-timing-function: cubic-bezier(0.4, 0, 1, 1) |
ease-out | transition-timing-function: cubic-bezier(0, 0, 0.2, 1) |
ease-in-out | transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1) |
Animations
| Class | Description |
|---|
animate-none | No animation |
animate-spin | Continuous rotation (loading spinners) |
animate-ping | Scale + fade out (notification dot) |
animate-pulse | Gentle fade in/out (skeleton loaders) |
animate-bounce | Bouncing motion (scroll indicator) |
<!-- Transition examples -->
<button class="bg-blue-500 hover:bg-blue-700 transition-colors duration-200">
Smooth color change on hover
</button>
<div class="hover:scale-105 transition-transform duration-300 ease-out">
Scale up on hover
</div>
<div class="hover:shadow-xl transition-shadow duration-300">
Shadow appears on hover
</div>
<!-- Animation examples -->
<svg class="animate-spin h-5 w-5">...</svg> <!-- Loading spinner -->
<span class="animate-ping absolute">...</span> <!-- Notification dot -->
<div class="animate-pulse bg-gray-300 h-4 rounded">...</div> <!-- Skeleton -->
Prefixes responsifs
Tailwind utilise une approche mobile-first. Prefixez n'importe quel utilitaire avec un breakpoint pour l'appliquer a cette taille et au-dessus.
| Prefix | Min Width | CSS Media Query |
|---|
(none) | 0px | No media query (applies to all) |
sm: | 640px | @media (min-width: 640px) { ... } |
md: | 768px | @media (min-width: 768px) { ... } |
lg: | 1024px | @media (min-width: 1024px) { ... } |
xl: | 1280px | @media (min-width: 1280px) { ... } |
2xl: | 1536px | @media (min-width: 1536px) { ... } |
<!-- Mobile-first responsive design -->
<!-- Stack on mobile, side-by-side on tablet+ -->
<div class="flex flex-col md:flex-row gap-4">
<div class="w-full md:w-1/3">Sidebar</div>
<div class="w-full md:w-2/3">Main</div>
</div>
<!-- Responsive text size -->
<h1 class="text-2xl sm:text-3xl md:text-4xl lg:text-5xl">
Responsive Heading
</h1>
<!-- Responsive grid columns -->
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
<div>Card</div>
<div>Card</div>
<div>Card</div>
<div>Card</div>
</div>
<!-- Hide/show at breakpoints -->
<div class="hidden md:block">Visible on md and above</div>
<div class="block md:hidden">Visible only below md</div>
<!-- Responsive padding -->
<div class="p-4 sm:p-6 md:p-8 lg:p-12">
Padding grows with screen size
</div>
Variantes d'etat
Appliquez des styles conditionnellement avec les prefixes de variantes d'etat.
| Variant | CSS Selector / Condition | Example |
|---|
hover: | :hover | hover:bg-blue-700 |
focus: | :focus | focus:outline-none focus:ring-2 |
focus-within: | :focus-within | focus-within:border-blue-500 |
focus-visible: | :focus-visible | focus-visible:ring-2 |
active: | :active | active:bg-blue-800 |
disabled: | :disabled | disabled:opacity-50 |
visited: | :visited | visited:text-purple-600 |
first: | :first-child | first:mt-0 |
last: | :last-child | last:mb-0 |
odd: | :nth-child(odd) | odd:bg-gray-100 |
even: | :nth-child(even) | even:bg-gray-50 |
group-hover: | .group:hover & | group-hover:text-white |
peer-focus: | .peer:focus ~ & | peer-focus:text-blue-500 |
dark: | prefers-color-scheme: dark | dark:bg-gray-900 |
placeholder: | ::placeholder | placeholder:text-gray-400 |
before: | ::before | before:content-[""] |
after: | ::after | after:content-[""] |
<!-- State variant examples -->
<!-- Button with multiple states -->
<button class="bg-blue-500 hover:bg-blue-700 active:bg-blue-800
focus:outline-none focus:ring-2 focus:ring-blue-300
disabled:opacity-50 disabled:cursor-not-allowed
transition-colors duration-200">
Click me
</button>
<!-- Group hover: parent hover affects child -->
<div class="group p-4 hover:bg-blue-50 rounded-lg">
<h3 class="group-hover:text-blue-600">Title</h3>
<p class="group-hover:text-blue-400">Description</p>
</div>
<!-- Dark mode -->
<div class="bg-white dark:bg-gray-900 text-black dark:text-white">
Adapts to light/dark mode
</div>
<!-- Peer: input state affects sibling -->
<input class="peer" type="text" placeholder="Email" />
<p class="invisible peer-invalid:visible text-red-500">
Invalid email address
</p>
Astuces et utilisation avancee
Fonctionnalites avancees quand les utilitaires integres ne suffisent pas.
Valeurs arbitraires
Utilisez des crochets pour specifier une valeur personnalisee :
<!-- Arbitrary values with square brackets -->
<div class="w-[120px]">width: 120px</div>
<div class="h-[calc(100vh-80px)]">height: calc(100vh - 80px)</div>
<div class="bg-[#1a2b3c]">background: #1a2b3c</div>
<div class="text-[22px]">font-size: 22px</div>
<div class="grid-cols-[200px_1fr_200px]">custom grid template</div>
<div class="p-[clamp(1rem,3vw,3rem)]">responsive clamp padding</div>
<div class="text-[color:var(--brand)]">CSS variable color</div>
<div class="top-[var(--header-h)]">CSS variable position</div>
Modificateur Important
Prefixez un utilitaire avec ! pour ajouter !important :
<!-- Important modifier with ! prefix -->
<div class="!p-4">padding: 1rem !important</div>
<div class="!mt-0">margin-top: 0 !important</div>
<div class="!text-red-500">color: #ef4444 !important</div>
<!-- Useful for overriding third-party styles -->
<div class="external-widget !bg-transparent !border-none">
Override library styles
</div>
Directive @apply
Extrayez les patterns repetes en classes CSS personnalisees :
/* In your CSS file — use @apply to extract components */
.btn {
@apply px-4 py-2 rounded-lg font-semibold transition-colors duration-200;
}
.btn-primary {
@apply btn bg-blue-500 text-white hover:bg-blue-700;
}
.btn-secondary {
@apply btn bg-gray-200 text-gray-800 hover:bg-gray-300;
}
.input {
@apply w-full px-3 py-2 border border-gray-300 rounded-md
focus:outline-none focus:ring-2 focus:ring-blue-500
focus:border-transparent;
}
.card {
@apply bg-white dark:bg-gray-800 rounded-xl shadow-md p-6
hover:shadow-lg transition-shadow duration-300;
}
/* Note: Tailwind recommends using utilities directly in HTML
and only extracting with @apply for truly repeated patterns. */
Questions frequentes
Quelle est la difference entre Tailwind CSS et le CSS classique ?
Tailwind CSS est un framework utilitaire qui fournit des classes CSS preconstruites a appliquer directement en HTML. Contrairement au CSS classique, Tailwind utilise des noms de classes comme p-4, text-lg, bg-blue-500.
Comment fonctionne l'echelle d'espacement ?
Chaque unite vaut 0.25rem (4px). p-1 = 0.25rem, p-4 = 1rem (16px). L'echelle va de 0 a 96 (24rem/384px). Les valeurs arbitraires comme p-[13px] sont aussi supportees.
Comment fonctionnent les breakpoints responsifs ?
Approche mobile-first. Les utilitaires sans prefixe s'appliquent a toutes les tailles. md:flex s'applique a partir de 768px. Breakpoints : sm(640px), md(768px), lg(1024px), xl(1280px), 2xl(1536px).
Peut-on utiliser des couleurs personnalisees ?
Oui. Etendez la palette dans tailwind.config.js sous theme.extend.colors ou utilisez des valeurs arbitraires comme bg-[#1a2b3c].
Qu'est-ce que la directive @apply ?
@apply permet d'extraire des patterns de classes repetes en classes CSS personnalisees. Utilisez-la avec parcimonie - Tailwind recommande d'utiliser les utilitaires directement.
Comment supporter le mode sombre ?
Utilisez la variante dark:, par exemple bg-white dark:bg-gray-900. Configurez la strategie dans tailwind.config.js comme "media" ou "class".