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

HTML CSS Style Guide

fredycaceres edited this page Nov 7, 2016 · 5 revisions
<title></title> <style> body { background-color: #fff; color: #333; font-family: sans-serif; font-size: 10pt; margin-right: 100px; margin-left: 100px; } h1, h2, h3, h4, h5, h6, .toc_title { color: #06c; margin-top: 2em; margin-bottom: 1em; } h2, .toc_title { font-weight: bold; font-size: 12pt; margin-left: -40px; } h3, h4, h5, h6 { font-size: 10pt; margin-left: -20px; } .link_button { float: left; display: none; background-color: #f8f8ff; border-color: #f0f0ff; border-style: solid; border-width: 1px; font-size: 75%; margin-top: 0px; margin-left: -50px; padding: 4px; border-radius: 3px; -webkit-border-radius: 3px; -moz-border-radius: 3px; } .showhide_button { float: left; cursor: pointer; border-width: 1px; border-style: solid; border-color: #ddd #aaa #aaa #ddd; padding: 0 3px 1px; margin: 0 4px 8px 0; border-radius: 3px; -webkit-border-radius: 3px; -moz-border-radius: 3px; } pre { font-size: 10pt; display: block; color: #060; background-color: #f8fff8; border-color: #f0fff0; border-style: solid; border-top-width: 1px; border-bottom-width: 1px; border-right-width: 1px; border-left-width: 5px; padding-left: 12px; padding-right: 12px; padding-top: 4px; padding-bottom: 4px; } pre.badcode { color: #c00; background-color: #fff8f8; border-color: #fff0f0; } code, samp, var { color: #060; } </style>

General Formatting Rules

link
Indent by 2 spaces at a time.

Don’t use tabs or mix tabs and spaces for indentation.

<ul>
  <li>Fantastic
  <li>Great
</ul>
.example {
  color: blue;
}
link
Use only lowercase.

All code has to be lowercase: This applies to HTML element names, attributes, attribute values (unless text/CDATA), CSS selectors, properties, and property values (with the exception of strings).

<!-- Not recommended -->
<A HREF="/">Home</A>
<!-- Recommended -->
<img src="google.png" alt="Google">
/* Not recommended */
color: #E5E5E5;
/* Recommended */
color: #e5e5e5;
link
Remove trailing white spaces.

Trailing white spaces are unnecessary and can complicate diffs.

<!-- Not recommended -->
<p>What?_
<!-- Recommended -->
<p>Yes please.
<title></title> <style> body { background-color: #fff; color: #333; font-family: sans-serif; font-size: 10pt; margin-right: 100px; margin-left: 100px; } h1, h2, h3, h4, h5, h6, .toc_title { color: #06c; margin-top: 2em; margin-bottom: 1em; } h3, h4, h5, h6 { font-size: 10pt; margin-left: -20px; } .link_button { float: left; display: none; background-color: #f8f8ff; border-color: #f0f0ff; border-style: solid; border-width: 1px; font-size: 75%; margin-top: 0px; margin-left: -50px; padding: 4px; border-radius: 3px; -webkit-border-radius: 3px; -moz-border-radius: 3px; } .showhide_button { float: left; cursor: pointer; border-width: 1px; border-style: solid; border-color: #ddd #aaa #aaa #ddd; padding: 0 3px 1px; margin: 0 4px 8px 0; border-radius: 3px; -webkit-border-radius: 3px; -moz-border-radius: 3px; } pre { font-size: 10pt; display: block; color: #060; background-color: #f8fff8; border-color: #f0fff0; border-style: solid; border-top-width: 1px; border-bottom-width: 1px; border-right-width: 1px; border-left-width: 5px; padding-left: 12px; padding-right: 12px; padding-top: 4px; padding-bottom: 4px; } pre.badcode { color: #c00; background-color: #fff8f8; border-color: #fff0f0; } code, samp, var { color: #060; } </style> <title></title> <style> h1, h2, h3, h4, h5, h6, .toc_title { color: #06c; margin-top: 2em; margin-bottom: 1em; } h2, .toc_title { font-weight: bold; font-size: 12pt; margin-left: -40px; } body { background-color: #fff; color: #333; font-family: sans-serif; font-size: 10pt; margin-right: 100px; margin-left: 100px; } </style>

HTML Style Rules

link
Use HTML according to its purpose.

Use elements (sometimes incorrectly called “tags”) for what they have been created for. For example, use heading elements for headings, p elements for paragraphs, a elements for anchors, etc.

Using HTML according to its purpose is important for accessibility, reuse, and code efficiency reasons.

    <div>
<!-- Not recommended -->
<div onclick="goToRecommendations();">All recommendations</div>
<!-- Recommended -->
<a href="recommendations/">All recommendations</a>
<title></title> <style> body { background-color: #fff; color: #333; font-family: sans-serif; font-size: 10pt; margin-right: 100px; margin-left: 100px; } h1, h2, h3, h4, h5, h6, .toc_title { color: #06c; margin-top: 2em; margin-bottom: 1em; } h2, .toc_title { font-weight: bold; font-size: 12pt; margin-left: -40px; } h3, h4, h5, h6 { font-size: 10pt; margin-left: -20px; } .link_button { float: left; display: none; background-color: #f8f8ff; border-color: #f0f0ff; border-style: solid; border-width: 1px; font-size: 75%; margin-top: 0px; margin-left: -50px; padding: 4px; border-radius: 3px; -webkit-border-radius: 3px; -moz-border-radius: 3px; } .showhide_button { float: left; cursor: pointer; border-width: 1px; border-style: solid; border-color: #ddd #aaa #aaa #ddd; padding: 0 3px 1px; margin: 0 4px 8px 0; border-radius: 3px; -webkit-border-radius: 3px; -moz-border-radius: 3px; } pre { font-size: 10pt; display: block; color: #060; background-color: #f8fff8; border-color: #f0fff0; border-style: solid; border-top-width: 1px; border-bottom-width: 1px; border-right-width: 1px; border-left-width: 5px; padding-left: 12px; padding-right: 12px; padding-top: 4px; padding-bottom: 4px; } pre.badcode { color: #c00; background-color: #fff8f8; border-color: #fff0f0; } code, samp, var { color: #060; } </style>

HTML Formatting Rules

link
Use a new line for every block, list, or table element, and indent every such child element.

Independent of the styling of an element (as CSS allows elements to assume a different role per display property), put every block, list, or table element on a new line.

Also, indent them if they are child elements of a block, list, or table element.

(If you run into issues around whitespace between list items it’s acceptable to put all li elements in one line. A linter is encouraged to throw a warning instead of an error.)

<blockquote>
  <p><em>Space</em>, the final frontier.</p>
</blockquote>
<ul>
  <li>Moe
  <li>Larry
  <li>Curly
</ul>
<table>
  <thead>
    <tr>
      <th scope="col">Income
      <th scope="col">Taxes
  <tbody>
    <tr>
      <td>$ 5.00
      <td>$ 4.50
</table>
link
When quoting attributes values, use double quotation marks.

Use double ("") rather than single quotation marks ('') around attribute values.

<!-- Not recommended -->
<a class='maia-button maia-button-secondary'>Sign in</a>
<!-- Recommended -->
<a class="maia-button maia-button-secondary">Sign in</a>
<title></title> <style> h1, h2, h3, h4, h5, h6, .toc_title { color: #06c; margin-top: 2em; margin-bottom: 1em; } h2, .toc_title { font-weight: bold; font-size: 12pt; margin-left: -40px; } body { background-color: #fff; color: #333; font-family: sans-serif; font-size: 10pt; margin-right: 100px; margin-left: 100px; } </style>

CSS Style Rules

link
Use shorthand properties where possible.

CSS offers a variety of shorthand properties (like font) that should be used whenever possible, even in cases where only one value is explicitly set.

Using shorthand properties is useful for code efficiency and understandability.

/* Not recommended */
border-top-style: none;
font-family: palatino, georgia, serif;
font-size: 100%;
line-height: 1.6;
padding-bottom: 2em;
padding-left: 1em;
padding-right: 1em;
padding-top: 0;
/* Recommended */
border-top: 0;
font: 100%/1.6 palatino, georgia, serif;
padding: 0 1em 2em;
### Attribute order HTML attributes should come in this particular order for easier reading of code. * class * id, name * data-* * src, for, type, href, value * title, alt * aria-*, role

Classes make for great reusable components, so they come first. Ids are more specific and should be used sparingly (e.g., for in-page bookmarks), so they come second.

Clone this wiki locally