Home / Learn HTML / HTML Style Guide and Best Practices
HTML Style Guide and Best Practices
Small habits that make your code clean, fast and easy to fix.
Definition
A style guide is a set of habits that keep code clean and the same everywhere. Clean code is easier to read, fix and share.
Theory in plain words
What it is
A style guide is a set of habits for clean HTML: lowercase tags, quoted values, indentation and meaningful elements.
Why we use it
Clean code is easier to read, share and fix, and has fewer bugs.
How it works
Follow the same rules in every file. Tools such as Prettier and the W3C validator can help check them.
Where it is used
- Team projects
- Code reviews
- Your own portfolio
It works, but it is harder to read and easy to break.
Name what it is, not how it looks. Prefer price over big-red-text.
- Keep file names lower case with hyphens:
about-us.html. - Declare the language:
<html lang="en">. - Put scripts at the end or use
defer. - Do not repeat ids.
- Check your code in a validator such as validator.w3.org.
Quick quiz
1. Which is the better habit?
Clean style avoids mistakes.
2. Alt text on images is
Alt helps screen readers and SEO.
3. Skipping from h1 to h4 is
Keep heading levels in order.