Show Menu
Cheatography

TailwindCSS Cheat Sheet (DRAFT) by

Tailwind CSS - by Helen

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Button

cursor­-no­t-a­llowed
bg-gra­die­nt-­to-bl from-purpl­e-500 via-yello­w-500 to-green-400
bg-gra­die­nt-to-t
Gradient from bottom to top
bg-gra­die­nt-to-b
Gradient from top to bottom
bg-gra­die­nt-to-l
Gradient from right to left
bg-gra­die­nt-to-r
Gradient from left to right
bg-gra­die­nt-­to-tl
Gradient from bottom­-right to top-left
bg-gra­die­nt-­to-tr
Gradient from bottom­-left to top-right
bg-gra­die­nt-­to-bl
Gradient from top-right to bottom­-left
bg-gra­die­nt-­to-br
Gradient from top-left to bottom­-right
Can define custom button styles in tailwind css

1. use @layer components in global.css

@layer components {
.btn-p­rimary {
@apply px-4 py-2 bg-blu­e-500 text-white font-s­emibold rounded shadow-md hover:­bg-­blu­e-600 transi­tion;
}
}

2. import global path at your page
import "../­sty­les­/gl­oba­l.c­ss";

ul / li

list-disc
list-d­ecimal
marker (Style Numbers)
list-i­nside
<ul class=­"­lis­t-disc pl-6 space-y-2 marker­:te­xt-­sky­-40­0">
<li­>5 cups chopped Porcini mushro­oms­</l­i>
<li­>1/2 cup of olive oil</l­i>
<li­>3lb of celery­</l­i>
</u­l>

Text align

text-left
text-c­enter
text-right

Text transforms

uppercase
lowercase
capitalize

Font size

text-xs
12px
text-sm
14px
text-base
16px
text-lg
18px
text-xl
20px
text-2xl
24px
text-9xl
128px
text-[­50px]
Valid
You can extend Tailwind’s font size scale in tailwi­nd.c­on­fig.js:
export default {
theme: {
extend: {
fontSize: {
'xxs': '10px',
'huge': '100px',
}
}
}
}

.astro:
<h1 class=­"­tex­t-h­uge­"­>Ab­out­</h­1>

Background colors / Text colors

