html-standards

HTML Standards & Best Practices

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "html-standards" with this command: npx skills add devbyray/github-copilot-starter/devbyray-github-copilot-starter-html-standards

HTML Standards & Best Practices

Apply these standards when writing HTML markup to ensure accessibility, semantics, maintainability, and security.

Structure & Semantics

  1. Use Semantic HTML Elements

Prefer semantic elements over generic divs and spans:

Good:

<header> <nav> <ul> <li><a href="/">Home</a></li> </ul> </nav> </header>

<main> <article> <h2>Article Title</h2> <section> <p>Content...</p> </section> </article>

&#x3C;aside>
	&#x3C;h3>Related Links&#x3C;/h3>
&#x3C;/aside>

</main>

<footer> <p>&copy; 2026 Company Name</p> </footer>

Bad:

<div class="header"> <div class="nav">...</div> </div>

<div class="main"> <div class="article">...</div> </div>

  1. Document Structure

Always use proper HTML5 document structure:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Page Title</title> </head> <body> <!-- Content --> </body> </html>

  1. Heading Hierarchy
  • Use headings in logical order (H2, H3, H4, etc.)

  • Do NOT use <h1> (reserved for page title generation)

  • Don't skip heading levels

Good:

<h2>Main Section</h2> <h3>Subsection</h3> <h4>Detail</h4>

Bad:

<h1>Title</h1> <!-- Don't use H1 --> <h4>Content</h4> <!-- Skipped H2, H3 -->

  1. Code Organization
  • Indent nested elements consistently (2 spaces)

  • Use blank lines to separate logical sections

  • Keep lines readable (max 120 characters)

Accessibility

  1. Images

All images must have descriptive alt text:

<!-- Informative image --> <img src="chart.png" alt="Sales chart showing 20% increase in Q4 2025" />

<!-- Decorative image --> <img src="divider.png" alt="" />

  1. Forms

Always label form controls:

<form> <label for="email">Email address</label> <input type="email" id="email" name="email" required />

&#x3C;label for="password">Password&#x3C;/label>
&#x3C;input type="password" id="password" name="password" required />

&#x3C;button type="submit">Submit&#x3C;/button>

</form>

  1. Keyboard Navigation

Ensure interactive elements are keyboard accessible:

<button type="button">Clickable Button</button> <a href="/page">Link to Page</a>

<!-- Only use tabindex="0" for custom interactive elements --> <div role="button" tabindex="0" onclick="handleClick()">Custom Button</div>

  1. ARIA Attributes

Use ARIA only when native HTML is insufficient:

<!-- Good: Native HTML --> <button>Click me</button>

<!-- OK: ARIA when needed --> <button aria-label="Close dialog">×</button>

<!-- Good: ARIA for custom widgets --> <div role="dialog" aria-labelledby="dialog-title" aria-modal="true"> <h2 id="dialog-title">Dialog Title</h2> </div>

Maintainability

  1. Avoid Inline Styles and Scripts

Keep HTML clean by using external files:

Bad:

<div style="color: red; font-size: 20px;" onclick="alert('clicked')">Content</div>

Good:

<div class="error-text" data-action="show-alert">Content</div>

  1. Consistent Naming

Use lowercase, hyphen-separated names:

<div class="main-header"></div> <nav class="site-navigation"></nav> <button id="submit-button">Submit</button>

  1. Code Comments

Use comments to organize sections:

<!-- Header Section --> <header> <!-- Navigation --> <nav>...</nav> </header>

<!-- Main Content --> <main>...</main>

Security

  1. Escape User-Generated Content

Never inject raw user data into the DOM:

Bad (XSS vulnerability):

element.innerHTML = userInput

Good:

element.textContent = userInput // OR use DOMPurify for HTML element.innerHTML = DOMPurify.sanitize(userInput)

  1. Security Meta Tags

Include security headers:

<head> <meta charset="UTF-8" /> <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'" /> <meta http-equiv="X-Content-Type-Options" content="nosniff" /> <meta http-equiv="Strict-Transport-Security" content="max-age=31536000; includeSubDomains" /> </head>

Performance

  1. Optimize Images

<!-- Modern formats with fallback --> <picture> <source srcset="image.webp" type="image/webp" /> <source srcset="image.jpg" type="image/jpeg" /> <img src="image.jpg" alt="Description" loading="lazy" /> </picture>

