HTML
General
- All HTML must validate as XHTML 1.0 Strict.
- Use standard tags whenever possible. Tags should be used in a semantic way. For example <quote> instead of <p class="quote">.
- Keep the templates simple; make them in a way that they look decent without any css. The document flow should be logical.
- A functionality that is in more than one template should use the same vars and html in all those templates. Examples are pagination, asset controls, attachments, file icons etc.
- Add indents and comments to add more structure to the code, this is especially important for closing tags of the same type (e.g. </div></div>).
- Remove inline styles and other deprecated markup.
Basic tags
Headers (h1, h2, ...)
All asset title headers in templates should be h3. Exceptions are the Style (the site name is in a h1) and Page Layouts (h2). H2's should also be used in operation templates, account layouts etc.
Any other headers inside the template should have the correct hierarchy. So, in summary:
- h1: sitename in style template
- h2: page layout title, titles in operation templates (e.g. "Login") or other templates for things that do not live on a page
- h3: asset title
- h4 – h6: asset sub titles
Table, tr, td, th, thead, tbody etc.
Remove all table layout that is used for positioning. When use of a table is appropriate, column names should be in th tags (in a thead).
The only attribute on a table tag should be cellspacing="0". Use the __ODD__ variable when a table is in a loop to add a class to the odd trs:
<tr<tmpl_if __ODD__> class="odd"</tmpl_if>>
<td>...</td>
</tr>
Use caption, thead, tbody, tfoot and colgroup when appropriate.
Divs
Every element should be contained in a div with a class for easy positioning (e.g. Attachments, description, thread menu), but beware of “divitis”, keep it balanced.
Every template should have a containing div, with and id, and class:
<div id="[asset name]<tmpl_var assetId>" class="[asset name] [template name]">
...
<!--/[asset name]<tmpl_var assetId> /[asset name] [template name]-->
</div>
Descriptions should always be in a div w/ class “description”. Close divs with a comment, e.g.
<div class=”description”>
...
<!--/decription-->
</div>
Note: to prevent bugs in IE (repeating text - usually triggered by floats) the comment comes before the closing tag.
B, i, strong, em and span
Do not use b, i, strong or em for markup, unless they are used in a semantic way (e.g. an error message could contain a strong). Use span for styling inline elements.
Ul, ol and dl
Use the appropriate type of list for listed items: search results in a dl, link lists in an ul etc.
P
Use the p tag for a paragraph of text only, for example for wrapping a synopsis. Since text is usually generated by the editor, p tags included, p tags should be scarse in templates.
Br
Do not add breaks, spacing and newlines should be done with css by the designer.
Form, fieldset, legend, input, select, optgroup, textarea, label etc.
A specification for forms is in the works.
Hr
Don't use hrs, since cross browser markup is difficult.
Img
Images should have an alt attribute with descriptive content. An image url or filename is not descriptive. Use the asset title when possible (like in Article with Image) or add an RFE when there is no way of adding a proper alt content (and sometimes: improvise).
Blockquote, q
Use blockquote or q for quotes (for instance for quotes in the collaboration system).
Classes and IDs
- CSS should be valid CSS2.1
- Classes and IDs should be semantic/decriptive.
- Don't add IDs unless they are unique (wrong: id="article", right: id="article<tmpl_var assetId>").
- Keep it simple: do not add classes to elements that can easily be targeted with use of their parent.
- Use classes that are already in other templates, if the element has the same function. Find common elements and standardize classes and IDs. e.g. buttons, pagination, success and error messages.
- Styles for those elements should be added to wg-core.css; classnames and IDs should be preceded by "wg-" (e.g. "wg-attachmentIcon").
- Use camelCase for classes and IDs consisting of multiple words.