ToolHop.

ADVERT

๐ŸŽจ CSS Cheatsheet

Quick CSS reference for selectors, box model utilities, flexbox, grid, and responsive typography patterns.

Modern CSS snippets that cover selectors, layout primitives, and responsive typography. Ship resilient UI foundations without digging through docs.

Selectors

Target elements precisely with modern selectors.

SelectorMatchesUsage
.cardClass selectorAttach reusable styles to semantic classes.
#heroID selectorUse sparingly for unique anchors or JS hooks.
button:hoverPseudo-classDesign interactive states (hover, focus-visible, active).
nav a:nth-of-type(2)Nth-child familyTarget patterned elements without extra markup.
[data-theme="dark"]Attribute selectorGreat for theming, feature flags, or QA hooks.

Box Model Essentials

Control spacing, intrinsic sizing, and media fit.

SelectorMatchesUsage
box-sizing: border-box;Sizing modelInclude padding/borders within declared width/height.
margin-inline / margin-blockLogical propertiesRespect writing modes and RTL layouts automatically.
aspect-ratio: 16 / 9;Aspect ratioReserve responsive media slots without hacks.
object-fit: cover;Media croppingFill containers without stretching images/videos.

Flexbox

Layout one-dimensional flows with ease.

Container

display: flex; gap: 1rem; align-items: center;

display: flex;
gap: 1rem;
align-items: center;
  • justify-content
  • align-items
  • flex-wrap

Axis control

flex-direction switches between rows and columns.

  • row
  • row-reverse
  • column
  • column-reverse

Flex children

flex: 1; grows, flex: 0; stays true to content width.

  • flex
  • flex-basis
  • align-self

Gap vs margin

Use gap for consistent spacing without collapsing margins.

  • gap
  • column-gap
  • row-gap

CSS Grid

Powerful two-dimensional layouts in a few lines.

Auto-fit grid

grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));

display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 1.5rem;

Named areas

grid-template-areas with area assignments simplify layouts.

grid-template-areas: "nav nav" "sidebar main";

Responsive clamp

clamp() typography works beautifully with grid minmax().

font-size: clamp(1rem, 1.5vw, 1.25rem);

Alignment

Use place-items or place-content to center both axes.

place-items: center;

Typography & Responsiveness

Scale text and color systems intelligently.

  • Fluid typography

    font-size: clamp(1rem, 2vw + 0.5rem, 1.5rem);

  • Variable fonts

    font-variation-settings: 'wght' 600;

  • System stack

    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  • Color contrast

    prefers-color-scheme queries plus custom properties keep palettes accessible.

  • Container queries

    @container (inline-size > 600px) { ... } scales components instead of pages.

ADVERT

ADVERT

CSS Cheatsheet - Selectors, Flexbox, Grid & Responsive Tips