I created this cheat sheet to serve as a quick reference for common CSS properties in Tailwind along with their corresponding classes. As a beginner, I often find myself needing to look up these classes in the Tailwind documentation. With this cheat sheet, you’ll have a handy resource at your fingertips to help you build muscle memory and speed up your development process.
Here are the CSS properties and classes that I use most frequently:
Margin and Padding
-
Margin and padding classes follow a specific naming convention:
pstands for paddingmstands for margin-mrepresents negative margin
Additionally, you can combine these classes with directional and sizing modifiers:
tfor toprfor rightbfor bottomlfor leftxfor horizontal (left and right)yfor vertical (top and bottom)
The numerical values indicate the size of the margin or padding, ranging from
0to32. Additionally,pxcorresponds to1pxandautorepresentsautovalue.For example:
pt-2representspadding-top: 0.5remm-autorepresentsmargin: 0 auto
Width
The width classes determine the width of an element. They range from w-1 to w-screen, indicating different sizes and percentages.
Max Width
Max width classes are used to set the maximum width of an element. They range from max-w-xs to max-w-full.
Min Width
Min width classes define the minimum width of an element. The available classes are min-w-0 and min-w-full.
Font Family
Font family classes are available to set the font-family property. The classes include font-sans, font-serif, and font-mono.
Font Size
To adjust the font size, use the font size classes such as text-xs, text-sm, text-base, and more.
Font Weight
Control the font weight with classes like font-hairline, font-bold, and font-black.
Colors
Tailwind provides a wide range of color classes for convenience. Available colors include transparent, black, gray, white, red, orange, yellow, green, teal, blue, indigo, purple, and pink. Each color also has different intensity levels ranging from -100 to -900.
Text Color
To change the text color, prepend text- to the desired color class.
Background Color
Prepend bg- to the color class to set the background color.
Center Text
Use the text-center class to center align text.
Line Height
Line height can be adjusted with classes like .leading-none, .leading-tight, .leading-normal, and .leading-loose.
Flexbox
Flexbox plays a vital role in modern web design. Here are the relevant classes for implementing flexbox layout:
Container
flexfordisplay: flexinline-flexfordisplay: inline-flex
Items
Direction
flex-rowforflex-direction: rowflex-row-reverseforflex-direction: row-reverseflex-colforflex-direction: columnflex-col-reverseforflex-direction: column-reverse
Wrapping
flex-no-wrapforflex-wrap: nowrapflex-wrapforflex-wrap: wrapflex-wrap-reverseforflex-wrap: wrap-reverse
Align Items
items-stretchforalign-items: stretchitems-startforalign-items: flex-startitems-centerforalign-items: centeritems-endforalign-items: flex-enditems-baselineforalign-items: baseline
Align Content
content-startforalign-content: flex-startcontent-centerforalign-content: centercontent-endforalign-content: flex-endcontent-betweenforalign-content: space-betweencontent-aroundforalign-content: space-around
Align Self
self-autoforalign-self: autoself-startforalign-self: flex-startself-centerforalign-self: centerself-endforalign-self: flex-endself-stretchforalign-self: stretch
Justify Content
justify-startforjustify-content: flex-startjustify-centerforjustify-content: centerjustify-endforjustify-content: flex-endjustify-betweenforjustify-content: space-betweenjustify-aroundforjustify-content: space-around
Flex, Grow, Shrink
flex-initialforflex: initialflex-1forflex: 1flex-autoforflex: autoflex-noneforflex: noneflex-growforflex-grow: 1flex-shrinkforflex-shrink: 1flex-no-growforflex-grow: 0flex-no-shrinkforflex-shrink: 0
Modifiers
Hover
To apply a specific style on hover, prefix the class with hover:.
That concludes our Tailwind Cheat Sheet! Keep this handy resource within reach to streamline your development process.