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 flowabsoluteβ relative to positioned parentfixedβ viewportstickyβ 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
alton 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 lineinlineβ no width/heightinline-blockβ width/height, flows with textnoneβ 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
| Question | Answer |
|---|---|
| margin vs padding | margin = outside border, padding = inside |
| em vs rem | em = parent relative, rem = root relative |
| id vs class | id = unique, class = reusable |
| strong vs b | strong = semantic importance, b = visual only |
| display:none vs visibility:hidden | none = no space, hidden = takes space |
Last check: Open your project, resize to mobile, and explain your layout choices out loud.