You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: manual/en-US/coding-standards/chapters/html.md
+261-5Lines changed: 261 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,65 @@
3
3
These guidelines have been assembled following an examination of emerging practices, ideas and existing styleguides, and include items from:
4
4
5
5
1.[Google's html styleguide](http://google-styleguide.googlecode.com/svn/trunk/htmlcssguide.xml)
6
+
2.[JQuery's HTML Styleguide](http://contribute.jquery.org/style-guide/html/)
7
+
3.[Nicolas Ghallager's "Principles of writing consistent, idiomatic HTML"](https://github.com/necolas/idiomatic-html)
8
+
4.[Harry Robert's "My HTML/CSS coding style"](http://csswizardry.com/2012/04/my-html-css-coding-style/)
9
+
4.[The BBC's Media Standards and Guidelines](http://www.bbc.co.uk/guidelines/futuremedia/technical/semantic_markup.shtml)
10
+
11
+
### General principles
12
+
13
+
All code should look like a single person typed it, no matter how many people contributed. All comments and class names should be written using British English spelling.
14
+
15
+
### Doctype
16
+
17
+
Always use the minimal, versionless doctype.
18
+
19
+
```html
20
+
<!doctype html>
21
+
```
22
+
23
+
### Language
24
+
25
+
Always define which language the page is written in.
26
+
27
+
```html
28
+
<htmllang="en">
29
+
```
30
+
31
+
### Encoding
32
+
Always define the character encoding. The encoding should be defined as early as possible.
33
+
Make sure your editor uses UTF-8 as character encoding, without a byte order mark (UTF-8, no BOM).
34
+
Do not specify the encoding of style sheets as these assume UTF-8.
35
+
36
+
```html
37
+
<metacharset="utf-8">
38
+
```
39
+
40
+
[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/)
41
+
42
+
43
+
### Capitalisation
44
+
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.
45
+
46
+
```html
47
+
<!-- Good -->
48
+
<imgsrc="joomla.png"alt="Joomla">
49
+
50
+
<!-- Bad -->
51
+
<AHREF="/">Home</A>
52
+
```
53
+
54
+
```html
55
+
<!-- Good -->
56
+
a {
57
+
color: #a3a3a3;
58
+
}
59
+
60
+
<!-- Bad -->
61
+
a {
62
+
color: #A3A3A3;
63
+
}
64
+
```
6
65
7
66
### Protocol
8
67
@@ -18,8 +77,12 @@ This prevents mixed content issues and results in minor file size savings.
All html should be lowercase; element names, attributes, attribute values (unless text/CDATA), CSS selectors, properties, and property values (with the exception of strings).
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.
Elements with multiple attributes can have attributes arranged across multiple lines in an effort to improve readability and produce more useful diffs:
136
+
137
+
```html
138
+
<aclass="[some-value]"
139
+
data-action="[some-value]"
140
+
data-id="[some-value]"
141
+
href="[some-value]">
142
+
<span>Text</span>
143
+
</a>
144
+
```
145
+
146
+
### Elements
147
+
Optional closing tags may not be omitted.
148
+
```html
149
+
<!-- Good -->
150
+
<p>The quick brown fox jumps over the lazy dog.</p>
151
+
<!-- Bad -->
152
+
<p>The quick brown fox jumps over the lazy dog.
153
+
```
154
+
155
+
Self-closing (void) elements should not be closed. Trailing forward slashes and spaces should be omitted.
156
+
```html
157
+
<!-- Good -->
158
+
<imgsrc="//images/logo.png"alt="">
159
+
<!-- Bad -->
160
+
<imgsrc="//images/logo.png"alt="" />
40
161
```
41
162
163
+
42
164
### Formatting
43
165
Use a new line for every block, list, or table element, and indent every such child element.
44
166
@@ -58,6 +180,113 @@ Use a new line for every block, list, or table element, and indent every such ch
58
180
</ul></div>
59
181
```
60
182
183
+
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.)
184
+
185
+
Keep line-length to a sensible maximum, e.g., 80 columns.
186
+
187
+
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.
188
+
189
+
```html
190
+
<blockquote>
191
+
<p><em>Space</em>, the final frontier.</p>
192
+
</blockquote>
193
+
194
+
195
+
<ul>
196
+
<li>Moe</li>
197
+
<li>Larry</li>
198
+
<li>Curly</li>
199
+
</ul>
200
+
201
+
202
+
<table>
203
+
<thead>
204
+
<tr>
205
+
<thscope="col">Income</th>
206
+
<thscope="col">Taxes</th>
207
+
</tr>
208
+
<tbody>
209
+
<tr>
210
+
<td>$ 5.00</td>
211
+
<td>$ 4.50</td>
212
+
</tr>
213
+
</table>
214
+
```
215
+
216
+
### Indentation
217
+
Don't indent inside html, body, script, or style. Indent inside head and all other elements.
218
+
Indent by four spaces at a time. Don’t use tabs or mix tabs and spaces for indentation.
219
+
220
+
221
+
```html
222
+
<!-- Good -->
223
+
<!doctype html>
224
+
<htmllang="en">
225
+
<head>
226
+
<metacharset="utf-8">
227
+
<title>Sample Page</title>
228
+
229
+
<linkrel="stylesheet"href="/style.css">
230
+
<style>
231
+
body {
232
+
font-size: 100em;
233
+
}
234
+
</style>
235
+
236
+
<scriptsrc="/jquery.js"></script>
237
+
<script>
238
+
$(function() {
239
+
$( "p" ).text( $.fn.jquery );
240
+
});
241
+
</script>
242
+
</head>
243
+
<body>
244
+
245
+
<p>Joomla! is awesome!<p>
246
+
247
+
</body>
248
+
</html>
249
+
```
250
+
251
+
### Trailing Whitespace
252
+
Remove trailing white spaces. Trailing white spaces are unnecessary and can complicate diffs.
253
+
254
+
```html
255
+
<!-- Good -->
256
+
<p>Yes please.</p>
257
+
258
+
<!-- Bad -->
259
+
<p>No, thank you. </p>
260
+
```
261
+
262
+
263
+
### Entity References
264
+
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.
265
+
266
+
The only exceptions apply to characters with special meaning in HTML (like < and &) as well as control or “invisible” characters (like no-break spaces).
267
+
```html
268
+
<!-- Good -->
269
+
<p>The currency symbol for the Euro is “€”.</p>
270
+
271
+
<!-- Bad -->
272
+
<p>The currency symbol for the Euro is “&eur;”.</p>
273
+
```
274
+
275
+
### Inline CSS
276
+
277
+
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.
You should not use border, align, valign, or clear attributes. Avoid use of style attributes, except where using syndicated content or internal syndicating systems.
288
+
289
+
61
290
### Semantics
62
291
Use HTML according to its purpose. For example, use heading elements for headings, p elements for paragraphs, a elements for anchors, etc.
63
292
@@ -70,6 +299,26 @@ Using HTML according to its purpose is important for accessibility, reuse, and c
0 commit comments