Note: This style guide inherits rules from the SGML-Based Languages Style Guide and the Global Style Guide. For images, it also assumes compliance with the Media Files Style Guide. This document supersedes our legacy Production Standards and HTML Style Guide documents (Microsoft Word).
"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." - Mark Otto (source)
- It is recommended to use Mark Otto's proposed attribute order
- Always begin the document with the doctype (i.e.,
<!DOCTYPE html>) - Always include optional elements (e.g.,
html,head,body) - If setting content type, always use
text/html(even for XHTML) - Explicitly close tags where closing tag is optional (e.g.,
<p>,<li>) - Use self-enclosing syntax for "void" elements (e.g.,
<br />,<hr />) - Do not include attribute value for Boolean attributes (e.g.,
<input disabled />) - Always provide an
altelement for multimedia content (e.g.,<img>,<audio>,<video>) - Prefer
<svg>to<canvas>unless performance is a key concern (e.g., 100+ elements) - Omit
typeattribute for<link>,<script>or<style>elements - Always define
relattribute for<link>element; define when appropriate for<a>element - Always define a
langattribute on the<html>element - Always wrap
<input>elements with a<label>element (no need for theforattribute in this usage) - Elements that must exist no more than one time should be identified using
id; otherwiseclass
- Always use semantic tags when available (e.g.,
<button>over<div class="button" />) - Every page should have one (and exactly one)
<main>element identifying the primary content - Every page should have at least one
<header>,<footer>,<nav>, and<article>element - For a detail page, the
<main>element will typically include an<article>element, which may include multiple<section>elements - For an index of pages or comments, use an
<article>element for each item; in this case, the<article>elements may be wrapped in a<section>element - Headings (e.g.,
h1-h6) should be used to denote outline, not (just) style; use a class modifier to alter a style rather than skipping a heading - The
<section>,<article>, and<aside>effectively encapsulate a node in the outline; headings can optionally be "reset" within them (i.e., start back ath1) if preferred (not required) - At minimum, set ARIA
roleattributes on HTML5 semantic elements (e.g.,<header role="banner">) - When no meaningful semantic tags are otherwise available, authors are strongly encouraged to decorate markup with Schema.org types
- Prefer using RDFa lite syntax over Microdata or Microformats; RDFa is extensible into other vocabularies, and is no more verbose than Microdata
- Attempt to limit
<div>elements for presentational requirements (e.g., changing positioning); otherwise, prefer semantic elements - Use HTML5 Shim to ensure backward compatibility with Internet Explorer
- Always set encoding to UTF-8 (i.e., via
<meta charset="utf-8">) - Take advantage of UTF-8 encoding; do not use entity-references unless required (e.g., for HTML escaping)