Follow these habits to write clean, professional HTML.
- Always start with
<!DOCTYPE html>and setlang,charsetandviewport. - Use lowercase tag and attribute names.
- Always close elements (
</p>,</li>) and quote attribute values. - Indent nested elements so the code is easy to read.
- Use semantic elements (
header,nav,main,footer). - Keep CSS in a separate file instead of many
styleattributes. - Compress images and set
width/heightto avoid layout jumps. - 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>© 2026</p>
</footer>
</body>
</html>