Writing HTML that works is one thing. Writing HTML that is clean, maintainable, and professional is another. Following a few simple best practices will make your code easier to read, debug, and share with others.
Indentation Matters
Indent nested tags consistently — two spaces or four spaces, pick one and stick with it. Proper indentation makes it obvious which tags are children of which. When you are missing a closing tag, good indentation helps you spot it instantly.
<ul>
<li>Item one</li>
<li>Item two</li>
</ul>
Try it Yourself →
Lowercase Tags and Closing Tags
HTML is case-insensitive, but the convention is to always use lowercase for tag names and attribute names. It is cleaner and consistent. Also, always close your tags — <p> needs </p>, <li> needs </li>. Self-closing tags like <br> are the exception.
Alt Attributes on Images
Every <img> needs an alt attribute. Screen readers read it aloud. Search engines use it to understand the image. If the image fails to load, the alt text shows instead. It is not optional if you care about accessibility.
<img src="logo.png" alt="Company logo">
Valid HTML and File Naming
Run your pages through the W3C validator to catch errors. Use lowercase letters and hyphens for file names — about-us.html, not AboutUs.html. Avoid spaces in file names; they cause problems with URLs and server paths.