diff --git a/manual/en-US/coding-standards/chapters/html.md b/manual/en-US/coding-standards/chapters/html.md index c0e0138a..9a7a641f 100644 --- a/manual/en-US/coding-standards/chapters/html.md +++ b/manual/en-US/coding-standards/chapters/html.md @@ -3,6 +3,62 @@ These guidelines have been assembled following an examination of emerging practices, ideas and existing styleguides, and include items from: 1. [Google's html styleguide](http://google-styleguide.googlecode.com/svn/trunk/htmlcssguide.xml) +2. [JQuery's HTML Styleguide](http://contribute.jquery.org/style-guide/html/) +3. [Nicolas Ghallager's "Principles of writing consistent, idiomatic HTML"](https://github.com/necolas/idiomatic-html) +4. [Harry Robert's "My HTML/CSS coding style"](http://csswizardry.com/2012/04/my-html-css-coding-style/) +4. [The BBC's Media Standards and Guidelines](http://www.bbc.co.uk/guidelines/futuremedia/technical/semantic_markup.shtml) + + +### Doctype + +Always use the minimal, versionless doctype. + +```html + +``` + +### Language + +Always define which language the page is written in. + +```html + +``` + +### Encoding +Always define the character encoding. The encoding should be defined as early as possible. +Make sure your editor uses UTF-8 as character encoding, without a byte order mark (UTF-8, no BOM). +Do not specify the encoding of style sheets as these assume UTF-8. + +```html + +``` + +[More on encodings and when and how to specify them can be found in Handling character encodings in HTML and CSS](http://www.w3.org/International/tutorials/tutorial-char-enc/) + + +### Capitalisation +All html should be lowercase; element names, attributes, attribute values (unless text/CDATA), CSS selectors, properties, and property values (with the exception of strings). Additionally, there is no need to use CDATA to escape inline JavaScript, formerly a requirement to meet XML strictness in XHTML. + +```html + +Joomla + + +Home +``` + +```html + +a { + color: #a3a3a3; +} + + +a { + color: #A3A3A3; +} +``` ### Protocol @@ -18,8 +74,12 @@ This prevents mixed content issues and results in minor file size savings. ``` +### Elements and Attributes + +Always include html, head, and body tags. + ### Type attributes -Do not use type attributes for style sheets (unless not using CSS) and scripts (unless not using JavaScript). +Do not use type or attributes for style sheets (unless not using CSS) and scripts (unless not using JavaScript). ```html @@ -28,17 +88,77 @@ Do not use type attributes for style sheets (unless not using CSS) and scripts ( ``` -### Capitalisation -All html should be lowercase; element names, attributes, attribute values (unless text/CDATA), CSS selectors, properties, and property values (with the exception of strings). +### Language attributes +Do not use language attributes on script tags. +```html + + + + +``` +Use attribute/value pairs for boolean attributes +```html + + -Home + +``` + +HTML attributes should be listed in an order that reflects the fact that class names are the primary interface through which CSS and JavaScript select elements. + +1. class +2. id +3. data-* +4. Everything else +```html + +Text + +Text +``` + +Elements with multiple attributes can have attributes arranged across multiple lines in an effort to improve readability and produce more useful diffs: + +```html + + Text + +``` + +### Elements +Optional closing tags may not be omitted. +```html + +

The quick brown fox jumps over the lazy dog.

+ +

The quick brown fox jumps over the lazy dog. +``` + +Self-closing (void) elements should not be closed. Trailing forward slashes and spaces should be omitted. +```html + + + + ``` + ### Formatting Use a new line for every block, list, or table element, and indent every such child element. @@ -51,13 +171,122 @@ Use a new line for every block, list, or table element, and indent every such ch - +

``` +We prefer readability over file-size savings when it comes to maintaining existing files. Plenty of whitespace is encouraged. Use whitespace to visually separate groups of related markup and to improve the readability and maintainability of your HTML. Use two empty lines between larger blocks, and use a single empty line between child blocks of larger blocks. Be consistent. (If you are worried about your document's size, spaces (as well as repeated use of the same strings - for instance class names) are excellent candidates for compression. Also, you may use a markup minifier to decrease your document's file size.) + +Keep line-length to a sensible maximum, e.g., 80 columns. + +Tip: configure your editor to "show invisibles". This will allow you to eliminate end of line whitespace, eliminate unintended blank line whitespace, and avoid polluting commits. + +```html +
+

Space, the final frontier.

+
+ + + + + + + + + + + + + + + + +
IncomeTaxes
$ 5.00$ 4.50
+``` + +### Indentation +Don't indent inside html, body, script, or style. Indent inside head and all other elements. +Indent by four spaces at a time. Don’t use tabs or mix tabs and spaces for indentation. + + +```html + + + + + + Sample Page + + + + + + + + + +

Joomla! is awesome!

+ + + +``` + +### Trailing Whitespace +Remove trailing white spaces. Trailing white spaces are unnecessary and can complicate diffs. + +```html + +

Yes please.

+ + +

No, thank you.

+``` + + +### Entity References +Do not use entity references. 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). +```html + +

The currency symbol for the Euro is “€”.

+ + +

The currency symbol for the Euro is “&eur;”.

+``` + +### Inline CSS + +Inline CSS must be avoided. When altering states using JavaScript, use CSS to define your states, and only use onobtrusive JavaScript to alter class names whenever possible. +```html + +Home + + +Home +``` + +@todo more meaningful example. + +### Style Attributes +You should not use border, align, valign, or clear attributes. Avoid use of style attributes, except where using syndicated content or internal syndicating systems. + + ### Semantics Use HTML according to its purpose. For example, use heading elements for headings, p elements for paragraphs, a elements for anchors, etc. @@ -66,10 +295,34 @@ Using HTML according to its purpose is important for accessibility, reuse, and c View subscriptions - +
View subscriptions
``` + + +### Markup + +#### Image Tags +Image elements () must have an alt attribute. Height and width attributes are optional and may be omitted. + + +@todo add examples from here http://www.bbc.co.uk/guidelines/futuremedia/technical/semantic_markup.shtml + +### Comments +@todo: comment styles in JS, CSS, HTML +For more complex blocks of HTML, it may be useful to add a comment to the closing tag: +```html +
+ +
+
+ +
+``` + + + ### Mark todos Highlight todos by using the keyword TODO, eg: @@ -79,4 +332,11 @@ Highlight todos by using the keyword TODO, eg:
  • Home
  • Blog
  • -``` \ No newline at end of file +``` + + + +### Markup validation tools +@todo: list various testing tools: +* http://validator.w3.org/nu/ +* http://csslint.net/