-
Hajipur, Bihar, 844101
A good HTML style guide helps you write clean, consistent and easy-to-maintain code. When multiple developers work on the same project or when your files grow large, a consistent structure becomes important. In this chapter, you will learn the recommended rules for formatting, naming and organising your HTML. These guidelines make your pages easier to read, debug and extend.
A style guide ensures that your code stays readable. It avoids messy formatting and unpredictable patterns. When you follow a uniform style:
the code becomes easier to scan
debugging becomes faster
teamwork becomes smoother
files look professional and organised
browsers render pages without confusion
A style guide does not change how HTML works. It only standardises how you write it.
HTML is not case-sensitive, but using lowercase tags keeps your code clean and consistent.
<p>This is a paragraph.</p>
<P>This is a paragraph.</P>
Lowercase tags are easier to read and match common best practices.
Just like tags, keep attribute names lowercase.
<input type="text" placeholder="Enter name">
Avoid mixed or uppercase attributes because they make the code look inconsistent.
HTML5 allows some tags to be self-closing, but for clarity use proper closing tags whenever required.
<div>
<p>Hello</p>
</div>
<div>
<p>Hello
</div>
Unclosed tags often break layouts.
Indentation makes the structure visible. Each nested element should be indented by two spaces or four spaces. Stick to one style throughout your project.
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
</ul>
</nav>
Indentation helps you understand parent-child relationships instantly.
Always wrap attribute values inside double quotes.
<input type="text" name="username">
Some values work without quotes, but that is error-prone and not preferred.
Name your classes and IDs based on their purpose, not their appearance.
header
footer
main-nav
product-card
blue-text
big-div
box1
Meaningful names make your code understandable even months later.
Semantic tags describe the purpose of each section. This improves readability and accessibility.
header
main
footer
nav
section
article
aside
<article>
<h2>Blog Title</h2>
<p>Blog content...</p>
</article>
Semantic tags help both developers and search engines.
Avoid writing very long lines inside your HTML. Short and clean lines make your code easier to scan.
<p class="intro" id="first-intro" style="color: #333; font-size: 16px;">Welcome to our tutorial on HTML styling. This text explains why formatting is important.</p>
<p class="intro" id="first-intro">
Welcome to our tutorial on HTML styling. This text explains why formatting is important.
</p>
Comments help when you revisit code after months.
<!-- Main navigation -->
<nav>
...
</nav>
Use comments sparingly but effectively.
Inline styles make your HTML cluttered and hard to maintain. Prefer external CSS files.
<p style="color: red;">Error message</p>
<p class="error">Error message</p>
This separates structure from design.
Always add descriptive alt text. This improves accessibility and SEO.
<img src="team-photo.jpg" alt="Team members standing together">
Alt text describes the image when it fails to load or when a screen reader is used.
File names should be short, lowercase and use hyphens instead of spaces.
about-us.html
contact-form.html
AboutUs.HTML
contact form.html
Consistent naming prevents errors and looks professional.
Some attributes don't need a value. Their presence alone is meaningful.
Examples:
checked
disabled
required
readonly
<input type="checkbox" checked>
Using checked="checked" is allowed but unnecessary.
Group related elements together.
<!-- Header -->
<header>...</header>
<!-- Main content -->
<main>...</main>
<!-- Footer -->
<footer>...</footer>
This structure keeps the page easy to understand.
Extra spaces or blank lines can make code look messy. Keep spacing consistent.
<div>
<p>Hello</p>
</div>
<div>
<p>Hello</p>
</div>
Meta tags set the character set, description and viewport.
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
These two should appear in every modern HTML page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Page</title>
</head>
<body>
<header>
<h1>Website Title</h1>
</header>
<main>
<section>
<h2>About Us</h2>
<p>Welcome to our website.</p>
</section>
</main>
<footer>
<p>Copyright 2025</p>
</footer>
</body>
</html>
This example follows most of the style rules discussed above.
A consistent HTML style guide helps you write clean, readable and well-structured code. You learned how to format tags, indent code, name attributes, use semantic elements, avoid inline styles and follow proper commenting and spacing practices. These guidelines make your HTML easier to work with and ensure a professional codebase that stays maintainable in the long run.
Q1. Format the given messy HTML code according to style guide rules.
Q2. Write semantic HTML for a blog post including header, main, and footer sections.
Q3. Create a navigation menu with consistent indentation and attribute order.
Q4. Correctly use void tags like <img> and <br> without closing tags.
Q5. Identify and fix inline styles by moving them to external CSS.
Q6. Use descriptive class and id names for a form section.
Q7. Add comments to explain a complex section of HTML code.
Q8. Write an accessible image tag with alt text following best practices.
Q9. Create a consistent attribute order for a list of links.
Q10. Refactor an HTML page to keep lines under 100 characters.