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
The DOCTYPE declaration should be in the first line of any HTML file. Actually, it activates the standard mode in all browser. It is recommended that you use the HTML doctype when using HTML 5:
51
+
47
52
```HTML
48
53
<!DOCTYPE html>
49
54
```
50
55
56
+
57
+
51
58
### DECLARE THE LANGUAGE OF THE PAGE
52
59
53
60
Always add a `lang` attribute to the `html` tag to set the default language of your page.
61
+
54
62
```HTML
55
63
<htmllang="en">
56
64
```
57
65
58
66
Browsers and other applications can use information about the language of content to deliver to users the most appropriate information, or to present information to users in the most appropriate way. The more content is tagged and tagged correctly, the more useful and pervasive such applications will become.
59
67
68
+
69
+
60
70
### TITLES
61
71
62
72
Titles should contain descriptive information that concisely describes the current page. In case of nested pages, information in the title tag should be ordered from most specific to least specific. A standard delimiter such as `–` or `|` should be employed to indicate distinct content levels, for example:
73
+
63
74
```HTML
64
75
<title>About us - Our mission and values | The Most Wonderful Company</title>
65
76
```
66
77
78
+
79
+
67
80
### META DESCRIPTIONS
68
81
69
82
A quality `meta description` can help when talking about SEO and indexing the web pages on the search engines. Ideally, all pages include a unique `meta description` that is a concise, human-readable description of that page’s contents.
@@ -72,9 +85,12 @@ _**Do not duplicate meta descriptions from other pages.**_
72
85
73
86
Customised meta descriptions can appear in search engine result pages. For example, _Google_ will sometimes replace custom meta descriptions with on-page content if they feel it is of more value to the end user. If no meta description exists, it usually create its own from on-page content. [More about titles and meta tags on _Google Developers_](https://developers.google.com/search/docs/advanced/appearance/good-titles-snippets).
74
87
88
+
89
+
75
90
### VIEWPORT
76
91
77
92
The viewport is the user's visible area of a web page. The viewport varies with the device, for this reason, it is smaller on a mobile phone than on a computer screen. HTML5 introduced a method to let web designers take control over the viewport, through the `<meta>` tag. We should include the `meta` tag `viewport` in all our web pages:
@@ -83,9 +99,12 @@ The viewport is the user's visible area of a web page. The viewport varies with
83
99
-`initial-scale=1` sets the initial zoom level when the page is first loaded by the browser and ensures smartphones retain the same zoom level during orientation change (from portrait to landscape and viceversa).
84
100
-`viewport-fit=cover` ensures that smartphones that use "[safe areas](https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/adaptivity-and-layout/)" are able to [adapt the content accordingly](https://stackoverflow.com/questions/56243315/handle-the-safe-area-in-chrome-browser-on-the-iphone-x-family).
85
101
102
+
103
+
86
104
### USE SEMANTIC HTML 5 TAGS
87
105
88
106
To improve the experience of users that are using readers and other tools to read a website, the best practice is to use the tags provided by HTML 5 so that clearly describe their meaning in a human and machine readable way.
107
+
89
108
```HTML
90
109
<!-- Don't do this -->
91
110
<divid="main">
@@ -114,11 +133,14 @@ To improve the experience of users that are using readers and other tools to rea
114
133
</main>
115
134
```
116
135
136
+
137
+
117
138
### CLOSE TAGS
118
139
119
140
Leaving some tags open is simply a bad practice.
120
141
121
142
**Only self-closing tags are valid**. In HTML 5, normal HTML tags can never have self-closing tags.
143
+
122
144
```HTML
123
145
<!-- Don't do this - Wrong but accepted in HTML 5 -->
124
146
<br />
@@ -137,29 +159,39 @@ Leaving some tags open is simply a bad practice.
137
159
<hr>
138
160
```
139
161
162
+
163
+
140
164
### USE LOWERCASE
141
165
142
166
It is a good practice to keep markup lower-case. The capitalizing markup will work and will probably not affect how your web pages are rendered, but it does affect code readability.
143
167
144
168
We should keep it simple.
145
169
170
+
171
+
146
172
### CHARACTER ENCODING
147
173
148
174
Quickly and easily ensure proper rendering of your content by declaring an explicit character encoding. When doing so, you may avoid using character entities in your HTML, provided their encoding matches that of the document (generally UTF-8).
175
+
149
176
```HTML
150
177
<metacharset="utf-8">
151
178
```
152
179
180
+
181
+
153
182
### USE CONDITIONAL COMMENTS
154
183
155
184
Sometimes some clients want to target specific versions of *Internet Explorer*, other than using well known IE hacks, we can use the conditional comment like the one shown below to target IE9 and lower versions.
### USE PRACTICAL `id` AND `class` NAMES AND VALUES
164
196
165
197
We should only give elements an `id` attribute if they are unique. Classes can be applied to multiple elements that share the same style properties.
@@ -168,29 +200,40 @@ It is always preferable to name something `id` or `class`, by the nature of what
168
200
169
201
Ids and class names should be all lowercase.
170
202
203
+
204
+
171
205
#### SPECIFICITY
172
206
173
207
To avoid CSS specificity issues, `id`s should be used sparingly, examples are: in-page bookmarks, anchors, form `label` tags, JavaScript's hooks, etc.
174
208
209
+
210
+
175
211
### IMAGES NEED `alt` ATTRIBUTES
176
212
177
213
The `img` tag requires alt text to both validate and meet accessibility guidelines. The text in the `alt` attribute should be descriptive of what the image shows, or is trying to achieve, unless of course the image is not critical.
178
214
179
215
If an image is purely decorative (it provides no content value other than visual flair to the page) then a `background-image` is appropriate.
180
216
217
+
218
+
181
219
### USE TABLES FOR TABULAR DATA ONLY
182
220
183
221
The `table` tag should only be used for the presentation of tabular data such as pricing or feature charts.
184
222
185
223
The only exception is when composing HTML email, in which a table is almost the only thing supported by soul crushing email clients.
186
224
225
+
226
+
187
227
### INCLUDE EXTERNAL CSS INSIDE THE `head` TAG
188
228
189
229
Style sheets can be placed anywhere but the HTML specification recommends that they be placed within the document `head` tag. The primary benefit is that pages will load faster.
190
230
231
+
232
+
191
233
### INCLUDING CSS AND JAVASCRIPT
192
234
193
235
Per HTML 5 spec, typically there is no need to specify a `type` when including CSS and JavaScript files as `text/css` and `text/javascript` are their respective defaults.
236
+
194
237
```HTML
195
238
<!-- External CSS file -->
196
239
<linkhref="styles.css"rel="stylesheet">
@@ -204,6 +247,8 @@ Per HTML 5 spec, typically there is no need to specify a `type` when including
204
247
<scriptsrc="app.js"></script>
205
248
```
206
249
250
+
251
+
207
252
### KEEP THE SYNTAX ORGANIZED
208
253
209
254
When pages grow, managing HTML can be hard. There are some quick rules that can help us to keep our syntax clean and organized. These include the following:
@@ -213,6 +258,7 @@ When pages grow, managing HTML can be hard. There are some quick rules that can
213
258
- Omit the values on Boolean attributes
214
259
215
260
For example:
261
+
216
262
```HTML
217
263
<formaction="/action_page.php"method="get">
218
264
<fieldset>
@@ -231,11 +277,14 @@ For example:
231
277
</form>
232
278
```
233
279
280
+
281
+
234
282
### REDUCE MARKUP
235
283
236
284
Whenever possible, avoid superfluous parent elements when writing HTML: merging attributes and tags can help readability and improve the code.
237
285
238
286
Many times this requires iteration and refactoring, but produces less HTML.
287
+
239
288
```HTML
240
289
<!-- Don't do this -->
241
290
<spanclass="avatar">
@@ -246,11 +295,14 @@ Many times this requires iteration and refactoring, but produces less HTML.
0 commit comments