- This document is based on the Google HTML/CSS style guide and others, as cited.
- The purpose of this document is to define the format and style for HTML and CSS. The syntax of this document is GitHub Flavored Markdown (GFM), licensed under Attribution-ShareAlike 4.0 International, and has been validated by linter-markdown 5.2.2.
-
- Use the HTTPS protocol for embedded resources where possible
-
- Two spaces per
tab
- Use Atom-Beautify to format
- Use only lowercase unless
text/CDATA
- Remove trailing white spaces.
-
- Use UTF-8 (no BOM). Make sure your editor uses UTF-8 as character encoding, without a byte order mark.
- Explain where possible
- Mark todos and action items only with keyword
TODO
. - Append a contact
TODO(John)
- Append action items after a colon as in
TODO : action item
-
- HTML5 (HTML syntax) is preferred for all HTML documents:
<!DOCTYPE html>
- Use valid HTML where possible.
- Example
- 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.
- Provide alternative contents for multimedia.
- For multimedia, such as images, videos, animated objects via
canvas
, make sure to offer alternative access. For images that means use of meaningful alternative text (alt
) and for video and audio transcripts and captions, if available. - Strictly keep structure (markup), presentation (styling), and behavior (scripting) apart, and try to keep the interaction between the three to an absolute minimum.
- That is, make sure documents and templates contain only HTML and HTML that is solely serving structural purposes. Move everything presentational into style sheets, and everything behavioral into scripts.
- In addition, keep the contact area as small as possible by linking as few style sheets and scripts as possible from documents and templates.
- There is no need to use entity references like
—
,”
, or☺
, assuming the same encoding (UTF-8) is used for files and editors as well as among teams. - The only exceptions apply to characters with special meaning in HTML (like
<
and&
) as well as control or “invisible” characters (like no-break spaces). - Omit optional tags (optional) BUT PLAY WELL WITH OTHERS.
- For file size optimization and scannability purposes, consider omitting optional tags. The HTML5 specification defines what tags can be omitted.
- Do not use
type
attributes for style sheets (unless not using CSS) and scripts (unless not using JavaScript). - Specifying
type
attributes in these contexts is not necessary as HTML5 impliestext/css
andtext/javascript
as defaults.
-
- Use a new line for every block, list, or table element, and indent every such child element.
- Also, indent them if they are child elements of a block, list, or table element.
- Use soft wrap in your text editor.
- Double quotes.
-
- Use valid CSS where possible.
- Use meaningful or generic ID and class names.
- Names that are specific and reflect the purpose of the element should be preferred as these are most understandable and the least likely to change.
- Using functional or generic names reduces the probability of unnecessary document or template changes.
- Use ID and class names that are as short as possible but as long as necessary.
- Try to convey what an ID or class is about while being as brief as possible.
- Using ID and class names this way contributes to acceptable levels of understandability and code efficiency.
- Avoid qualifying ID and class names with type selectors.
- Unless necessary (for example with helper classes), do not use element names in conjunction with IDs or classes.
- 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. - Do not use units after
0
values unless they are required. - Do not put
0
s in front of values or lengths between -1 and 1. - For color values that permit it, 3 character hexadecimal notation is shorter and more succinct.
- In large projects as well as for code that gets embedded in other projects or on external sites use prefixes (as namespaces) for ID and class names. Use short, unique identifiers followed by a dash.
adw-help {} /* AdWords */
- Separate words in ID and class names by a hyphen.
- Do not concatenate words and abbreviations in selectors by any characters (including none at all) other than hyphens, in order to improve understanding and scannability.
.ads-sample {}
- Avoid user agent detection as well as CSS “hacks”—try a different approach first.
- It’s tempting to address styling differences over user agent detection or special CSS filters, workarounds, and hacks. Both approaches should be considered last resort in order to achieve and maintain an efficient and manageable code base. Put another way, giving detection and hacks a free pass will hurt projects in the long run as projects tend to take the way of least resistance. That is, allowing and making it easy to use detection and hacks means using detection and hacks more frequently—and more frequently is too frequently.
-
- NO ALPHA
-
- Positioning
- Positioning comes first because it can remove an element from the normal flow of the document and override box model related styles.
-
- Box model (display, float, width, etc)
- The box model comes next as it dictates a component's dimensions and placement.
-
- Typography (font, line-height, text-*)
- Everything else takes place inside the component or without impacting the previous two sections, and thus they come last.
-
- Visuals (background, border, opacity)
-
- Misc (CSS3 properties)
- Indent all block content.
- Use a semicolon after every declaration.
- Use a space after a property name’s colon.
font-weight: bold;
- Always use a single space between the last selector and the opening brace that begins the declaration block.
#video {
h1,
h2,
h3
- Always put a blank line (two line breaks) between rules.
html {
background: #fff;
}
body {
margin: auto;
width: 50%;
}
- Single not double
-
4.3 Material Design
-
4.3.1 Material Design Responsive Grid Breakpoints
TODO
- Material Design provides responsive layouts based on the following column structures. Layouts using 4-column, 8-column, and 12-column grids are available for use across different screens, devices, and orientations.
- Each breakpoint range determines the number of columns, and recommended margins and gutters, for each display size.
-
Breakpoint Range (dp) | Portrait | Landscape | Window | Columns | Margins / Gutters* |
---|---|---|---|---|---|
0 – 359 | xs | 4 | 16 | ||
360 – 399 | xs | 4 | 16 | ||
400 – 479 | xs | 4 | 16 | ||
480 – 599 | xs | 4 | 16 | ||
600 – 719 | s | 8 | 16 | ||
720 – 839 | s | 8 | 24 | ||
840 – 959 | s | 12 | 24 | ||
960 – 1023 | s | 12 | 24 | ||
1024 – 1279 | m | 12 | 24 | ||
1280 – 1439 | m | 12 | 24 | ||
1440 – 1599 | l | 12 | 24 | ||
1600 – 1919 | l | 12 | 24 | ||
1920 + | xl | 12 | 24 | ||
*Margins and gutters are flexible and don’t need to be of equal size.
-
- Content is placed in the areas of the screen that contain columns.
- Column width is defined using percentages, rather than fixed values, to allow content to flexibly adapt to any screen size. The number of columns displayed in the grid is determined by the breakpoint range (a range of predetermined screen sizes) at which a screen is viewed, whether it’s a breakpoint for mobile, tablet, or another size.
- Gutters are the spaces between columns. They help separate content.
- Gutter widths are fixed values at each breakpoint range. To better adapt to the screen, gutter width can change at different breakpoints. Wider gutters are more appropriate for larger screens, as they create more whitespace between columns.
- Margins are the space between content and the left and right edges of the screen.
- Margin widths are defined as fixed values at each breakpoint range. To better adapt to the screen, the margin width can change at different breakpoints. Wider margins are more appropriate for larger screens, as they create more whitespace around the perimeter of content.
- The Material Design layout grid can be customized for touch UIs that scroll horizontally. Columns, gutters, and margins are laid out from left to right, rather than top to bottom. The height of the screen determines the number of columns in a horizontal grid.
- Horizontally scrolling UIs are uncommon on non-touch and web platforms.
- Horizontal grids can be positioned to accommodate different heights, allowing space for app bars or other UI regions at the top.
-
- Group sections by a section comment (optional).
- If possible, group style sheet sections together by using comments. Separate sections with new lines.
/* Header */
#adw-header {}
/* Footer */
#adw-footer {}
/* Gallery */
.adw-gallery {}
-
5.1 Be consistent and REMEMBER syntax tag omission
-
-
5.2.1 Code Declaration
-
5.2.2 Grouping
-
5.2.3 Property Order
-
5.2.4 CSS Style Guides
-