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
+268-8Lines changed: 268 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,62 @@
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
+
12
+
### Doctype
13
+
14
+
Always use the minimal, versionless doctype.
15
+
16
+
```html
17
+
<!doctype html>
18
+
```
19
+
20
+
### Language
21
+
22
+
Always define which language the page is written in.
23
+
24
+
```html
25
+
<htmllang="en">
26
+
```
27
+
28
+
### Encoding
29
+
Always define the character encoding. The encoding should be defined as early as possible.
30
+
Make sure your editor uses UTF-8 as character encoding, without a byte order mark (UTF-8, no BOM).
31
+
Do not specify the encoding of style sheets as these assume UTF-8.
32
+
33
+
```html
34
+
<metacharset="utf-8">
35
+
```
36
+
37
+
[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/)
38
+
39
+
40
+
### Capitalisation
41
+
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.
42
+
43
+
```html
44
+
<!-- Good -->
45
+
<imgsrc="joomla.png"alt="Joomla">
46
+
47
+
<!-- Bad -->
48
+
<AHREF="/">Home</A>
49
+
```
50
+
51
+
```html
52
+
<!-- Good -->
53
+
a {
54
+
color: #a3a3a3;
55
+
}
56
+
57
+
<!-- Bad -->
58
+
a {
59
+
color: #A3A3A3;
60
+
}
61
+
```
6
62
7
63
### Protocol
8
64
@@ -18,8 +74,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:
134
+
135
+
```html
136
+
<aclass="[some-value]"
137
+
data-action="[some-value]"
138
+
data-id="[some-value]"
139
+
href="[some-value]">
140
+
<span>Text</span>
141
+
</a>
142
+
```
143
+
144
+
### Elements
145
+
Optional closing tags may not be omitted.
146
+
```html
147
+
<!-- Good -->
148
+
<p>The quick brown fox jumps over the lazy dog.</p>
149
+
<!-- Bad -->
150
+
<p>The quick brown fox jumps over the lazy dog.
151
+
```
152
+
153
+
Self-closing (void) elements should not be closed. Trailing forward slashes and spaces should be omitted.
154
+
```html
155
+
<!-- Good -->
156
+
<imgsrc="//images/logo.png"alt="">
157
+
<!-- Bad -->
158
+
<imgsrc="//images/logo.png"alt="" />
40
159
```
41
160
161
+
42
162
### Formatting
43
163
Use a new line for every block, list, or table element, and indent every such child element.
44
164
@@ -51,13 +171,122 @@ Use a new line for every block, list, or table element, and indent every such ch
51
171
</ul>
52
172
</div>
53
173
54
-
<!-- Bad - ul is a block element -->
174
+
<!-- Bad -->
55
175
<div><ul>
56
176
<li>Home</li>
57
177
<li>Blog</li>
58
178
</ul></div>
59
179
```
60
180
181
+
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.)
182
+
183
+
Keep line-length to a sensible maximum, e.g., 80 columns.
184
+
185
+
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.
186
+
187
+
```html
188
+
<blockquote>
189
+
<p><em>Space</em>, the final frontier.</p>
190
+
</blockquote>
191
+
192
+
193
+
<ul>
194
+
<li>Moe</li>
195
+
<li>Larry</li>
196
+
<li>Curly</li>
197
+
</ul>
198
+
199
+
200
+
<table>
201
+
<thead>
202
+
<tr>
203
+
<thscope="col">Income</th>
204
+
<thscope="col">Taxes</th>
205
+
</tr>
206
+
<tbody>
207
+
<tr>
208
+
<td>$ 5.00</td>
209
+
<td>$ 4.50</td>
210
+
</tr>
211
+
</table>
212
+
```
213
+
214
+
### Indentation
215
+
Don't indent inside html, body, script, or style. Indent inside head and all other elements.
216
+
Indent by four spaces at a time. Don’t use tabs or mix tabs and spaces for indentation.
217
+
218
+
219
+
```html
220
+
<!-- Good -->
221
+
<!doctype html>
222
+
<htmllang="en">
223
+
<head>
224
+
<metacharset="utf-8">
225
+
<title>Sample Page</title>
226
+
227
+
<linkrel="stylesheet"href="/style.css">
228
+
<style>
229
+
body {
230
+
font-size: 100em;
231
+
}
232
+
</style>
233
+
234
+
<scriptsrc="/jquery.js"></script>
235
+
<script>
236
+
$(function() {
237
+
$( "p" ).text( $.fn.jquery );
238
+
});
239
+
</script>
240
+
</head>
241
+
<body>
242
+
243
+
<p>Joomla! is awesome!<p>
244
+
245
+
</body>
246
+
</html>
247
+
```
248
+
249
+
### Trailing Whitespace
250
+
Remove trailing white spaces. Trailing white spaces are unnecessary and can complicate diffs.
251
+
252
+
```html
253
+
<!-- Good -->
254
+
<p>Yes please.</p>
255
+
256
+
<!-- Bad -->
257
+
<p>No, thank you. </p>
258
+
```
259
+
260
+
261
+
### Entity References
262
+
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.
263
+
264
+
The only exceptions apply to characters with special meaning in HTML (like < and &) as well as control or “invisible” characters (like no-break spaces).
265
+
```html
266
+
<!-- Good -->
267
+
<p>The currency symbol for the Euro is “€”.</p>
268
+
269
+
<!-- Bad -->
270
+
<p>The currency symbol for the Euro is “&eur;”.</p>
271
+
```
272
+
273
+
### Inline CSS
274
+
275
+
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
@@ -66,10 +295,34 @@ Using HTML according to its purpose is important for accessibility, reuse, and c
0 commit comments