bg-red-400
text-r­ed-400
bg-primary
bg-sec­ondary
bg-ter­tiary
bg-alt
bg-white
bg-black
bg-pla­ceh­older
text-[­#a4­d01e]
bg-[#a­4d01e]
extend: {
colors:{
primar­y:"#­1e4­0AF­",
}
},

<div class=­"bg-primary"­></­div>
<p class=­"text-p­rimary"­>Ab­out­</p>

Text decoration

underline
overline
line-t­hrough
decora­tio­n-r­ed-500
decora­tio­n-solid
decora­tio­n-d­ouble
decora­tio­n-d­otted
decora­tio­n-d­ashed
decora­tio­n-wavy
decora­tion-0
decora­tion-1
decora­tion-2
decora­tion-4
decora­tion-8
<h1 class=­"­tex­t-b­lue-600 line-t­hrough decora­tio­n-r­ed-200 decora­tio­n-wavy decora­tio­n-4­"­>Ab­out­</h­1>

Font weight

font-thin
font-e­xtr­alight
font-light
font-n­ormal
font-m­edium
font-s­emibold
font-bold
font-e­xtr­abold
font-black

Font family

font-sans (default)
font-serif
font-mono
fontFa­mily: {
fancy: ['"P­opp­ins­"', 'sans-­ser­if'],
code: ['"Fira Code"', 'monos­pace'],
},

<h1 class=­"­fon­t-c­ode­"­>Te­sti­ng<­/h1>

Line height

leadin­g-tight (1.25)
leadin­g-snug (1.375)
leadin­g-n­ormal (1.5)
leadin­g-r­elaxed (1.625)
leadin­g-loose (2)
leading-[1.1]

Letter Spacing

tracki­ng-­tighter (-0.05em)
tracki­ng-­tight (-0.025em)
tracki­ng-­nor­mal­(0em)
tracki­ng-­wid­e(0.025em)
tracki­ng-­wid­est­(0.1em)

Shadow

shadow-xl
shadow­-gr­ay-400
shadow­-inner (Applies the shadow inside the element)
text ✔elements ❌(div/­but­ton­/image)
boxShadow: {
'neon-­green': '0px 4px 10px rgba(164, 208, 30, 0.6)',
},


<div class=­"­sha­dow­-ne­on-­green w-32 h-44"><­/di­v>

Opacity

opacity
opacity-20

Blur

blur-sm

Cursor

cursor­-auto (default browser cursor)
cursor­-de­fault (default arrow pointer)
cursor­-po­inter (pointer hand ☝)
cursor­-text (text selection )
cursor­-no­t-a­llowed (🚫Shows a blocked circle)
cursor­-wait (⏳Shows a loading wait cursor)
cursor­-pr­ogress (Shows a progress indicator)
cursor­-move (✥ Move cursor (for draggable elements)
cursor­-grab (🖐 Open hand cursor (grabb­able)
cursor­-gr­abbing (✊ Closed hand cursor, while dragging)
cursor­-n-­resize (⬆ Resize vertically (north)
a lot different area resize
cursor­-none (hides the cursor)
cursor­-help (shows a question mark cursor)
cursor­-zo­om-in (🔍➕)
cursor­-zo­om-out (🔍➖)

Position

absolute
relative
fixed
ticky
left / top / right / bottom

scale-*

Blend modes

mix-bl­end­-normal (default, no blend)
mix-bl­end­-mu­ltiply (multiply, darken effect)
mix-bl­end­-screen (screen, lighten effect)
mix-bl­end­-ov­erlay (overlay, contrast effect)
mix-bl­end­-darken (darken)
mix-bl­end­-co­lor­-dodge (color dodge)
mix-bl­end­-co­lor­-burn (color burn)
mix-bl­end­-di­ffe­rence (diffe­rence)
mix-bl­end­-ex­clusion (exclusion 排除)
mix-bl­end-hue (hue 色调)
mix-bl­end­-sa­tur­ation (satur­ati­on饱和)
mix-bl­end­-color (color)
mix-bl­end­-lu­min­osity (lumin­osi­ty亮度)

Other

whites­pac­e-n­owrap (Prevents text from wrapping to the next line.)
overfl­ow-­hidden (Hides overfl­owing content (anything that goes beyond the contai­ner).)
 

Width

w-auto
w-5
h-auto
h-5
w-1/2
w-1/3
w-2/4
h-1/2
h-1/3
h-2/4
w-full
w-screen
h-full
h-screen
w-10p (Invalid)
width:{
"­wid­th":­"­10%­",
},
height:{
"­hei­ght­"­:"50­%",
},

<div class=­"­bg-­primary w-width h-heig­ht">­Bac­kgr­oun­d</­div>

Pseudo­-cl­assess

hover:
focus:
active:
select:
file:
print:
first-­letter
first-line
landscape:
portrait:
dark:
marker:
visited:
disabled:
checked:
invalid
valid
required:
placeh­old­er-­shown:
placeh­older:
peer-i­n-r­ange:
peer-o­ut-­of-­range:
sm:
md:
lg:
xl:
2xl:
<input
type="f­ile­"
class=­"­fil­e:mr-4 file:r­oun­ded­-full file:b­order-5 file:b­g-v­iol­et-50 file:px-4 file:py-2 file:t­ext-sm file:f­ont­-se­mibold file:t­ext­-vi­ole­t-7­00"
/>

only work for file

Aspect Ratios

Aspect­-auto (Default based on content)
Aspect­-square (1:1 square)
Aspect­-video (16:9 video)
Aspect­-wi­des­creen (21:9 ultrawide)
Aspect­-[4/3] (4:3 old TV)
Aspect­-[3/2] (3:2 photo)

Padding & Margin

p-0 (no padding)
p-8
p-8
pt-1
pr-5
pb-2
pl-2
px-1 (padding left & right)
py-2 (padding top & bottom)
m-auto (used to center element horizo­ntally)
-mx-4
-mt-3
-m-2
padding use p-
margin use m-
p-auto (Invalid)
margin can support negative, but -m-auto (Invalid).

Border & ring

border default 1px border
border-0
border-2
border-4
border-8
border-t
border-r
border-b-5
border-l-2
border­-gr­een-400
border­-solid (default)
border­-dashed
border­-dotted
border­-double
ring-3
ring-blue-400

Box shadow

shadow-xs
shadow-2xl

Rounded

rounde­d-none
rounded-sm
rounded
rouond­ed-md
rounded-lg
rounded-xl
rounde­d-2xl
rounde­d-3xl
rounde­d-full
rounded-t
rounded-r
rounded-l
rounded-b
-> Can add size (round­ed-­t-lg)

Animation

ease-l­inear
ease-in
ease-out
ease-i­n-out
transi­tio­n-all
durati­on-500
delay
<button class=­"­bg-­blu­e-500 text-white px-4 py-2 rounded-lg transi­tio­n-all durati­on-500 ease-out hover:­sca­le-­110­">
Hover Me
</b­utt­on>

<div class=­"w-32 h-32 bg-red-500 transform transl­ate­-x-­[-1­00px] transi­tio­n-all durati­on-700 ease-out hover:­tra­nsl­ate­-x-­0">
Slide In
</d­iv>

<div class=­"­opa­cit­y-100 transi­tio­n-o­pacity durati­on-700 ease-out hover:­opa­cit­y-0­">
Fade Out on Hover
</d­iv>

Display

grid
flex

Display : flex (justi­fy-­con­tent)

justif­y-end (col: right)
items-end (row: bottom)
justif­y-start / justif­y-n­ormal / items-­start / (position: left)
items-­center (row: center)
justif­y-c­enter (col: center)
justif­y-e­venly (same equal space)
justif­y-b­etween (first item align to first, and last item align to the last. The remain space equals.
justif­y-a­round (equal between item, half of the middle space at the first and last item)
items-­stretch ( stretches items vertically to fill the parent contai­ner's height (Only works if the items don't have a fixed height (h-3)
flex-col (arrange its items vertically (column direct­ion))
* space-y-5 (to add place between the column [vertical)
* space-x-5 (to add place between the column [horiz­ontal])
gap-3 (sets the space between child elements inside a flexbox, grid, or gap-su­pported layout.)
gap-x-3 (horiz­­ontal spacing [left-­­ri­ght])
gap-y-2 (vertical spacing [top-b­­ot­tom])
<div class=­"flex gap-4 bg-gra­y-200 p-4">
<div class=­"­bg-­blu­e-500 p-4 w-1/3 h-16">Item 1</­div>
<div class=­"­bg-­red-500 p-4 w-1/3 h-16">Item 2</­div>
<div class=­"­bg-­gre­en-500 p-4 w-1/3 h-16">Item 3</­div>
</d­iv>

*must set width and height. *

Display : flex (flex-­wrap)

flex-wrap
flex-w­rap­:wrap;
flex-w­rap­-re­verse
flex-w­rap­:wr­ap-­rev­erse;
flex-n­owrap
flex-w­rap­:nowrap
nowrap: Every item is fit to a single line.
wrap: Items wrap around to additional lines.
wrap-r­everse: Items wrap around to additional lines in reverse.

Display : flex (flex-­dir­ection)

row: Items are placed the same as the text direction. (
row-re­verse: Items are placed opposite to the text direction. (right)
column: Items are placed top to bottom.
column­-re­verse: Items are placed bottom to top.

Display : flex (flex-­flow)

The flex-flow property is a shorthand for both flex-d­ire­ction and flex-wrap.

Display : flex (align­-co­ntent)

conten­t-start
align-­con­tent: flex-s­tart;
conten­t-end
align-­con­tent: flex-end;
conten­t-c­enter
align-­con­tent: center;
conten­t-b­etween
align-­con­tent: space-­bet­ween;
conten­t-a­round
align-­con­tent: space-­around;
conten­t-e­venly
align-­con­tent: space-­evenly;
conten­t-s­tretch
align-­con­tent: stretch;
conten­t-s­tart: Rows align at the top.
conten­t-end: Rows align at the bottom.
conten­t-c­enter: Rows align in the middle.
conten­t-b­etween: Rows spread evenly with space between them.
conten­t-a­round: Rows have equal space around them.
conten­t-e­venly: Rows are evenly spaced in the container.
conten­t-s­tretch: Rows stretch to fill the container height.

Display : flex (align­-items)

items-­start
align-­ite­ms:­fle­x-s­tart;
items-end
align-­ite­ms:­fle­x-end;
items
align-­ite­ms:­center;
items-­bas­eline
align-­ite­ms:­bas­eline;
items-­stretch
align-­ite­ms:­str­etch; (default)
flex-s­tart: Items align to the top of the container.
flex-end: Items align to the bottom of the container.
center: Items align at the vertical center of the container.
baseline: Items display at the baseline of the container.
stretch: Items are stretched to fit the container. (default)

Display : flex (order)

order-1
Each order has a default order of 0.
Lower order values appear first, while higher values appear later.
We can use this property to also set it to a positive or negative integer value (-2, -1, 0, 1, 2).

Display : flex (self)

self-auto
align-­self: auto;
self-start
align-­self: flex-s­tart;
self-c­enter
align-­sel­f:c­enter;
self-end
align-­sel­f:f­lex­-end;
self-s­tretch
align-­sel­f:s­tretch;
self-b­aseline
align-­sel­f:b­ase­line;
align-­items affects all flex items inside the container.
align-self overrides align-­items but only for the specific item you apply it to.

Display : grid

justif­y-start (align the entire grid to the left of the container)
justif­y-end (align the entire grid to the right of the container)
justif­y-c­enter (center the entire grid inside its container)
justif­y-b­etween (distr­ibutes items evenly inside the grid container)
grid-cols-3 (set column as 3) [grid-­col­-start: 2;]
grid-rows-4 (set row as 4) [grid-­row­-start: 2;]
col-start-2 / row-start-2 [grid-­col­umn­-start: 2] (Starts the element at column 2)
col-end-4 / row-end-4 [grid-­row­-start: 2] (Ends at column 4, not including column 4 itself)
CSS: grid-c­olu­mn-­sta­rt:2; / grid-c­olu­mn-­sta­rt:4;
col-span-2 (Makes the item span 2 columns instead of specifying col-end directly) [grid-­col­umn­-en­d:span 2]
gap-3 (sets the space between child elements inside a flexbox, grid, or gap-su­pported layout.)
gap-x-3 (horiz­ontal spacing [left-­right])
gap-y-2 (vertical spacing [top-b­ottom])
<div class=­"grid mt-5 grid-c­ols-2 gap-x-5 bg-gra­y-200 h-40 p-4 ">
<div class=­"­rou­nde­d-full bg-blu­e-5­00">­</d­iv>
</d­iv>

* no need set the h and w *

<div class=­"­w-full bg-[#e­8f0f7] grid gap-20 mt-20 grid-c­ols-1 sm:gri­d-c­ols-2 lg:gri­d-c­ols­-3">
</d­iv>

grid-c­ols-1 → Defaults to 1 column on extra-­small screens.
sm:gri­d-c­ols-2 → Changes to 2 columns on small screens (≥ 640px).
lg:gri­d-c­ols-3 → Changes to 3 columns on large screens (≥ 1024px).