Catalog / Tailwind CSS Cheatsheet
Tailwind CSS Cheatsheet
A comprehensive cheat sheet for Tailwind CSS, covering essential utilities, directives, and concepts for rapid UI development.
Core Concepts & Setup
Installation
Using npm:
Using yarn:
|
Configure your template paths in
|
Add Tailwind directives to your CSS:
|
Utility-First Fundamentals
Tailwind CSS is a utility-first CSS framework. Instead of pre-designed components, it provides low-level utility classes that you compose to build custom designs directly in your HTML. |
Example:
|
This creates a blue button that changes color on hover, has white text, bold font, padding, and rounded corners. |
Common Utilities
Layout
|
Centers content horizontally with maximum width based on breakpoints. |
|
Sets the display property of an element. |
|
Enables CSS Grid and Flexbox layouts. |
|
Sets the position property of an element. |
Spacing
|
Sets padding on all sides of an element. E.g., |
|
Sets padding on the top, bottom, left, and right sides respectively. E.g., |
|
Sets margin on all sides of an element. E.g., |
|
Sets margin on the top, bottom, left, and right sides respectively. E.g., |
|
Adds space between elements in a flex or grid container. E.g., |
Typography
|
Sets the font family. E.g., |
|
Sets the text size. E.g., |
|
Sets the font weight. |
|
Sets the font style. |
|
Sets text decoration. |
|
Sets text alignment. |
Customization & Directives
Configuration
The |
Example: Extending the theme
|
This adds a custom color |
Directives
|
Used to inject Tailwind’s base, components, and utilities styles. |
|
Allows you to use Tailwind’s utility classes directly in your own CSS. Useful for extracting reusable component styles.
|
|
Used to organize custom CSS into layers (base, components, utilities). This helps Tailwind properly optimize and order the CSS.
|
|
Specifies a custom Tailwind configuration file. |
Responsive Design & State Variants
Responsive Modifiers
Tailwind uses breakpoint prefixes to apply styles conditionally based on screen size. |
Example:
|
State Variants
|
Applies styles on hover. |
|
Applies styles when the element is focused. |
|
Applies styles when the element is active (e.g., being clicked). |
|
Applies styles when the element is disabled. |
|
Applies styles to the parent when a child element is focused. |
|
Applies styles when the element is focused using the keyboard (accessibility). |
Dark Mode
Tailwind supports dark mode using the
|
Then, you can use the
|