Semantic HTML and SEO
Good HTML is not just markup — it is the contract between your content, search engines, assistive technologies, and the browser. Semantic HTML, correct metadata, and progressive enhancement make UI resilient, findable, and accessible by default.
Semantic HTML5
Use the element that describes the content's meaning, not just its appearance.
Document structure
Headings
One <h1> per page — the primary topic. Headings form an outline: do not skip levels (h1 → h3 without h2).
Interactive elements
Never use <div> or <span> as interactive elements without full ARIA annotation — and even then, prefer the native element.
Images and Alt Text
Every <img> needs an alt attribute. What goes in it depends on context.
SEO Fundamentals
Title and description
- Title: 50–60 characters. Most important keyword first.
- Description: 120–160 characters. Shown in search results — write for the human, not the algorithm.
Canonical URL
Prevents duplicate content penalties when the same page is accessible via multiple URLs.
Open Graph (social sharing)
OG image: 1200×630px. Appears when the URL is shared on Slack, LinkedIn, Twitter, iMessage.
The card's headline is the reader's phrase, not the article's insight. A feed supplies no context, so a line that needs the article to make sense reads as nonsense to a scrolling stranger. Put the plain promise they are already looking for on the card, in the vocabulary of the platform they are on, and keep the clever line for the page.
Adapt a card to a platform by mode, not by shade. Against a light feed a dark card reads as an ad banner; the fix is a light card on that platform's own ground, not a warmer navy or a softer blue. A hue nudge is invisible next to the platform's chrome and costs a round trip for nothing. Tone tweaks come after the mode is right.
Structured Data (JSON-LD)
Machine-readable content enables rich search results.
Common types: Product, Article, BreadcrumbList, FAQPage, Organization, SiteLinksSearchBox.
Progressive Enhancement
Build in layers. The core content and function must work without JavaScript. Enhance with CSS. Enhance further with JS.
In practice:
- Forms must submit via native
<form action>without JS — JS can intercept and enhance with fetch - Navigation links must be real
<a href>— JS can add transitions - Content must be in the HTML — JS can enhance with lazy-load or personalisation
- Images must have
src— JS can add lazy loading vialoading="lazy"(now native)
SPA Considerations
Single-page applications break browser defaults that SEO and accessibility depend on. Fix them explicitly.
Server-side rendering or static generation
Client-rendered HTML is not reliably indexed by search engines. Use SSR (Next.js, Nuxt, SvelteKit) or static generation for any content that needs to be found.
Title and meta updates
Update document.title and meta tags on every route change. Use the framework's <Head> component or equivalent.
Focus management
On route change, move focus to the new page's <h1> or <main> — screen readers do not detect SPA navigation automatically.
Scroll restoration
Restore scroll position to top on navigation, or to the saved position on back navigation. Browser default scroll restoration is disabled in SPAs.
History API
Use pushState / replaceState so back/forward navigation and bookmarking work correctly.
Device Capabilities and User Context
Design and code should adapt to what the device and user can actually do.
Client-side storage as a personalization tool
localStorage, sessionStorage, and other browser capabilities (cookies, IndexedDB, media/permission queries) are legitimate tools for tailoring the experience — last view mode, chosen locale, a dismissed banner, an in-progress draft, a returning user's context.
Guardrails:
- Personalise from real understanding, not a guess. What to persist and pre-fill safely usually needs customer testing — a wrong assumption in stored state is worse than a neutral default.
- Scope and consent.
sessionStoragefor one session,localStorageacross sessions; never store anything sensitive client-side; honour consent. - Re-validate every 2–3 years. Needs drift; a personalization that fit at launch becomes friction. Revisit, ideally with fresh testing.
Input method detection
Pointer precision
Pointer precision can select a default behaviour, not only target size. Read the same query from JavaScript with matchMedia('(pointer: fine)'), but use each event's pointerType when the interaction model differs: a click that toggles and a pointer that pans on a mouse, pinch and double tap on touch. Never infer input type from viewport width; hybrid devices break the guess. See [[modal-and-overlay-patterns]] for the image-zoom case.
Network conditions
User preferences
Review Checklist
- One
<h1>per page, headings form a logical outline - Semantic elements used:
<main>,<nav>,<header>,<footer>,<article>,<section> - Every
<img>has a meaningfulaltoralt=""for decorative images -
<title>is unique per page, 50–60 characters, keyword-first -
<meta name="description">present and 120–160 characters - Open Graph tags present on all shareable pages
-
<link rel="canonical">on pages accessible via multiple URLs - Structured data (JSON-LD) on product, article, and FAQ pages
- Forms work without JavaScript
- SPA updates
document.titleand meta tags on route change - SPA moves focus on route change
- Hover states scoped to
@media (hover: hover) - Touch targets ≥ 44px on
@media (pointer: coarse) - Images use
loading="lazy"below the fold -
prefers-reduced-motionrespected


