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.

In shortLower case, quoted values, nested properly, indented, with alt text and a clear structure.

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

Clean code habitsLowercase tagsQuote attribute valuesIndent nested elementsValidate the page
Clean code habits

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
Good: lower case and quotesTry it Yourself
Bad: mixed case and no quotesTry it Yourself

It works, but it is harder to read and easy to break.

Indent nested elementsTry it Yourself
Always close tagsTry it Yourself
Always add altTry it Yourself
Use meaningful class namesTry it Yourself

Name what it is, not how it looks. Prefer price over big-red-text.

Do not skip heading levelsTry it Yourself
Use CSS, not HTML, for looksTry it Yourself
Comments for big sectionsTry it Yourself
Short lines and one tag per lineTry it Yourself

Quick quiz

1. Which is the better habit?

2. Alt text on images is

3. Skipping from h1 to h4 is

My notes
Ask a question about this lesson