Well-structured HTML is easier to read, maintain, and learn. The following style rules help you write clean, consistent code.
Use 2 or 4 spaces for indentation when nesting HTML elements. It helps visually separate hierarchical levels.
html
<ul>
<li>First</li>
<li>Second</li>
</ul>Always write HTML tags and attributes in lowercase. While HTML is case-insensitive, lowercase improves consistency.
Always use double quotes for attribute values. This is the most widely adopted convention.
html
<img src="logo.png" alt="Company Logo">Use attributes in a consistent order (e.g., class, id, src, alt). This helps readability.
Insert blank lines between larger HTML sections. It visually separates different content blocks.
Use meaningful, hyphen-separated names for classes and IDs (e.g., 'main-header', 'footer-links').
html
<div class="main-header">
<h1>Welcome</h1>
</div>Use comments to mark larger blocks or provide explanations. Donβt overuse them, but make navigation easier.
html
<!-- Start of main section -->
<main>
...
</main>The most important rule: be consistent! Choose a style and follow it throughout the entire project.
β¨ Ask Lara β your AI study partner
Unlock personalized learning support. Lara can explain lessons, summarize topics, and answer your study questions β available from the Go plan and above.
Lara helps you learn faster β exclusive to ReadyTools Go, Plus, and Max members.