Cheatsheets

CSS Cheatsheet

Use this CSS cheatsheet for fast reminders on selectors, flexbox, grid, spacing, radius, shadows, gradients, media queries and responsive styling patterns you can copy into real interfaces.

Quick reference

Selectors

Class.card

Targets elements with class="card".

ID#main

Targets one element with id="main".

Child.nav > a

Direct child selector.

Attributeinput[type="email"]

Targets elements by attribute.

Layout

Flex rowdisplay: flex;
Griddisplay: grid;
Gapgap: 1rem;
Responsive maxwidth: min(100%, 72rem);

Responsive

Media query@media (max-width: 768px) { ... }
Fluid typefont-size: clamp(1rem, 2vw, 2rem);
Aspect ratioaspect-ratio: 16 / 9;
Container fitmax-width: 100%;

Visual patterns

Compare the syntax with a small rendered example so the reference is easier to scan and remember.

Flexbox alignment

Use flexbox for one-dimensional layouts such as navbars, toolbars and button rows.

Generated CSSGenerated CSS
.nav {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
HTMLHTML
<div class="nav">
  <span>Logo</span>
  <span>Docs</span>
  <strong>Start</strong>
</div>
Live preview
Direction
LogoDocsStart
Responsive grid

Use grid when rows and columns both matter.

Generated CSSGenerated CSS
.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, auto);
  gap: 16px;
}
HTMLHTML
<div class="cards">
  <article>One</article>
  <article>Two</article>
  <article>Three</article>
</div>
Live preview
Spacing and radius

Padding creates breathing room; border-radius softens the container.

Generated CSSGenerated CSS
.panel {
  padding: 16px;
  border-radius: 18px;
}
HTMLHTML
<div class="panel">Content</div>
Live preview
spacing
panel
Shadows and gradients

Layer subtle shadows with a controlled gradient for depth.

Generated CSSGenerated CSS
.card {
  background: linear-gradient(135deg, #2563eb, #14b8a6);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
}
HTMLHTML
<div class="card">
  <strong>Gradient card</strong>
  <p>Shadow, radius and layered color.</p>
</div>
Live preview
Gradient card

Shadow, radius and layered color.

Media query

Change layout rules at practical breakpoints.

Generated CSSGenerated CSS
@media (max-width: 640px) {
  .cards {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}
HTMLHTML
<div class="cards">
  <article>Desktop column</article>
  <article>Mobile stack</article>
</div>
Live preview
Desktop: 3 columnsMobile: 1 column

Learn the pattern

Short notes to help you decide when to use each pattern, avoid common mistakes and copy the examples with confidence.

When to use

  • Use flexbox for one-dimensional rows or columns.
  • Use grid when columns and rows both matter.
  • Use media queries when layout needs to change at a breakpoint.

Quick tips

  • Start with normal document flow before adding layout rules.
  • Use gap for spacing inside flex and grid containers.
  • Prefer rem, %, min(), max() and clamp() for responsive sizing.

Common mistakes

  • Using fixed pixel widths that overflow small screens.
  • Adding margins to every child instead of using gap.
  • Hiding focus styles while styling links and buttons.

Best practices

  • Keep layout rules close to the component they affect.
  • Use predictable tokens for spacing, radius and shadows.
  • Test keyboard focus and narrow mobile widths before shipping.

Examples

CodeResponsive card grid
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}
CodeAccessible focus style
a:focus-visible,
button:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 3px;
}

CSS FAQ

What is included in the CSS cheatsheet?

CSS Cheatsheet includes quick reference sections, practical examples, common mistakes, tips and links to related DevKitYard tools.

Is the CSS cheatsheet interactive?

Yes. This cheatsheet includes visual examples with copyable code and lightweight controls where interaction helps explain the pattern.

When should I use this CSS reference?

Use it when you need to recall syntax, compare common patterns or avoid mistakes without opening a long tutorial.

What should I use after reading this cheatsheet?

Use related DevKitYard tools such as CSS Gradient Generator, CSS Beautifier, Flexbox Generator when you need to format, validate, generate or inspect real output.