HTML Syntax

Overview

  • Use soft tabs with two spaces—they’re the only way to guarantee code renders the same in any environment.
  • Nested elements should be indented once (two spaces).
  • Always use double quotes, never single quotes, on attributes.
  • Don’t include a trailing slash in self-closing HTML5 elements.

CSS and JavaScript Includes

Per HTML5 spec there is no need to specify a type when including CSS and JavaScript files. text/css and text/javascript are their respective defaults.

HTML5 spec links

Practicality Over Purity

Strive to maintain HTML standards and semantics, but not at the expense of practicality. Use the least amount of markup with the fewest intricacies whenever possible.

Reducing Markup

Whenever possible, avoid superfluous parent elements in your markup.

<!-- Not Good -->
<section>
  <div class="container">
    <div class="row"></div>
  </div>
</section>

<!-- Better -->
<section class="container">
  <div class="row"></div>
</section>

Javascript Generated Markup

Writing markup in a JavaScript file makes the content harder to find, harder to edit, and less performant. Avoid it whenever possible.