Best Practices for Writing Clean and Valid HTML
A collection of HTML best practices including proper indentation, naming, W3C validation, and common beginner mistakes you should avoid.
- Reading time
- 1 min read
- Comments
- Discussion

On this page
Writing clean HTML makes your code easier to read, maintain, and debug. Here are some practical habits worth building early.
Best Practices
1. Use Proper Indentation
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>2. Close Your Tags
<!-- Good -->
<p>This is correct</p>
<!-- Bad -->
<p>This is missing a closing tag</p>3. Use Lowercase Tag Names
<!-- Recommended -->
<div class="card"></div>4. Prefer Semantic Tags
Use <article>, <section>, <nav>, etc. instead of only <div>.
5. Validate Your Code
You can check your HTML using the W3C Validator.
6. Avoid Common Beginner Mistakes
- Don’t use headings just to make text bigger
- Don’t use tables for layout
- Don’t skip the
altattribute on important images - Don’t put block elements inside
<p>or<span>
Quick Tips
- Keep your code neat even when you’re just practicing.
- Give classes and IDs clear, meaningful names.
- Comment only when necessary — clean code is often self-explanatory.
- Write HTML first for structure, then add CSS for styling.

Written by
Razak
Writes about the web, slowly, and builds small tools on the side.
Keep reading
Read next
2 minGetting to Know HTML Iframe: How to Embed YouTube and Google Maps
How to use the HTML <iframe> tag to embed content from other sites, like a YouTube video or a Google Map, inside your own page.
Read article
1 minHow to Create Forms in HTML for Beginners
A beginner's guide to HTML forms: how the <form> tag sends data for logins, sign-ups and contact messages, starting from the basics.
Read article
1 minHTML Form Validation Without JavaScript
HTML5 has built-in form validation: required fields, length and number limits, and format patterns, all without a single line of JavaScript.
Read article
Discussion
Comments
Loading comments…