HTML and CSS Cheat Sheet

This sheet lists the HTML tags and CSS properties used on almost every website, grouped by job: document setup, semantic layout, text, lists, media, forms, selectors, units, layout and visual styling. Type in the filter to find one, open a mini demo to see it work, or press Print for a clean paper copy.

What is in the sheet
PartEntries
HTML43
CSS32
With a live demo10

Updated

Filter by keyword or switch between HTML and CSS, and the list narrows as you type. Entries with a demo open a small sandboxed preview. The print layout hides the controls and keeps each group's table together on the page.

Document

Document cheat sheet
Tag or propertySyntaxWhat it does
<!doctype html><!doctype html>First line of every page; turns on standards mode
<html><html lang="en">Root element; lang sets the page language
<head><head>...</head>Metadata, title, links to CSS and scripts
<meta><meta name="viewport" content="width=device-width, initial-scale=1">Charset, viewport, description and social tags
<link><link rel="stylesheet" href="styles.css">Connects stylesheets, icons and preloads
<script><script src="app.js" defer></script>Loads JavaScript; defer runs it after parsing

Semantic layout

Semantic layout cheat sheet
Tag or propertySyntaxWhat it does
<header><header>...</header>Intro or top bar of a page or section
<nav><nav aria-label="Main">...</nav>A block of major navigation links
<main><main>...</main>The unique main content; one per page
<section><section><h2>...</h2></section>A themed group of content, usually with a heading
<article><article>...</article>Self-contained content such as a post or product card
<aside><aside>...</aside>Related but secondary content, like a sidebar
<footer><footer>...</footer>Closing info: contact, legal, links
<details><details><summary>Q</summary>A</details>Native disclosure widget, no script needed
<dialog><dialog open>...</dialog>A modal or non-modal dialog box

Text

Text cheat sheet
Tag or propertySyntaxWhat it does
<h1> to <h6><h1>Title</h1>Headings in order; one h1 per page is the norm
<p><p>Text</p>A paragraph
<strong> / <em><strong>Important</strong> <em>stress</em>Strong importance and emphasis, bold and italic by default
<mark><mark>highlight</mark>Highlighted text
<code> / <pre><pre><code>...</code></pre>Inline code and preformatted blocks
<blockquote><blockquote cite="url">...</blockquote>An extended quotation
<abbr><abbr title="HyperText Markup Language">HTML</abbr>Abbreviation with its expansion
<time><time datetime="2026-10-14">Oct 14</time>A machine-readable date or time
<br> / <hr><br> <hr>Line break inside text; thematic break between blocks

Lists and tables

Lists and tables cheat sheet
Tag or propertySyntaxWhat it does
<ul> / <ol> / <li><ul><li>Item</li></ul>Unordered and ordered lists
<dl> / <dt> / <dd><dl><dt>Term</dt><dd>Definition</dd></dl>Description list of name and value pairs
<table><table><caption>..</caption><thead>..</thead><tbody>..</tbody></table>Tabular data with caption, head and body
<th scope><th scope="col">Price</th>Header cell; scope links it to its column or row

Media and links

Media and links cheat sheet
Tag or propertySyntaxWhat it does
<a><a href="/about">About</a>A link; add target and rel for new tabs
<img><img src="a.jpg" alt="..." width="800" height="600" loading="lazy">An image; alt, width and height are expected
<picture><picture><source srcset="a.avif" type="image/avif"><img ...></picture>Art direction and format fallbacks
<figure><figure><img ...><figcaption>..</figcaption></figure>Self-contained media with a caption
<video><video src="v.mp4" controls playsinline></video>Embedded video
<iframe><iframe src="..." title="..." loading="lazy"></iframe>Embeds another page
<svg><svg viewBox="0 0 24 24">...</svg>Inline vector graphics

Forms

Forms cheat sheet
Tag or propertySyntaxWhat it does
<form><form action="/subscribe" method="post">Wraps inputs and submits them
<label><label for="email">Email</label>Names a control; clicking it focuses the control
<input><input id="email" type="email" required>Text, email, number, date, checkbox, radio and more
<select><select><option>One</option></select>Dropdown list
<textarea><textarea rows="4"></textarea>Multi-line text input
<button><button type="submit">Send</button>A button; set type to avoid accidental submits
<fieldset> / <legend><fieldset><legend>Delivery</legend>...</fieldset>Groups related controls under a caption
Validation attributesrequired minlength="2" pattern="[0-9]{5}"Built-in checks before submit

Selectors

Selectors cheat sheet
Tag or propertySyntaxWhat it does
Type, class, IDp {} .card {} #top {}Element name, class and ID selectors
Descendant / child.nav a {} .nav > a {}Any depth versus direct children only
Siblingh2 + p {} h2 ~ p {}Next sibling, or any later sibling
Attributea[href^="https"] {}Matches by attribute presence or value
:hover / :focus-visiblea:hover {} button:focus-visible {}Pointer over and keyboard focus states
:nth-child()li:nth-child(odd) {}Picks items by position
:has() / :is() / :where().card:has(img) {}Parent matching and selector grouping
::before / ::after.req::after { content: " *" }Generated content before or after an element

Units

