HTML & CSS ⚑ Recently updatedUpdated on Jun 30, 2026 β€” this content may still be evolving.

HTML & CSS: Revision Sheet

One-page rapid review. Read this the night before your interview.

Box Model

content β†’ padding β†’ border β†’ margin | Use box-sizing: border-box

Specificity (low β†’ high)

Element (1) < Class (10) < ID (100) < Inline (1000) | Avoid !important

Flexbox (1D layout)

Parent: display:flex, justify-content, align-items, gap, flex-wrap Child: flex: 1, align-self

Grid (2D layout)

display:grid, grid-template-columns: repeat(3, 1fr), gap, grid-template-areas

Flexbox vs Grid

  • Flexbox: navbar, card row, centering, 1D
  • Grid: page layout, card grid, dashboard, 2D

Positioning

  • relative β€” offset, still in flow
  • absolute β€” relative to positioned parent
  • fixed β€” viewport
  • sticky β€” scroll-based fixed

Responsive

<meta name="viewport" content="width=device-width, initial-scale=1.0">

Mobile-first: @media (min-width: 768px)

Semantic HTML

header, nav, main, article, section, footer β€” not div soup

Accessibility Quick Hits

  • alt on images
  • <label for="id"> on form inputs
  • <button> for actions, <a> for navigation
  • Don’t remove focus outlines
  • Color contrast 4.5:1 minimum

Centering

.parent { display: flex; justify-content: center; align-items: center; }
/* OR */
.parent { display: grid; place-items: center; }

Common Display Values

  • block β€” full width, new line
  • inline β€” no width/height
  • inline-block β€” width/height, flows with text
  • none β€” removed from layout

Pseudo-classes vs Pseudo-elements

  • :hover, :focus, :nth-child() β€” one colon
  • ::before, ::after β€” two colons

Script Loading

  • defer β€” after HTML parse, keeps order (preferred)
  • async β€” when ready, no order guarantee

CSS Variables

:root { --primary: #3498db; }
.btn { background: var(--primary); }

z-index

Only works within same stacking context. New context: positioned + z-index, opacity < 1, transform.

Quick Answers

QuestionAnswer
margin vs paddingmargin = outside border, padding = inside
em vs remem = parent relative, rem = root relative
id vs classid = unique, class = reusable
strong vs bstrong = semantic importance, b = visual only
display:none vs visibility:hiddennone = no space, hidden = takes space

Last check: Open your project, resize to mobile, and explain your layout choices out loud.