agyanadda@gmail.com

HTML Best Practices

HTML Best Practices 1 min read Updated Nov 30, 2026 Topic 33 of 33

Follow these habits to write clean, professional HTML.

  1. Always start with <!DOCTYPE html> and set lang, charset and viewport.
  2. Use lowercase tag and attribute names.
  3. Always close elements (</p>, </li>) and quote attribute values.
  4. Indent nested elements so the code is easy to read.
  5. Use semantic elements (header, nav, main, footer).
  6. Keep CSS in a separate file instead of many style attributes.
  7. Compress images and set width/height to avoid layout jumps.
  8. Validate your HTML with the AgyanAdda HTML Formatter or the W3C validator.

Good HTML is the base for good CSS, JavaScript and SEO.

Example

Example — Clean, well-structured page HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Clean HTML Example</title>
</head>
<body>
  <header>
    <h1>My Portfolio</h1>
  </header>
  <main>
    <section>
      <h2>About me</h2>
      <p>I am learning web development.</p>
    </section>
  </main>
  <footer>
    <p>&copy; 2026</p>
  </footer>
</body>
</html>

Test Yourself With Exercises

Exercise 1 True / False

HTML tag names should be written in lowercase.

Exercise 2 Multiple Choice

Where should most CSS go?

Frequently Asked Questions

Learn CSS next to style your pages, then JavaScript to make them interactive. AgyanAdda has free tutorials for both.