Skip to content
This repository was archived by the owner on Apr 6, 2022. It is now read-only.

Latest commit

 

History

History
96 lines (68 loc) · 1.8 KB

File metadata and controls

96 lines (68 loc) · 1.8 KB

HTML Style Guide

The following document outlines a style guide for HTML pages and templates.

Tags

  • Always include a trailing slash in self-closing elements (e.g. <br/>, not <br>).
  • Don't omit optional closing tags (e.g. </li> or </body>).

Quotes

  • Use double quotes.
  • Don't omit quotes.

Whitespace

  • 4 spaces for indentation.
  • Strip trailing whitespace.

Attributes

HTML attributes can be indented 4 spaces OR aligned.

4-space indentation:

<marquee
    behavior="alternate"
    bgcolor="yellow"
    scrollamount="15">
    Hello World!
</marquee>

Aligned:

<div href="http://www.example.com/"
     class="link">
    Link Text
</a>

Identification

  • Prefer class for identifying elements that need to be selected for styling or queried via JavaScript.

Reducing markup

Whenever possible, avoid superfluous parent elements when writing HTML. Many times this requires iteration and refactoring, but produces less HTML. Take the following example:

<!-- Not so great -->
<span class="avatar">
    <img src="...">
</span>

<!-- Better -->
<img class="avatar" src="...">

Trivialities

Doctype

<!DOCTYPE html>
<html>
...
</html>

lang

The HTML lang attribute should be included and its value should conform to W3C standards and RFC 1766.

IE compatibility mode is deprecated

The IE Document Mode selector (<meta http-equiv="X-UA-Compatible" content="IE=edge" />) is now deprecated and should not be used (Source). Per Microsoft's recommendation, use the IE11 Standards selector, <!DOCTYPE html> instead.

Character encoding

<head>
    <meta charset="utf-8">
</head>