CSS Cheat Sheet
Searchable CSS properties and patterns cheat sheet organized by category. Covers selectors, Flexbox, Grid, box model, typography, layout, and visual effects with copy support.
Last updated:
How to Use
Expand how to useCollapse how to use
- 1
Search for properties
Enter a property name in the search field, or filter by category (Flexbox, Grid, etc.) to find what you need.
- 2
Review syntax and values
Check the property description, syntax, and available values for each CSS property.
- 3
Copy the property
Click the copy button to copy the property name to your clipboard for immediate use in your stylesheet.
elementSelect elements by tag name
Syntax
element { }Values
- div { } — select all div elements
- p { } — select all paragraph elements
- h1 { } — select all h1 headings
- a { } — select all anchor elements
.classSelect elements by class name
Syntax
.classname { }Values
- .btn { } — select all elements with class 'btn'
- .btn.primary { } — select elements with both classes
- div.card { } — select div elements with class 'card'
#idSelect element by unique ID
Syntax
#idname { }Values
- #header { } — select element with id 'header'
- #nav { } — select element with id 'nav'
[attr]Select elements by attribute
Syntax
[attr], [attr=value], [attr^=value]Values
- [href] { } — elements that have href attribute
- [type="text"] { } — input elements with type text
- [class^="btn"] { } — class starting with 'btn'
- [href$=".pdf"] { } — href ending with .pdf
:pseudo-classSelect elements based on state or position
Syntax
selector:pseudo-class { }Values
- :hover — mouse over state
- :focus — focused element
- :nth-child(n) — nth child element
- :first-child — first child element
- :not(selector) — elements not matching selector
::pseudo-elementStyle specific parts of an element
Syntax
selector::pseudo-element { }Values
- ::before — insert content before element
- ::after — insert content after element
- ::first-line — style first line of text
- ::placeholder — style placeholder text
combinatorsCombine selectors to express relationships
Syntax
A B, A > B, A + B, A ~ BValues
- A B { } — B that is a descendant of A
- A > B { } — B that is a direct child of A
- A + B { } — B immediately following A (sibling)
- A ~ B { } — all B siblings following A
display: flexEnable flexbox layout on a container
Syntax
display: flex | inline-flexValues
- flex — block-level flex container
- inline-flex — inline-level flex container
flex-directionSet the direction of flex items
Syntax
flex-direction: row | row-reverse | column | column-reverseValues
- row — left to right (default)
- row-reverse — right to left
- column — top to bottom
- column-reverse — bottom to top
justify-contentAlign flex items along the main axis
Syntax
justify-content: flex-start | flex-end | center | space-between | space-around | space-evenlyValues
- flex-start — items at start (default)
- flex-end — items at end
- center — items centered
- space-between — equal space between items
- space-around — equal space around items
- space-evenly — equal space between and around items
align-itemsAlign flex items along the cross axis
Syntax
align-items: stretch | flex-start | flex-end | center | baselineValues
- stretch — items stretch to fill (default)
- flex-start — items at cross-axis start
- flex-end — items at cross-axis end
- center — items centered on cross axis
- baseline — items aligned by text baseline
flex-wrapControl whether flex items wrap to new lines
Syntax
flex-wrap: nowrap | wrap | wrap-reverseValues
- nowrap — all items on one line (default)
- wrap — items wrap to next line
- wrap-reverse — items wrap in reverse direction
gapSet spacing between flex or grid items
Syntax
gap: <row-gap> <column-gap>Values
- gap: 16px — equal gap in all directions
- gap: 8px 16px — row-gap 8px, column-gap 16px
- row-gap: 8px — gap between rows only
- column-gap: 16px — gap between columns only
flex-growSet how much a flex item grows relative to siblings
Syntax
flex-grow: <number>Values
- 0 — item does not grow (default)
- 1 — item grows to fill available space
- 2 — item grows twice as much as flex-grow: 1
flex-shrinkSet how much a flex item shrinks relative to siblings
Syntax
flex-shrink: <number>Values
- 1 — item shrinks if needed (default)
- 0 — item does not shrink
- 2 — item shrinks twice as much as flex-shrink: 1
flex-basisSet the initial main size of a flex item
Syntax
flex-basis: auto | <length> | <percentage>Values
- auto — use item's natural size (default)
- 0 — item starts from zero size
- 200px — item starts at 200px
- 50% — item starts at 50% of container
display: gridEnable CSS Grid layout on a container
Syntax
display: grid | inline-gridValues
- grid — block-level grid container
- inline-grid — inline-level grid container
grid-template-columnsDefine the columns of a grid
Syntax
grid-template-columns: <track-list>Values
- repeat(3, 1fr) — 3 equal columns
- 200px 1fr 200px — fixed, flexible, fixed
- repeat(auto-fill, minmax(200px, 1fr)) — responsive columns
- repeat(auto-fit, minmax(150px, 1fr)) — auto-fit columns
grid-template-rowsDefine the rows of a grid
Syntax
grid-template-rows: <track-list>Values
- 100px 1fr — header then flexible main
- repeat(3, 100px) — 3 rows of 100px
- auto — row sized by content
- minmax(100px, auto) — min 100px, max content
gap (grid)Set spacing between grid tracks
Syntax
gap: <row-gap> <column-gap>Values
- gap: 16px — equal gap
- gap: 8px 16px — row gap, column gap
- row-gap: 8px — only between rows
- column-gap: 16px — only between columns
grid-columnSet a grid item's column span
Syntax
grid-column: <start> / <end>Values
- grid-column: 1 / 3 — span from column 1 to 3
- grid-column: 1 / span 2 — start at 1, span 2 columns
- grid-column: 1 / -1 — span all columns
grid-rowSet a grid item's row span
Syntax
grid-row: <start> / <end>Values
- grid-row: 1 / 3 — span from row 1 to 3
- grid-row: 1 / span 2 — start at 1, span 2 rows
- grid-row: 2 / -1 — from row 2 to last
place-itemsShorthand for align-items and justify-items in grid
Syntax
place-items: <align-items> <justify-items>Values
- place-items: center — center on both axes
- place-items: start end — align start, justify end
- place-items: stretch — stretch on both axes (default)
marginSet space outside an element
Syntax
margin: <top> <right> <bottom> <left>Values
- margin: 16px — all sides 16px
- margin: 8px 16px — top/bottom 8px, left/right 16px
- margin: 0 auto — center horizontally
- margin-top: 8px — only top margin
paddingSet space inside an element
Syntax
padding: <top> <right> <bottom> <left>Values
- padding: 16px — all sides 16px
- padding: 8px 16px — top/bottom 8px, left/right 16px
- padding: 4px 8px 12px 16px — individual sides
- padding-inline: 16px — left and right (logical)
borderSet border around an element
Syntax
border: <width> <style> <color>Values
- border: 1px solid #ccc — solid gray border
- border: 2px dashed red — dashed red border
- border-top: 1px solid — top border only
- border: none — remove border
box-sizingControl how width and height are calculated
Syntax
box-sizing: content-box | border-boxValues
- content-box — width excludes padding and border (default)
- border-box — width includes padding and border
width / heightSet the dimensions of an element
Syntax
width: <value>; height: <value>Values
- width: 100% — full width of parent
- width: 200px — fixed width
- max-width: 1200px — maximum width
- min-height: 100vh — minimum viewport height
- height: auto — height determined by content
overflowControl content that overflows element bounds
Syntax
overflow: visible | hidden | scroll | autoValues
- visible — content visible outside (default)
- hidden — overflow clipped
- scroll — always show scrollbar
- auto — show scrollbar when needed
- overflow-x: hidden — clip only horizontal overflow
font-sizeSet the size of the font
Syntax
font-size: <length> | <percentage> | keywordValues
- font-size: 16px — fixed size in pixels
- font-size: 1rem — relative to root font size
- font-size: 1.2em — relative to parent font size
- font-size: clamp(14px, 2vw, 18px) — responsive size
font-weightSet the weight (boldness) of the font
Syntax
font-weight: normal | bold | <number>Values
- 400 — normal weight
- 700 — bold weight
- 100–900 — numeric weights (100 lightest, 900 heaviest)
- normal — same as 400
- bold — same as 700
line-heightSet the height of a line of text
Syntax
line-height: normal | <number> | <length>Values
- 1.5 — 1.5× font-size (recommended for body text)
- 1 — same as font-size
- 24px — fixed line height
- normal — browser default (~1.2)
text-alignAlign inline content horizontally
Syntax
text-align: left | right | center | justifyValues
- left — align to left (default in LTR)
- right — align to right
- center — center alignment
- justify — justify text to both edges
text-decorationSet decorative lines on text
Syntax
text-decoration: none | underline | line-through | overlineValues
- none — remove decoration
- underline — underline text
- line-through — strikethrough text
- underline dotted — dotted underline
word-breakControl how words break at end of line
Syntax
word-break: normal | break-all | keep-all | break-wordValues
- normal — default word break rules
- break-all — break between any characters
- keep-all — don't break between CJK characters
- overflow-wrap: break-word — break only when necessary
positionSet how an element is positioned in the document
Syntax
position: static | relative | absolute | fixed | stickyValues
- static — default flow (default)
- relative — offset from normal position
- absolute — positioned relative to nearest positioned ancestor
- fixed — positioned relative to viewport
- sticky — switches between relative and fixed on scroll
displaySet the display behavior of an element
Syntax
display: block | inline | inline-block | none | ...Values
- block — full width, starts on new line
- inline — flows with text, no width/height
- inline-block — inline but accepts dimensions
- none — hide element (removes from layout)
- flex — flexbox container
- grid — grid container
z-indexSet the stack order of a positioned element
Syntax
z-index: auto | <integer>Values
- auto — same as parent (default)
- 0 — base stacking level
- 1 — above default stack
- -1 — below default stack
- 9999 — very high stack (use sparingly)
floatFloat an element to the left or right
Syntax
float: none | left | right | inline-start | inline-endValues
- none — not floated (default)
- left — float to the left
- right — float to the right
clearControl behavior next to floated elements
Syntax
clear: none | left | right | bothValues
- none — element can be next to floats (default)
- left — move below left floats
- right — move below right floats
- both — move below all floats
backgroundSet background color, image, or gradient
Syntax
background: <color> | url() | linear-gradient()Values
- background: #f0f0f0 — solid color
- background: url('img.png') center/cover — image
- background: linear-gradient(to right, #f00, #00f) — gradient
- background-color: transparent — transparent background
colorSet the color of text and foreground elements
Syntax
color: <color>Values
- color: #333 — dark gray hex
- color: rgb(51, 51, 51) — RGB value
- color: hsl(0, 0%, 20%) — HSL value
- color: oklch(0.3 0 0) — OKLCH value
- color: currentColor — inherit current color
opacitySet the transparency of an element
Syntax
opacity: <number between 0 and 1>Values
- 0 — fully transparent
- 0.5 — 50% transparent
- 1 — fully opaque (default)
box-shadowAdd shadow effect to an element
Syntax
box-shadow: <offset-x> <offset-y> <blur> <spread> <color>Values
- box-shadow: 0 2px 4px rgba(0,0,0,0.1) — subtle shadow
- box-shadow: 0 4px 16px rgba(0,0,0,0.2) — elevated shadow
- box-shadow: inset 0 1px 3px rgba(0,0,0,0.2) — inner shadow
- box-shadow: none — remove shadow
border-radiusRound the corners of an element
Syntax
border-radius: <length> | <percentage>Values
- border-radius: 4px — slightly rounded
- border-radius: 50% — circular (for square elements)
- border-radius: 8px 0 — top-left and bottom-right 8px
- border-top-left-radius: 8px — single corner
transformApply 2D/3D transformations to an element
Syntax
transform: <function>Values
- transform: translate(10px, 20px) — move element
- transform: rotate(45deg) — rotate by 45 degrees
- transform: scale(1.5) — scale to 1.5×
- transform: skew(10deg) — skew by 10 degrees
- transform: translateX(-50%) translateY(-50%) — center trick
transitionAnimate property changes smoothly
Syntax
transition: <property> <duration> <timing> <delay>Values
- transition: all 0.3s ease — animate all properties
- transition: color 0.2s ease-in-out — animate color only
- transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) — custom easing
- transition: none — disable transitions
animationApply keyframe animations to an element
Syntax
animation: <name> <duration> <timing> <delay> <iteration> <direction>Values
- animation: spin 1s linear infinite — infinite rotation
- animation: fade-in 0.5s ease forwards — fade in once
- animation-play-state: paused — pause animation
- @keyframes spin { to { transform: rotate(360deg); } } — define keyframe
About CSS Cheat Sheet
CSS Cheat Sheet is a reference collection of frequently used CSS properties and patterns. It covers everything from fundamental selectors and box model to modern layout techniques like Flexbox and Grid, typography, and visual effects. Each entry includes a description, syntax, and practical values to help you write CSS faster.
Key Features
- 48 essential CSS properties and patterns
- Syntax and value examples for each property
- Category filtering (Flexbox, Grid, Selectors, etc.)
- Real-time search functionality
- One-click copy of property names
Use Cases
- Quickly checking Flexbox or CSS Grid syntax while building a responsive layout
- Looking up available values for properties like display, position, or overflow
- Learning CSS fundamentals as a developer new to front-end development
- Referencing box model, spacing, and sizing properties during component styling
- Using as a quick reference in VS Code or alongside a React or Vue project
- Checking animation and transition syntax when adding motion to a UI
FAQ
What is the difference between Flexbox and Grid?
Flexbox is a one-dimensional layout method designed for laying out items in a single row or column. CSS Grid is a two-dimensional layout system that can handle both rows and columns simultaneously. Use Flexbox for component-level layout and Grid for page-level or complex two-dimensional layouts.
What is the difference between margin and padding?
Padding is the space inside an element, between the content and the border. Margin is the space outside an element, between the border and surrounding elements. Background color applies to padding but not to margin.
What is box-sizing: border-box?
By default (content-box), width and height only apply to the content area. With border-box, width and height include padding and border, making it easier to predict element sizes. Most modern CSS resets apply border-box to all elements.
When should I use position: absolute vs fixed?
absolute positioning places an element relative to its nearest positioned ancestor (an ancestor with position other than static). fixed positioning places an element relative to the viewport, so it stays in place when scrolling. Use fixed for sticky headers, modals, or floating buttons.
What is the difference between transition and animation?
transition animates a property change from one state to another, typically triggered by user interaction (like :hover). animation uses @keyframes to define multi-step animations that can run automatically, loop, or play in reverse. Use transition for simple state changes and animation for complex, autonomous motion.
