AiredFree learning since 2009

HTML Code Snippets You Can Copy and Use

Six copy-ready HTML snippets for everyday tasks. Each one follows current accessibility and SEO best practice. Use the copy button on any block.

Semantic page skeleton

A clean HTML5 starting point with landmarks that help SEO and screen readers.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Page title | Site name</title>
  <meta name="description" content="One-sentence summary of the page.">
</head>
<body>
  <header>…</header>
  <main id="main">
    <h1>Main heading</h1>
  </main>
  <footer>…</footer>
</body>
</html>

Accessible form field

Every input needs a visible label linked with for/id, plus helpful hint text.

<label for="email">Email address</label>
<input id="email" name="email" type="email" autocomplete="email"
       required aria-describedby="email-hint">
<p id="email-hint">We never share your email.</p>

Responsive image

Serve the right size for each screen and lazy-load images below the fold.

<img src="photo-800.jpg"
     srcset="photo-400.jpg 400w, photo-800.jpg 800w, photo-1600.jpg 1600w"
     sizes="(max-width: 600px) 100vw, 800px"
     width="800" height="533" loading="lazy" alt="Team at a whiteboard">

Native accordion (no JavaScript)

The details/summary pair gives you an accessible accordion for free.

<details>
  <summary>What is semantic HTML?</summary>
  <p>Using elements for their meaning — header, nav, main,
     article — instead of generic divs.</p>
</details>

Data table with caption

Use th with scope so assistive technology can read rows and columns correctly.

<table>
  <caption>Cloud storage pricing (example)</caption>
  <thead>
    <tr><th scope="col">Plan</th><th scope="col">Storage</th><th scope="col">Price</th></tr>
  </thead>
  <tbody>
    <tr><th scope="row">Starter</th><td>50 GB</td><td>Free</td></tr>
    <tr><th scope="row">Pro</th><td>1 TB</td><td>₹199/month</td></tr>
  </tbody>
</table>

Open Graph tags for sharing

Control how your page looks when shared on WhatsApp, LinkedIn and X.

<meta property="og:title" content="HTML Code Snippets">
<meta property="og:description" content="Copy-ready HTML for everyday tasks.">
<meta property="og:image" content="https://www.example.com/og/html.png">
<meta property="og:url" content="https://www.example.com/html-snippets">
<meta name="twitter:card" content="summary_large_image">

Bonus: the same idea in CSS and JavaScript

Syntax colours work for many languages — set the language on the code block.

/* Visually hidden but readable by screen readers */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
// Copy text to the clipboard
async function copy(text) {
  await navigator.clipboard.writeText(text);
  console.log("Copied!");
}

Written by

Admin

Tech Enthusiast | Blogger | Investor · Aired India

Real Estate. Crypto, Web3 Marketing. Business Growth. Audience Building. DM for Marketing Campaigns.

View profile

Comments 0

No comments yet. Be the first to share a tip.

Comments are moderated before they appear. Comments with links are removed automatically. Max 600 characters.