devtools logo
by Ryan Macalandag
Back to cheatsheets
Cheatsheetshtmlreferencecheatsheet

HTML Cheatsheet

Quick reference for HTML tags, attributes, and structure.

Document structure

Every HTML document follows the same skeleton. The doctype must come first, followed by a single root html element containing exactly one head and one body.

<!DOCTYPE html>always first, case-insensitive
<html lang="en">
<head>
<meta charset="utf-8">
<title>Page title</title>
</head>
<body>
<!-- visible content -->
</body>
</html>
Minimum required structure of an HTML document.

Metadata & head

Tags inside <head> describe the document rather than render visible content.

Tag / attributePurpose
meta charset="utf-8"Character encoding — should be the first tag in head.
meta name="viewport"width=device-width, initial-scale=1 for responsive layouts.
meta name="description"Search engine snippet text, ~150–160 characters.
link rel="canonical"Points search engines to the preferred URL for duplicate content.
meta property="og:*"Open Graph tags controlling social share previews (title, image, description).
link rel="icon"Favicon reference — see the Favicon Package Generator for a full set.

Text content

Use the most specific element available rather than styling a generic div or span.

ElementUse for
h1–h6Document outline. One h1 per page; never skip levels for styling reasons.
pParagraphs of text.
ul / ol / liUnordered and ordered lists.
strong / emSemantic importance and emphasis (not just bold/italic styling).
blockquote / citeQuoted content and its source.
code / preInline code and preformatted code blocks.
abbrAbbreviations, with a title attribute for the expansion.

Semantic elements

Semantic landmarks give assistive technology and search engines a reliable outline of the page.

ElementRepresents
headerIntroductory content for a page or section (often a logo + nav).
navA block of primary navigation links.
mainThe dominant content of the document. Exactly one per page.
articleSelf-contained, independently distributable content (a post, a card).
sectionA thematic grouping of content, usually with its own heading.
asideContent tangentially related to the main content (sidebars, pull quotes).
footerFooter for its nearest sectioning ancestor.

Forms & inputs

Every form control needs a programmatic label. Prefer wrapping or a matching for/id pair over placeholder-only labeling.

Input type / elementUse for
input type="email"Email addresses — brings up an email keyboard on mobile.
input type="tel"Phone numbers — numeric keypad on mobile, no format enforcement.
input type="number"Numeric values with spinners. Use inputmode for numeric-only text.
select / optionChoosing one value from a short, known list.
textareaMulti-line free text.
fieldset / legendGroups related controls (e.g. a radio button set) with a shared label.
required, pattern, minlengthBuilt-in client-side validation attributes.

Media & embeds

Element / attributeUse for
img alt=""Images. alt is required — use an empty string for purely decorative images.
picture / sourceResponsive images: different files per viewport or format.
video / audioNative media playback with controls, autoplay, loop, muted.
track kind="captions"Captions/subtitles for a video element.
iframeEmbedding another document. Always set a descriptive title.

Global attributes

These work on virtually every HTML element, regardless of tag.

AttributePurpose
idUnique identifier, used by CSS, JS, and anchor links.
classOne or more style/behavior hooks, space-separated.
data-*Custom data attributes for scripting, e.g. data-state.
hiddenRemoves the element from rendering and the accessibility tree.
tabindex0 adds an element to natural tab order; -1 makes it focusable via script only.
contenteditableMakes an element's content directly editable by the user.

Accessibility basics

Reach for semantic HTML first — it comes with accessibility built in. Use ARIA only to patch gaps semantic elements can't cover.

  • Every interactive control needs an accessible name (visible label, aria-label, or aria-labelledby).
  • Use alt on images, not aria-label — alt is the correct, universally supported mechanism.
  • aria-live="polite" announces dynamic content updates (toasts, form errors) without stealing focus.
  • Never remove focus outlines without providing a visible replacement.
  • Check color contrast: 4.5:1 for normal text, 3:1 for large text, per WCAG AA.

Spot an error or have a suggestion? Open an issue on GitHub.