HTML & CSS Cheat Sheet

Free HTML/CSS cheat sheet: document structure, CSS selectors, Flexbox, Grid, and responsive design at a glance.

HTML Structure

ConceptSyntaxExample
Document skeleton<!DOCTYPE html><html><head></head><body></body></html>Every HTML page starts with this structure
Heading<h1> to <h6><h1>Main Title</h1>
Paragraph<p><p>Some text here</p>
Link<a href="url"><a href="/about">About</a>
Image<img src="" alt=""><img src="logo.png" alt="Logo">

CSS Selectors

ConceptSyntaxExample
Class selector.classname.btn { color: red; }
ID selector#idname#header { height: 60px; }
Child selectorparent > childul > li { margin: 0; }
Pseudo-class:hover, :focus, :nth-child()a:hover { color: blue; }

CSS Layout

ConceptSyntaxExample
Flexbox containerdisplay: flex.row { display: flex; gap: 1rem; }
Grid containerdisplay: grid.grid { display: grid; grid-template-columns: 1fr 1fr; }
Positionposition: relative | absolute | fixed | sticky.modal { position: fixed; top: 0; }

Responsive Design

ConceptSyntaxExample
Media query@media (max-width: 768px) {}@media (max-width: 768px) { .col { width: 100%; } }
Viewport meta<meta name="viewport" content="width=device-width, initial-scale=1">Add to <head> for mobile support
Relative unitsrem, em, %, vw, vhfont-size: 1.2rem; width: 80%;