Base HTML Coding Standards and Guidelines

  • HTML5 (HTML syntax) is preferred for all HTML documents: <!DOCTYPE html>.
  • Use UTF-8 (no BOM).
  • Unless circumstances require otherwise, set IE to use the latest supported mode with edge mode.
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  • Always use double quotes, never single quotes, on attributes.
  • Don’t include a trailing slash in self-closing elements.
  • Don’t omit optional closing tags (e.g. </li> or </body>).
  • If necessary attach JavaScript files at the end of document before tag.
  • Use the least amount of markup with the fewest intricacies whenever possible.
  • Omit the protocol portion (http:, https:) from embedded resources (Eg: images and other media files, style sheets, and scripts…) unless the respective files are not available over both protocols.
  • Use only lowercase for element names, attributes, attribute values (unless text/CDATA), CSS selectors, properties, and property values (with the exception of strings).
  • Use comments to explain code: What does it cover, what purpose does it serve, why is respective solution used or preferred?
  • Use valid HTML where possible. Use tools such as the W3C HTML validator to test.
  • Use semantic HTML elements.
  • Provide alternative contents for multimedia such as images, videos, animated objects via canvas.
  • Strictly keep structure (markup), presentation (styling), and behavior (scripting) apart, and try to keep the interaction between the three to an absolute minimum.
  • Avoid JavaScript generated markup whenever possible.
  • Do not use entity references (assuming the same encoding (UTF-8) is used for files and editors as well as among teams).
  • Use a new line for every block, list, or table element, and indent nested element (two spaces).