A complete guide to modern HTML best practices, including syntax rules, semantic elements, accessibility tips, SEO guidelines, and clean code formatting — based on W3Schools + professional standards.
- Introduction
- General Syntax Rules
- HTML Elements
- Attributes
- Boolean Attributes
- Quotations
- HTML Comments
- HTML Head Best Practices
- File Structure & Naming
- Code Formatting Tips
- Avoid Deprecated Tags
- Wrap Block Elements Correctly
- Keep CSS & JS External
- Validate HTML
- Accessibility Tips
- SEO Best Practices
- Performance Tips
- Summary Table
This document provides clean, modern best practices for writing HTML.
It expands on the guidelines from W3Schools and adds professional
standards used in production websites.
<p>This is correct</p>
<P>This is NOT recommended</P><br>
<img src="img.jpg" alt="Description">Use 2 or 4 spaces, but never tabs.
VSCode can automatically insert spaces when you press the Tab key.
Correct:
<p><strong>Important text</strong></p>Incorrect:
<p><strong>Important text</p></strong>Use semantic tags such as <header>, <main>, <footer>, <nav>, <section>, <article>, <aside>.
Read more: Stop Using <div> Everywhere
<a href="page.html">Link</a><input type="text" value="John"><img src="cat.jpg" alt="A cute cat">Correct:
<input type="checkbox" checked>Avoid:
<input type="checkbox" checked="checked">Use double quotes for attributes.
✔ Recommended:
<input type="text" placeholder="Enter name"><!-- Navigation bar -->
<nav>...</nav>Always include:
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your Page Title</title>Recommended additions:
<meta name="description" content="Short SEO-friendly description.">
<link rel="stylesheet" href="style.css">project/
│ README.md
│ index.html
│ style.css
│ script.js
└── assets/
├── images/
├── icons/
└── fonts/
Lowercase + hyphens:
my-website-page.html
- Use consistent indentation
- Keep one element per line
- Use blank lines between logical sections
- Format attributes on new lines when long
Example:
<img
src="large-photo.jpg"
alt="Mountain landscape"
loading="lazy"
><center><font><marquee>
Use CSS instead.
Incorrect:
<span><div>Invalid</div></span>Correct:
<div><span>Valid</span></div>CSS:
<link rel="stylesheet" href="styles.css">JS:
<script src="script.js"></script>W3C Validator: https://validator.w3.org/
- Add alt text to images
- Use
<label>with<input> - Use semantic HTML
- Ensure color contrast
- Add ARIA roles only when necessary
Example:
<label for="email">Email</label>
<input id="email" type="email"><h1>Main page title</h1>
<h2>Section title</h2>Do not use headings for visual styling only (e.g., bold text).
✘ Incorrect:
<p><a href="#">Click here</a> to learn about accessibility.</p>If all the links say “Click here,” they become meaningless:
- Click here
- Click here
- Click here
✔ Correct:
<p><a href="#">Learn more</a> about web accessibility.</p>Descriptive ones are clear:
- Download the accessibility guide
- Read HTML best practices
- View pricing
- Use
loading="lazy"on images - Compress assets
- Minimize CSS & JS
- Preload critical assets
- Keep DOM small
| Category | Best Practice |
|---|---|
| Doctype | Use <!DOCTYPE html> |
| Element Names | Use lowercase |
| Attributes | Use lowercase & quotes |
| Boolean Attributes | Omit value |
| Encoding | UTF-8 |
| Semantic Tags | Use proper structure |
| Deprecated Tags | Avoid them |
| Comments | Use proper comments |
| Block Elements | Wrap properly |
| File Names | lowercase + hyphen |
| Indentation | Consistent |
| CSS/JS | External files |
| Validation | W3C Validator |