Code formatting
HTML
-
Use Polygot Markup
with the following emphasis:
-
Use XHTML compliant Boolean attributes e.g.
<input type="text" required="required" />
. - Use double quotation marks for attributes.
-
Use the minimized tag syntax, with a space before the closing slash,
for void elements, e.g.
<br />
.
-
Use XHTML compliant Boolean attributes e.g.
-
Use consistent line breaks:
- Add line breaks only between sibling sectioning elements & ARIA landmark roles.
- Place inline tags on the same line.
- Place block-level tags on a new line and indented.
- Include templating serverside code as part of the nesting of elements.
- Wrap long lines of text and treat as block-level elements, using 150 char length as a guide.
CSS
Example of style
/* header */ .action .action-information, .button .information:last-child { background: url("../images/generic-logo.png") no-repeat center 0 #fff; background-image: url("../images/generic-bg-bottom.png"), url("../images/generic-bg-top.png"); border: 1px solid #000; -webkit-box-shadow: /* multiple properties on different lines */ 0 1px 3px rgba(0, 0, 0, .2), 0 2px 6px rgba(0, 0, 0, .1); -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, .2), 0 2px 6px rgba(0, 0, 0, .1); -ms-box-shadow: 0 1px 3px rgba(0, 0, 0, .2), 0 2px 6px rgba(0, 0, 0, .1); -o-box-shadow: 0 1px 3px rgba(0, 0, 0, .2), 0 2px 6px rgba(0, 0, 0, .1); box-shadow: 0 1px 3px rgba(0, 0, 0, .2), 0 2px 6px rgba(0, 0, 0, .1); color: #333; display: block; font-family: Helmet, Freesans, sans-serif; /* bbc glue font stack /* font-size: 1.3em; /* only use ems for font-sizes (including on the body) */ padding: 5px 0 2% 0; -webkit-transition: all 700ms ease; /* use ms for duration */ -moz-transition: all 700ms ease; -ms-transition: all 700ms ease; -o-transition: all 700ms ease; transition: all 700ms ease; z-index: 3; } .action a { color: rgba(0, 0, 0, .2); }
Structure of a style
Use "semi-expanded" structure.
[selector][comma][carriage-return] [selector][space][open-curly-bracket][carriage-return] [tab][property][colon][space][property-value][semi-colon][carriage-return] [close-curly-bracket][carriage-return] [carriage-return]
Selector naming
- Use only lowercase.
- Use only hyphens to separate words.
Property order
- Alphabetical.
- By the length of prefix (long to short) for vendor prefixed properties.
- Carry on the alphabetical order for multiple properties (e.g. border-bottom, border-left...):
.download { border-bottom: 1px solid #000; border-left: 2px solid #000; border-right: 1px solid #000; border-top: 2px solid #000; }
Property value order
background: [colour] ["url"] [scroll] [repeat] [position];
border: [size] [type] [colour];
Prefixed Property value spacing
.download { -webkit-transition: all 700ms ease; -moz-transition: all 700ms ease; -ms-transition: all 700ms ease; -o-transition: all 700ms ease; transition: all 700ms ease; }
Text formatting
-
Use consistent, version-control-friendly text formatting:
- Use tabs for indentation - length of 4 spaces.
- Use UNIX-style line endings.
- Trim trailing whitespace from lines.
- Ensure all text-based files end with a newline character.
Media assets
Naming conventions
- Use only lowercase.
- Use only hyphens to separate words e.g. "home-logo.png".