<!-- Lazy loading for non-critical images --> <img src="image.jpg" alt="Description" loading="lazy" />

  1. Resource Hints

Use preload and prefetch for critical resources:

<head> <!-- Preload critical CSS --> <link rel="preload" href="critical.css" as="style" />

&#x3C;!-- Prefetch next page -->
&#x3C;link rel="prefetch" href="/next-page" />

&#x3C;!-- DNS prefetch for external domains -->
&#x3C;link rel="dns-prefetch" href="https://api.example.com" />

</head>

Complete Example

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="description" content="Brief page description for SEO" /> <meta http-equiv="Content-Security-Policy" content="default-src 'self'" />

	&#x3C;title>Page Title - Site Name&#x3C;/title>

	&#x3C;link rel="preload" href="styles.css" as="style" />
	&#x3C;link rel="stylesheet" href="styles.css" />
&#x3C;/head>
&#x3C;body>
	&#x3C;!-- Header -->
	&#x3C;header class="site-header">
		&#x3C;nav class="main-navigation" aria-label="Main navigation">
			&#x3C;ul>
				&#x3C;li>&#x3C;a href="/" aria-current="page">Home&#x3C;/a>&#x3C;/li>
				&#x3C;li>&#x3C;a href="/about">About&#x3C;/a>&#x3C;/li>
				&#x3C;li>&#x3C;a href="/contact">Contact&#x3C;/a>&#x3C;/li>
			&#x3C;/ul>
		&#x3C;/nav>
	&#x3C;/header>

	&#x3C;!-- Main Content -->
	&#x3C;main id="main-content">
		&#x3C;article>
			&#x3C;h2>Article Title&#x3C;/h2>

			&#x3C;section>
				&#x3C;h3>Section Heading&#x3C;/h3>
				&#x3C;p>Content paragraph with &#x3C;a href="/link">descriptive link text&#x3C;/a>.&#x3C;/p>

				&#x3C;img src="image.jpg" alt="Detailed description of the image" loading="lazy" />
			&#x3C;/section>

			&#x3C;section>
				&#x3C;h3>Form Section&#x3C;/h3>
				&#x3C;form action="/submit" method="post">
					&#x3C;label for="name">Full Name&#x3C;/label>
					&#x3C;input type="text" id="name" name="name" required />

					&#x3C;label for="email">Email Address&#x3C;/label>
					&#x3C;input type="email" id="email" name="email" required />

					&#x3C;button type="submit">Send&#x3C;/button>
				&#x3C;/form>
			&#x3C;/section>
		&#x3C;/article>

		&#x3C;aside class="sidebar">
			&#x3C;h3>Related Content&#x3C;/h3>
			&#x3C;ul>
				&#x3C;li>&#x3C;a href="/related-1">Related Article 1&#x3C;/a>&#x3C;/li>
				&#x3C;li>&#x3C;a href="/related-2">Related Article 2&#x3C;/a>&#x3C;/li>
			&#x3C;/ul>
		&#x3C;/aside>
	&#x3C;/main>

	&#x3C;!-- Footer -->
	&#x3C;footer class="site-footer">
		&#x3C;p>&#x26;copy; 2026 Company Name. All rights reserved.&#x3C;/p>
	&#x3C;/footer>

	&#x3C;script src="app.js" defer>&#x3C;/script>
&#x3C;/body>

</html>

Validation

Tools

  • W3C Markup Validator

  • Browser DevTools accessibility audits

  • axe DevTools

Checklist

  • ✅ Valid HTML5 structure

  • ✅ Proper DOCTYPE and language attribute

  • ✅ Semantic elements used appropriately

  • ✅ No H1 in content (reserved for page title)

  • ✅ All images have alt text

  • ✅ Forms have proper labels

  • ✅ Keyboard navigation works

  • ✅ Security meta tags included

  • ✅ External CSS/JS files used

  • ✅ Consistent naming conventions

When to Apply

Apply these standards when:

  • Creating HTML pages

  • Building templates

  • Writing component markup

  • Reviewing HTML code

  • User asks about HTML best practices

  • Working with any HTML-based template engine

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

markdown-standards

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

css-standards

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

javascript-typescript-standards

No summary provided by upstream source.

Repository SourceNeeds Review