Skip to content

Commit 6bc68fe

Browse files
authored
Spaces for the code blocks that are not converted in GitHub pages correctly
1 parent db2f5fc commit 6bc68fe

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

HTML/html.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
- [JavaScript/TypeScript](../Scripts/javascript.md#javascripttypescript)
3030
- [General best practices](../Generals/generals.md#general-best-practices)
3131

32+
3233
---
3334

3435

36+
3537
# HTML
3638

3739
### VALIDATION
@@ -41,29 +43,40 @@ A concerted effort should be made to ensure that all HTML and CSS validate. Mark
4143
- [W3C HTML Markup Validator](http://validator.w3.org/)
4244
- [W3C CSS Validator](http://jigsaw.w3.org/css-validator)
4345

46+
47+
4448
### DECLARE A DOCTYPE
4549

4650
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+
4752
```HTML
4853
<!DOCTYPE html>
4954
```
5055

56+
57+
5158
### DECLARE THE LANGUAGE OF THE PAGE
5259

5360
Always add a `lang` attribute to the `html` tag to set the default language of your page.
61+
5462
```HTML
5563
<html lang="en">
5664
```
5765

5866
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.
5967

68+
69+
6070
### TITLES
6171

6272
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+
6374
```HTML
6475
<title>About us - Our mission and values | The Most Wonderful Company</title>
6576
```
6677

78+
79+
6780
### META DESCRIPTIONS
6881

6982
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.**_
7285

7386
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).
7487

88+
89+
7590
### VIEWPORT
7691

7792
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:
93+
7894
```HTML
7995
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
8096
```
@@ -83,9 +99,12 @@ The viewport is the user's visible area of a web page. The viewport varies with
8399
- `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).
84100
- `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).
85101

102+
103+
86104
### USE SEMANTIC HTML 5 TAGS
87105

88106
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+
89108
```HTML
90109
<!-- Don't do this -->
91110
<div id="main">
@@ -114,11 +133,14 @@ To improve the experience of users that are using readers and other tools to rea
114133
</main>
115134
```
116135

136+
137+
117138
### CLOSE TAGS
118139

119140
Leaving some tags open is simply a bad practice.
120141

121142
**Only self-closing tags are valid**. In HTML 5, normal HTML tags can never have self-closing tags.
143+
122144
```HTML
123145
<!-- Don't do this - Wrong but accepted in HTML 5 -->
124146
<br />
@@ -137,29 +159,39 @@ Leaving some tags open is simply a bad practice.
137159
<hr>
138160
```
139161

162+
163+
140164
### USE LOWERCASE
141165

142166
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.
143167

144168
We should keep it simple.
145169

170+
171+
146172
### CHARACTER ENCODING
147173

148174
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+
149176
```HTML
150177
<meta charset="utf-8">
151178
```
152179

180+
181+
153182
### USE CONDITIONAL COMMENTS
154183

155184
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.
185+
156186
```HTML
157187
<link href="style.css" rel="stylesheet">
158188
<!--[if lte IE 9]>
159189
<link href="ie.css" rel="stylesheet" type="text/css">
160190
<![endif]-->
161191
```
162192

193+
194+
163195
### USE PRACTICAL `id` AND `class` NAMES AND VALUES
164196

165197
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
168200

169201
Ids and class names should be all lowercase.
170202

203+
204+
171205
#### SPECIFICITY
172206

173207
To avoid CSS specificity issues, `id`s should be used sparingly, examples are: in-page bookmarks, anchors, form `label` tags, JavaScript's hooks, etc.
174208

209+
210+
175211
### IMAGES NEED `alt` ATTRIBUTES
176212

177213
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.
178214

179215
If an image is purely decorative (it provides no content value other than visual flair to the page) then a `background-image` is appropriate. 
180216

217+
218+
181219
### USE TABLES FOR TABULAR DATA ONLY
182220

183221
The `table` tag should only be used for the presentation of tabular data such as pricing or feature charts.
184222

185223
The only exception is when composing HTML email, in which a table is almost the only thing supported by soul crushing email clients.
186224

225+
226+
187227
### INCLUDE EXTERNAL CSS INSIDE THE `head` TAG
188228

189229
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.
190230

231+
232+
191233
### INCLUDING CSS AND JAVASCRIPT
192234

193235
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+
194237
```HTML
195238
<!-- External CSS file -->
196239
<link href="styles.css" rel="stylesheet">
@@ -204,6 +247,8 @@ Per HTML 5 spec, typically there is no need to specify a `type` when including
204247
<script src="app.js"></script>
205248
```
206249

250+
251+
207252
### KEEP THE SYNTAX ORGANIZED
208253

209254
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
213258
- Omit the values on Boolean attributes
214259

215260
For example:
261+
216262
```HTML
217263
<form action="/action_page.php" method="get">
218264
<fieldset>
@@ -231,11 +277,14 @@ For example:
231277
</form>
232278
```
233279

280+
281+
234282
### REDUCE MARKUP
235283

236284
Whenever possible, avoid superfluous parent elements when writing HTML: merging attributes and tags can help readability and improve the code.
237285

238286
Many times this requires iteration and refactoring, but produces less HTML.
287+
239288
```HTML
240289
<!-- Don't do this -->
241290
<span class="avatar">
@@ -246,11 +295,14 @@ Many times this requires iteration and refactoring, but produces less HTML.
246295
<img src="images/dog.jpg" class="avatar">
247296
```
248297

298+
299+
249300
### WHITESPACING AND FORMATTING
250301

251302
#### INDENT TAGS THAT ARE VERY LONG
252303

253304
For the sake or readability
305+
254306
```HTML
255307
<!-- Don't do this -->
256308
<input type="text" placeholder="Enter input" name="inputName"
@@ -270,7 +322,10 @@ For the sake or readability
270322
>
271323
```
272324

325+
326+
273327
#### ALWAYS USE DOUBLE QUOTES IN HTML FILES
328+
274329
```HTML
275330
<!-- Don't do this -->
276331
<input type='text' name='inputName' class='input-class'>
@@ -279,6 +334,8 @@ For the sake or readability
279334
<input type="text" name="inputName" class="input-class">
280335
```
281336

337+
338+
282339
#### ATTRIBUTES ORDER
283340

284341
HTML attributes should come in this particular order for easier reading the code:
@@ -292,6 +349,7 @@ HTML attributes should come in this particular order for easier reading the code
292349
- `data-*`
293350

294351
Examples:
352+
295353
```HTML
296354
<a href="/home" class="link" data-toggle="modal">
297355
Home page

0 commit comments

Comments
 (0)