CSS Cheatsheet

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

Free Online CSS Cheatsheet

A searchable CSS quick reference covering selectors, layout, Flexbox, Grid, typography, colors, animations, and responsive design patterns. Copy any property with one click.

About this cheatsheet

A comprehensive CSS cheatsheet covering modern layout and styling techniques.

  • 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()

100% free. No signup required. No data collected or sent anywhere.

Explore All Tools