Units cheat sheet
Tag or propertySyntaxWhat it does
pxborder: 1px solidAbsolute CSS pixel
rem / emfont-size: 1.125remRelative to the root font size / to the element's font size
%width: 50%Relative to the parent (which dimension depends on the property)
vw / vh / dvhmin-height: 100dvhViewport units; dvh tracks mobile toolbars
chmax-width: 65chWidth of the 0 glyph, handy for line length
frgrid-template-columns: 1fr 2frShare of free space in a grid
clamp()font-size: clamp(1rem, 2.5vw, 2rem)Fluid value between a minimum and maximum

Box and layout

Box and layout cheat sheet
Tag or propertySyntaxWhat it does
box-sizing*, *::before, *::after { box-sizing: border-box }Width includes padding and border
margin / paddingmargin: 0 auto; padding: 1rem 2remSpace outside and inside the border
displaydisplay: block | inline | flex | grid | noneHow the box takes part in layout
Flexboxdisplay: flex; gap: 1rem; align-items: centerOne-dimensional rows or columns
Griddisplay: grid; grid-template-columns: repeat(3, 1fr)Two-dimensional rows and columns
positionposition: relative | absolute | fixed | stickyTakes a box out of, or pins it within, normal flow
z-indexz-index: 10Stacking order of positioned elements
overflowoverflow: autoWhat happens to content that does not fit
@media@media (min-width: 768px) { ... }Styles for a screen size or preference

Visual

Visual cheat sheet
Tag or propertySyntaxWhat it does
color / backgroundcolor: #111; background: #fffText colour and background
fontfont: 600 1rem/1.5 system-ui, sans-serifWeight, size, line height and family in one line
border / border-radiusborder: 1px solid #ddd; border-radius: 12pxOutline and rounded corners
box-shadowbox-shadow: 0 4px 12px rgb(0 0 0 / .15)Drop shadow around the box
opacityopacity: .5Transparency of the whole element
transformtransform: rotate(5deg) scale(1.05)Move, rotate, scale or skew without affecting layout
transitiontransition: transform 200ms easeAnimates changes between states
var()--brand: #4F98FB; color: var(--brand)Custom properties (CSS variables)

Everything together in one small page

Semantic markup plus a few lines of CSS

A header, main content with a form and a footer, styled with a handful of the properties from the sheet.

<style>
  *, *::before, *::after { box-sizing: border-box }
  body { font: 15px/1.5 system-ui, sans-serif; margin: 0 }
  header, footer { padding: 10px 14px; background: #0f172a; color: #fff }
  main { padding: 14px; max-width: 60ch }
  label { display: block; margin-bottom: 6px }
  input { padding: 8px; border: 1px solid #cbd5e1; border-radius: 8px; width: 100% }
  button { margin-top: 8px; padding: 8px 14px; border: 0; border-radius: 999px; background: #4F98FB; color: #fff }
</style>
<header><strong>Harbour Bakery</strong></header>
<main>
  <h1 style="margin: 0 0 8px; font-size: 20px">Join the bread list</h1>
  <form><label for="e">Email</label><input id="e" type="email" required><button type="submit">Subscribe</button></form>
</main>
<footer><small>Open daily from 7am</small></footer>

How HTML and CSS divide the work

HTML says what each piece of content is: a heading, a list, a form field, a navigation block. CSS says how it looks and where it goes. Keeping them separate means one stylesheet can restyle hundreds of pages and the markup stays readable to search engines and assistive tech.

When you are unsure which element to use, ask what the content would be called in a printed document. A list of steps is an ol, a set of facts is a dl or a table, a sidebar note is an aside.

Reading CSS rules

A rule is a selector, then braces holding property and value pairs separated by semicolons. When two rules target the same element, the more specific selector wins; if they tie, the one later in the stylesheet wins.

How it works

  1. Type a tag, property or task, for example table, sticky or email, into the filter box.
  2. Narrow to HTML or CSS with the buttons, or leave both on.
  3. Press Show demo on an entry to see it rendered, and Copy to grab the syntax.
  4. Press Print to get a paper or PDF copy without the page chrome.

Tips

Frequently asked questions

How many HTML tags are there?

The HTML Living Standard defines well over a hundred elements, but day-to-day pages use a few dozen. This sheet covers the ones you will meet on nearly every site; MDN keeps the complete element reference.

What is the difference between a tag and an element?

A tag is the markup you type, such as <p> or </p>. An element is the whole thing the browser builds from it: the start tag, its content and the end tag. Void elements like <img> and <br> have no end tag at all.

Can I print this cheat sheet?

Yes. The Print button opens your browser's print dialog with a layout that drops the filter, buttons and demos and keeps the syntax tables. Choose Save as PDF to keep a digital copy.

Should I learn CSS or a framework like Tailwind first?

Learn the CSS properties first. Utility frameworks are shorthand for them, so knowing that p-4 means padding: 1rem makes the framework easier, and debugging in developer tools always shows the underlying CSS.

Related: CSS selectors cheat sheet, Flexbox and grid cheat sheet, HTML boilerplate, CSS text styling, HTML accessibility checker, Modern CSS features.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Guides

We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.

Product

Who It's For

Features

Resources

Company

View Sitemap