Reference

HTML, CSS & browser APIs

Look up semantic HTML, forms, CSS layout, events, DOM operations and common browser APIs.

Scope and conventions

Modern browser platform examples, independent of a framework. HTML/CSS excerpts belong in the appropriate document/style context; DOM snippets assume a browser and named elements/data; TypeScript annotations clarify DOM types and need compilation or removal in plain JavaScript. Check target-browser support for newer features.

Layout & responsive design

Include padding and borders in sizing deliberately

Web platform

With content-box, width describes the content box. border-box includes padding and border within the declared size; margins remain outside.

Fragment

Web platform · Include padding and borders in sizing deliberately
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
* { box-sizing: border-box; }
.card { width: 20rem; padding: 1rem; border: 1px solid; }

Choose units by their reference

Web platform

rem relates to root font size; em is context-dependent and commonly relates to an element/parent font size. Percentages depend on the property’s containing/reference box. dvh tracks dynamic viewport height.

Fragment

Web platform · Choose units by their reference
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
.page { max-width: 70rem; padding: 1rem; }
.panel { min-height: 50dvh; }

Viewport-unit and mobile-browser behavior varies; avoid locking all content into a height that cannot accommodate zoom/text growth.

Arrange items along one primary axis

Web platform

Flexbox distributes items along a main axis. gap adds spacing; alignment properties operate on axes. min-width:0 can let a flexible child shrink below its intrinsic content width.

Fragment

Web platform · Arrange items along one primary axis
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
.toolbar { display: flex; gap: .75rem; align-items: center; }
.toolbar .search { flex: 1; min-width: 0; }

Define tracks and prevent intrinsic overflow

Web platform

Grid lays out rows and columns. minmax(0,1fr) permits a track to shrink rather than preserving an oversized min-content minimum.

Fragment

Web platform · Define tracks and prevent intrinsic overflow
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
.layout {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  gap: 1rem;
}

Distinguish layout and positioning modes

Web platform

relative retains normal-flow space and establishes offsets. absolute leaves normal flow and uses its containing block. fixed and sticky have different containing/scroll relationships.

Fragment

Web platform · Distinguish layout and positioning modes
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
.card { position: relative; }
.badge { position: absolute; inset-block-start: .5rem; inset-inline-end: .5rem; }
.toolbar { position: sticky; top: 0; }

Transforms and other properties can establish containing blocks/stacking contexts. Sticky positioning depends on scroll containers and available space.

Reason within stacking contexts

Web platform

z-index orders participating boxes within their stacking context; it cannot universally lift a child above an unrelated ancestor context. Opacity, transforms, isolation and other features can create contexts.

Fragment

Web platform · Reason within stacking contexts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
.panel { isolation: isolate; }
.panel .overlay { position: absolute; z-index: 2; }

Native dialog/popover top-layer behavior is distinct from ordinary z-index ordering.

Adapt to viewport or container size

Web platform

Media queries test the environment/viewport. Container queries can test a declared query container’s size, letting a component adapt to its allocated space.

Fragment

Web platform · Adapt to viewport or container size
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
.cards { display: grid; grid-template-columns: 1fr; }
@media (min-width: 48rem) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.host { container-type: inline-size; }
@container (min-width: 30rem) {
  .card { display: flex; }
}