Skip to content

CSS Cheat Sheet — Complete Reference (70+ properties, 2026)

Last verified May 2026 — runs in your browser
CSS Cheatsheet
.class

Class selector

Selectors
#id

ID selector

Selectors
element

Type/tag selector

Selectors
parent > child

Direct child combinator

Selectors
ancestor descendant

Descendant combinator

Selectors
el + sibling

Adjacent sibling combinator

Selectors
el ~ siblings

General sibling combinator

Selectors
[attr="value"]

Attribute selector (exact match)

Selectors
:hover / :focus / :active

Interactive pseudo-classes

Selectors
:first-child / :last-child

First/last child pseudo-class

Selectors
:nth-child(2n)

Every even child

Selectors
::before / ::after

Pseudo-elements (generated content)

Selectors
:not(.class)

Negation pseudo-class

Selectors
:has(.child)

Parent selector (contains child)

Selectors
:is(h1, h2, h3)

Matches any in list

Selectors
display: block | inline | inline-block | none

Display mode

Layout
position: static | relative | absolute | fixed | sticky

Positioning scheme

Layout
top / right / bottom / left

Offset for positioned elements

Layout
z-index: 10

Stack order (higher = on top)

Layout
overflow: hidden | scroll | auto

Handle overflowing content

Layout
box-sizing: border-box

Include padding/border in size

Layout
margin: 0 auto

Center block element horizontally

Layout
width / height / min-width / max-width

Size constraints

Layout
float: left | right | none

Float element (legacy layout)

Layout
display: flex

Enable flexbox on container

Flexbox
flex-direction: row | column

Main axis direction

Flexbox
justify-content: center | space-between | space-around

Align items along main axis

Flexbox
align-items: center | stretch | flex-start | flex-end

Align items along cross axis

Flexbox
flex-wrap: wrap

Allow items to wrap to next line

Flexbox
gap: 1rem

Space between flex/grid items

Flexbox
flex: 1

Flex grow (fill available space)

Flexbox
flex: 0 0 200px

Fixed width flex item (no grow/shrink)

Flexbox
align-self: center

Override align-items for one item

Flexbox
order: -1

Change visual order of item

Flexbox
display: grid

Enable CSS Grid on container

Grid
grid-template-columns: 1fr 2fr 1fr

Define column sizes (fractions)

Grid
grid-template-columns: repeat(3, 1fr)

Repeat column pattern

Grid
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr))

Responsive auto-fill grid

Grid
grid-template-rows: auto 1fr auto

Define row sizes

Grid
grid-column: 1 / 3

Span item across columns

Grid
grid-row: 1 / -1

Span item across all rows

Grid
place-items: center

Center items both axes (shorthand)

Grid
grid-template-areas: "header header" "sidebar main" "footer footer"

Named grid areas

Grid
font-family: 'Inter', sans-serif

Font stack with fallback

Typography
font-size: 1rem | 16px | clamp(1rem, 2vw, 2rem)

Font size (responsive with clamp)

Typography
font-weight: 400 | 700 | bold

Font weight

Typography
line-height: 1.5

Line spacing (unitless ratio)

Typography
letter-spacing: 0.05em

Space between characters

Typography
text-align: left | center | right | justify

Text alignment

Typography
text-decoration: underline | line-through | none

Text decoration

Typography
text-transform: uppercase | lowercase | capitalize

Text case transform

Typography
white-space: nowrap

Prevent text wrapping

Typography
text-overflow: ellipsis

Truncate overflow with ...

Typography
color: #ff6600 | rgb(255, 102, 0) | hsl(24, 100%, 50%)

Text color (hex/rgb/hsl)

Colors
background-color: var(--bg)

Background color (CSS variable)

Colors
background: linear-gradient(to right, #f00, #00f)

Linear gradient background

Colors
opacity: 0.5

Element transparency (0-1)

Colors
box-shadow: 0 4px 6px rgba(0,0,0,0.1)

Box shadow

Colors
border: 1px solid #ccc

Border shorthand

Colors
border-radius: 0.5rem | 50%

Rounded corners (50% = circle)

Colors
outline: 2px solid blue

Outline (doesn't affect layout)

Colors
transition: all 0.3s ease

Smooth property transitions

Animations
transition: transform 0.2s, opacity 0.2s

Transition specific properties

Animations
transform: translateX(10px)

Move element

Animations
transform: scale(1.1) rotate(5deg)

Scale and rotate

Animations
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

Define keyframe animation

Animations
animation: fade 0.3s ease-in forwards

Apply animation

Animations
will-change: transform

Hint browser for optimization

Animations
@media (max-width: 768px) { ... }

Mobile-first breakpoint

Responsive
@media (min-width: 1024px) { ... }

Desktop breakpoint

Responsive
@media (prefers-color-scheme: dark) { ... }

Dark mode media query

Responsive
@media (prefers-reduced-motion: reduce) { ... }

Reduce animations for accessibility

Responsive
@container (min-width: 400px) { ... }

Container query

Responsive
clamp(1rem, 3vw, 2rem)

Fluid sizing (min, preferred, max)

Responsive
Showing 74 of 74 properties

CSS Cheat Sheet — Flexbox, Grid, Selectors & Pseudo-Classes Reference

CSS has grown from styling text in 1996 to driving the entire layout layer of modern browsers, and the parts that bite have shifted with it. The cheatsheet below covers 70+ properties across selectors, layout, Flexbox, Grid, typography, colors, animations, and responsive design. Most trouble in real stylesheets does not come from forgetting properties. It comes from quirks that look obvious alone but unravel inside a cascade. An `#id` selector beats any number of class selectors on the same element because specificity weights id above class, so a single id rule in a global stylesheet pins a colour no `.theme-dark` override will dislodge. `z-index` only takes effect on a positioned element (or a flex/grid child with explicit z-index), so `z-index: 9999` on `position: static` does nothing at all. A `margin-top` on the first child of a parent without padding or a border collapses up into the parent and pushes the parent down instead. These are the snippets pulled up while debugging that — the right selector, the right `box-sizing`, the right media query — without rereading the spec from line one each time.

Common pitfalls in CSS

A few rules earn their place near the top of any modern stylesheet. `box-sizing: border-box` applied with a `*` reset keeps `width: 300px` meaning exactly 300px on screen instead of 300px plus whatever padding and border later add — the default `content-box` model is the cause of more layout drift than any other single property. Specificity is read as four columns, not a single number: inline styles outrank ids, ids outrank classes and attributes, classes outrank type selectors, and within the same weight the last rule wins. The `:has()` selector finally provides a real parent match (`article:has(> img)`) and rewrites whole patterns that previously needed JavaScript. Grid and Flexbox stop nesting cleanly when an intermediate `display: contents` element interrupts the chain or when a child has `min-width: auto` (the default), which lets flex items overflow their container in subtle ways. The cheatsheet groups all of this into Selectors, Layout, Flexbox, Grid, Typography, Colors, Animations, and Responsive so the right section is one click away.

  • 70+ CSS properties and patterns
  • 8 categories including Flexbox and Grid
  • Modern selectors (:has, :is, :not)
  • Responsive design patterns
  • One-click copy to clipboard
  • Container queries and clamp()

Free. No signup. Your inputs stay in your browser. Ads via Google AdSense (consent required).