CHAPTER 23
Beginner
HTML Best Practices and Clean Structure
Updated: May 10, 2026
5 min read
# HTML Best Practices and Clean Structure
1. Introduction
Anybody can write HTML that "works." A professional developer writes HTML that is clean, readable, accessible, and fast. In this chapter, we cover the golden rules of structuring your codebase.2. Learning Objectives
- Write properly indented, clean HTML.
- Avoid "Div Soup".
- Implement semantic HTML rules.
3. Detailed Explanations
Indentation is Mandatory
Always use 2 or 4 spaces to indent nested elements. This makes reading parent-child relationships easy.
html
Always Use Lowercase
While HTML is technically case-insensitive, the standard is to write tags and attributes entirely in lowercase.
html
Quote Attribute Values
Always wrap your attribute values in double quotes.
html
Avoid "Div Soup"
"Div Soup" is a slang term for a webpage built entirely using<div> tags. Use semantic HTML instead (<header>, <nav>, <main>, <article>, <footer>).
html
4. Mini Project: Refactor Messy HTML
Look at this messy code and see how we fix it.The Mess:
html
The Refactor:
html
5. MCQs
Q1: Which of the following is considered bad practice in HTML? A) Using lowercase tags. B) Leaving out quotes around attribute values. C) Using indentation. D) Using the<main> tag.
*Answer: B*
6. Summary
Clean code shows that you are a professional. Always indent properly, use lowercase tags, quote your attributes, provide a doctype, and use semantic tags over<div> whenever possible.