LESSON 23

HTML Best Practices

Learning objective: Write clean, valid, accessible HTML you can be proud of.

Understand

Good HTML habits make your work easier to read and maintain.

Key habits: use semantic tags, always add alt text and labels, indent nested elements, close every tag, use lowercase tag names, and validate your page. Clean HTML is easier to style, debug, and hand to teammates.

Analogy: Best practices are like tidy handwriting: the content is the same, but everyone can read it.

See It in Action

Tidy, semantic, accessible markup:

<main>
  <article>
    <h1>Clean Code</h1>
    <img src="cover.png" alt="Book cover">
  </article>
</main>
How it works: Indentation shows nesting, semantic tags give meaning, and the image has alt text — all signs of well-crafted HTML.

Try It Yourself

  1. Re-indent one of your pages so nesting is clear.
  2. Check every image has alt and every field has a label.
  3. Paste your page into an online HTML validator.

Quick Quiz

Which of these is a good HTML habit?

Challenge

Clean up one of your earlier pages so it validates with no errors.

Success condition: Your page passes an HTML validator with no errors.