Going Further Lesson 41 of 42
HTML Style Guide — Writing Clean, Professional Code
Simple rules for neat, readable HTML that teachers, teammates and future you will thank you for — lowercase tags, indentation, quotes, file names and more.
Two pages can look exactly the same in the browser while one has neat, easy-to-read code and the other is a mess. The browser doesn't care. But people do: your teacher checking your project, your groupmate fixing a bug, and you, three weeks later, trying to remember what you wrote.
A style guide is a set of habits for writing code the same way every time. These are the habits professional web developers use.
1. Always declare the document type
The first line of every HTML page should be:
<!DOCTYPE html>
Without it, browsers switch to an old "quirks mode" that copies the bugs of browsers from the 1990s, and your layout may behave strangely.
2. Use lowercase for elements and attributes
HTML doesn't care whether you write <P> or <p>, but lowercase is the standard. It's easier to type and easier to read.
<!-- Avoid -->
<BODY><P CLASS="Intro">Hello</P></BODY>
<!-- Good -->
<body><p class="intro">Hello</p></body>
3. Close your elements
Browsers often forgive a missing </p> or </li>, but they guess where the element ends, and sometimes they guess wrong. Close every element that has a closing tag.
<!-- Avoid -->
<ul>
<li>Adobo
<li>Sinigang
</ul>
<!-- Good -->
<ul>
<li>Adobo</li>
<li>Sinigang</li>
</ul>
4. Quote your attribute values
Quotes are required when a value has spaces, so it's simplest to always use them. Double quotes are the most common choice.
<!-- Breaks: the class is only "card" -->
<div class=card featured>
<!-- Good -->
<div class="card featured">
5. Indent nested elements
When an element is inside another, move it in by 2 spaces (or 4, just be consistent). Indentation shows the family tree of your page at a glance, and makes missing closing tags easy to spot.
<!-- Hard to read: -->
<main><section><h2>Menu</h2><ul><li>Tapsilog</li><li>Longsilog</li></ul></section></main>
<!-- Easy to read: -->
<main>
<section>
<h2>Menu</h2>
<ul>
<li>Tapsilog</li>
<li>Longsilog</li>
</ul>
</section>
</main>
Both menus look the same in the result. Only the code is different. Don't add blank lines everywhere, though. Use them to separate big sections, the way you'd use paragraphs in an essay.
6. Always add alt, width and height to images
<img src="images/school-building.jpg" alt="Front view of the school building" width="800" height="500">
alt helps blind users and appears if the image fails to load. width and height let the browser reserve the space before the image arrives, so the text doesn't "jump" while the page loads on slow data.
7. Don't add spaces around the equals sign
<!-- Avoid -->
<a href = "about.html">
<!-- Good -->
<a href="about.html">
8. Always include lang, charset, viewport and title
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Grade 10 – Rizal | Class Page</title>
</head>
If your page is in Filipino, use lang="fil" instead. This helps screen readers pronounce words correctly and helps Google show your page to the right people.
9. Name files simply
Web servers are usually case-sensitive: Logo.PNG and logo.png are different files online, even if they work the same on your Windows laptop. This is the most common reason a project works on the student's computer but shows broken images after it's published.
- Use lowercase only:
about.html, notAbout.html - Use hyphens instead of spaces:
class-schedule.html, notclass schedule.html - No special characters like
ñ,#,&or?in file names - Call your home page
index.html. Servers open it automatically.
10. Comment the big sections, not every line
<!-- ===== Navigation ===== -->
<nav>...</nav>
<!-- ===== Main content ===== -->
<main>...</main>
A short comment before each major section helps others find their way around. Don't comment the obvious, like <!-- this is a paragraph -->.
What about XHTML?
You might see old textbooks or reviewers mention XHTML. It was a stricter version of HTML popular in the early 2000s. XHTML required lowercase tags, closed elements, quoted attributes, and a slash on empty elements like <br /> and <img ... />. If the code broke a rule, the page could fail to display completely.
Modern HTML (HTML5) is forgiving, and you don't need to write XHTML. But notice that most of XHTML's rules are the same good habits in this style guide. Writing <br> or <br /> are both fine in HTML today. Just pick one and stay consistent.
Check your code with a validator
The free W3C Markup Validation Service (validator.w3.org) checks your HTML for mistakes, like missing closing tags, wrong nesting, or duplicate ids. Paste your code into the "Validate by Direct Input" tab. It's like a spell checker for HTML, and a great final step before submitting a project.
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04