bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/HTML/HTML Foundations
HTML•HTML Foundations

HTML Style Guide

Concept visual

HTML Style Guide

Graph traversalgraph
ABCDE
current
queued
1
4

Start from A

Consistent, clean, and tidy HTML code makes it easier for others to read and understand your code. Here are some guidelines and tips for creating good HTML code.

Always Declare Document Type

Always declare the document type as the first line in your document. The correct document type for HTML is: <!DOCTYPE html>

Use Lowercase Element Names

HTML allows mixing uppercase and lowercase letters in element names. However, we recommend using lowercase element names, because:

Mixing uppercase and lowercase names looks bad

Developers normally use lowercase names

Lowercase looks cleaner

Lowercase is easier to type

Good:

<body>

Formula

< p > This is a paragraph.</p >

</body>

Bad:

<BODY>

Formula

< P > This is a paragraph.</P >

</BODY>

Close All HTML Elements

In HTML, you do not have to close all elements (for example the <p> element). However, we strongly recommend closing all HTML elements, like this:

Good:

<section>

Formula

< p > This is a paragraph.</p >
< p > This is a paragraph.</p >

</section>

Bad:

<section>

Formula

< p > This is a paragraph.
< p > This is a paragraph.

</section>

Use Lowercase Attribute Names

HTML allows mixing uppercase and lowercase letters in attribute names. However, we recommend using lowercase attribute names, because:

Mixing uppercase and lowercase names looks bad

Developers normally use lowercase names

Lowercase looks cleaner

Lowercase is easier to type

Good:

Formula

< a href ="https://www.w3schools.com/html/"> Visit our HTML tutorial </a >

Bad:

Formula

< a HREF ="https://www.w3schools.com/html/"> Visit our HTML tutorial </a >

Always Quote Attribute Values

HTML allows attribute values without quotes. However, we recommend quoting attribute values, because:

Developers normally quote attribute values

Quoted values are easier to read

You MUST use quotes if the value contains spaces

Good:

<table class="striped">

Bad:

Formula

< table class = striped >

Previous

HTML Responsive Web Design

Next

HTML Entities