Repository navigation
Expand file tree
/
Copy pathhtml-examples.html
More file actions
453 lines (290 loc) · 14.7 KB
/
Copy pathhtml-examples.html
File metadata and controls
453 lines (290 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<!--Basics-->
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
<!--
The <!DOCTYPE html> declaration defines that this document is an HTML5 document
The <html> element is the root element of an HTML page
The <head> element contains meta information about the HTML page and no content that will be displayed
The <title> element specifies a title for the HTML page
(which is shown in the browser's title bar or in the page's tab)
The <body> element defines the document's body, and is a container for all the visible contents,
such as headings, paragraphs, images, hyperlinks, tables, lists, etc.
The <h1> element defines a large heading
The <p> element defines a paragraph
-->
<!--This element sets the character set your document should use to UTF-8,
which includes most characters from the vast majority of written languages.-->
<meta charset="utf-8">
<!--This viewport element ensures the page renders at the width of the browser viewport,
preventing mobile browsers from rendering pages wider than the viewport and then shrinking them down.-->
<meta name="viewport" content="width=device-width">
<!--More basic tags-->
<!--HTML links are defined with the <a> tag:
The link's destination is specified in the href attribute.-->
<a href="https://www.w3schools.com">This is a link</a>
<!--HTML images are defined with the <img> tag.
The source file (src), alternative text (alt), width, and height are provided as attributes:-->
<img src="w3schools.jpg" alt="W3Schools.com" width="104" height="142">
<!--The <br> tag defines a line break, and is an empty element without a closing tag:-->
<p>This is a <br> paragraph with a line break.</p>
<!--The <hr> Horizontal rule element is used to separate content (or define a change) in an HTML page:-->
<p>This is some text.</p>
<hr>
<h2>This is heading 2</h2>
<!--The text inside a <pre> element is displayed in a fixed-width font (usually Courier),
and it preserves both spaces and line breaks:-->
<pre>
My Bonnie lies over the ocean.
My Bonnie lies over the sea.
My Bonnie lies over the ocean.
Oh, bring back my Bonnie to me.
</pre>
<!--You can create ordered and unordered lists in html using the UL or OL tag-->
<ol>
<li>I</li>
<li>Know</li>
<li>My</li>
<li>Lists</li>
</ol>
<!--Atrributes-->
<!--The <a> tag defines a hyperlink. The href attribute specifies the URL of the page the link goes to:-->
<a href="https://www.w3schools.com">Visit W3Schools</a>
<!--The style attribute is used to add styles to an element, such as color, font, size, and more.-->
<p style="color:red;">This is a red paragraph.</p>
<!--The <img> tag should also contain the width and height attributes, which specify the width and height of the image (in pixels):-->
<!--The required alt attribute for the <img> tag specifies an alternate text for an image,
if the image for some reason cannot be displayed. This can be due to a slow connection, or an error in the src attribute, or if the user uses a screen reader.-->
<img src="img_girl.jpg" width="500" height="600" alt="Girl Image">
<!--
1. Absolute URL - Links to an external image that is hosted on another website. Example: src="https://www.w3schools.com/images/img_girl.jpg".
Notes: External images might be under copyright. If you do not get permission to use it, you may be in violation of copyright laws.
In addition, you cannot control external images; it can suddenly be removed or changed.
2. Relative URL - Links to an image that is hosted within the website. Here, the URL does not include the domain name.
If the URL begins without a slash, it will be relative to the current page. Example: src="img_girl.jpg". If the URL begins with a slash, it will be relative to the domain.
Example: src="/images/img_girl.jpg".-->
<!--You should always include the lang attribute inside the <html> tag, to declare the language of the Web page.
This is meant to assist search engines and browsers.-->
<!--Country codes can also be added to the language code in the lang attribute.
So, the first two characters define the language of the HTML page, and the last two characters define the country.-->
<!DOCTYPE html>
<html lang="en-US">
</html>
<!--The title attribute defines some extra information about an element.
The value of the title attribute will be displayed as a tooltip when you mouse over the element:-->
<p title="I'm a tooltip">This is a paragraph.</p>
<!--When working with a lot of tags instead of changing them manually with the style attribute
you can use the ID attribute to recall it using #(ID NAME)-->
<!--Used for a single element-->
<p id="id-text">This is some text</p>
#id-text{
width:60%
}
<!--When working with a lot of tags instead of changing them by tag with the style attribute
you can use the class attribute to recall it using .(class NAME)-->
<!--Used for multiple elements-->
<p class="class-text">This is some text</p>
.class-text{
width:60%
}
<!--Styles-->
<!--Set the background color for a page to powderblue:-->
<body style="background-color:powderblue;"></body>
<!--The CSS color property defines the text color for an HTML element:-->
<h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
<!--The CSS font-family property defines the font to be used for an HTML element:-->
<h1 style="font-family:verdana;">This is a heading</h1>
<!--The CSS font-size property defines the text size for an HTML element:-->
<h1 style="font-size:300%;">This is a heading</h1>
<!--The CSS font weight defines the thickness of the letters-->
<h1 style="font-weight: 100;">This is a heading</h1>
<!--The CSS line height defines the spacing between the lines vertically-->
<h1 style="line-height: 50%;">This is a heading</h1>
<!--The CSS text transform defines the text font to either be: Uppercase, Lowercase or to Capitalize-->
<h1 style="text-transform: capitalize;">This is a heading</h1>
<!--The CSS text-align property defines the horizontal text alignment for an HTML element:-->
<h1 style="text-align:center;">Centered Heading</h1>
<!--You can set the color of borders:-->
<h1 style="border:2px solid Tomato;">Hello World</h1>
<h1 style="border:2px solid DodgerBlue;">Hello World</h1>
<h1 style="border:2px solid Violet;">Hello World</h1>
<!--Colors types in CSS-->
<!--In HTML, colors can also be specified using RGB values, HEX values, HSL values, RGBA values, and HSLA values.-->
<h1 style="background-color:rgb(255, 99, 71);">...</h1>
<h1 style="background-color:#ff6347;">...</h1>
<h1 style="background-color:hsl(9, 100%, 64%);">...</h1>
<h1 style="background-color:rgba(255, 99, 71, 0.5);">...</h1>
<h1 style="background-color:hsla(9, 100%, 64%, 0.5);">...</h1>
<!--Background In CSS-->
<!--In CSS you can use background images and manipulate them in certain ways-->
body{
background-image:url(link to image);
}
<!--You can also change the background to repeat itself to fill the page, set its position and if it stays attached while scrolling-->
body{
background-image:url(link to image);
background-repeat:no-repeat;
background-position:left;
background-attachment:fixed;
}
<!--Using CSS-->
<!--
Inline - by using the style attribute inside HTML elements
Internal - by using a <style> element in the <head> section
External - by using a <link> element to link to an external CSS file
-->
<!--An inline CSS is used to apply a unique style to a single HTML element.
An inline CSS uses the style attribute of an HTML element.
The following example sets the text color of the <h1> element to blue, and the text color of the <p> element to red:-->
<h1 style="color:blue;">A Blue Heading</h1>
<p style="color:red;">A red paragraph.</p>
<!--An internal CSS is used to define a style for a single HTML page.
An internal CSS is defined in the <head> section of an HTML page, within a <style> element.
The following example sets the text color of ALL the <h1> elements (on that page) to blue, and the text color of ALL the <p> elements to red.
In addition, the page will be displayed with a "powderblue" background color: -->
<head>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<!--External CSS-->
<!--An external style sheet is used to define the style for many HTML pages.
To use an external style sheet, add a link to it in the <head> section of each HTML page:-->
<head>
<link rel="stylesheet" href="styles.css">
</head>
<!--The external style sheet can be written in any text editor. The file must not contain any HTML code,
and must be saved with a .css extension.
Here is what the "styles.css" file looks like:-->
body {
background-color: powderblue;
}
h1 {
color: blue;
}
p {
color: red;
}
<!--External style sheets can be referenced with a full URL or with a path relative to the current web page.-->
<link rel="stylesheet" href="https://www.w3schools.com/html/styles.css">
<link rel="stylesheet" href="/html/styles.css">
<link rel="stylesheet" href="styles.css">
<!--CSS Colors, Fonts and Sizes-->
<!--Here, we will demonstrate some commonly used CSS properties. You will learn more about them later.
The CSS color property defines the text color to be used.
The CSS font-family property defines the font to be used.
The CSS font-size property defines the text size to be used.-->
<style>
h1 {
color: blue;
font-family: verdana;
font-size: 300%;
}
p {
color: red;
font-family: courier;
font-size: 160%;
}
</style>
<!--find the output from Google Fonts that you previously saved. If you've not already chosen a font, follow the link and do it now.
Add the <link> elements inside your index.html's <head>, just before the closing </head> tag. They should look something like this-->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100..900;1,100..900&display=swap"
rel="stylesheet" />
html {
/* px means "pixels". The base font size is now 10 pixels high */
font-size: 10px;
/* Replace PLACEHOLDER with the font-family property value you got from Google Fonts */
font-family: PLACEHOLDER;
}
<!--The CSS border property defines a border around an HTML element.
Tip: You can define a border for nearly all HTML elements.-->
p {
border: 2px solid powderblue;
}
<!--The CSS padding property defines a padding (space) between the text and the border.-->
p {
border: 2px solid powderblue;
padding: 30px;
}
<!--The CSS margin property defines a margin (space) outside the border.-->
p {
border: 2px solid powderblue;
margin: 50px;
}
<!--The CSS border radius defines a radius around the image which will be cut and make it round-->
p{
border-radius:50px;
}
<!--Formatting-->
<b> - Bold text
<strong> - Important text
<i> - Italic text
<em> - Emphasized text
<mark> - Marked text
<small> - Smaller text
<del> - Deleted text
<ins> - Inserted text
<sub> - Subscript text
<sup> - Superscript text
<!--The HTML <strong> element defines text with strong importance. The content inside is typically displayed in bold.-->
<strong>This text is important!</strong>
<!--The <i> tag is often used to indicate a technical term, a phrase from another language, a thought, a ship name, etc.-->
<i>This text is italic</i>
<!--A screen reader will pronounce the words in <em> with an emphasis, using verbal stress.-->
<em>This text is emphasized</em>
<!--The HTML <small> element defines smaller text:-->
<small>This is some smaller text.</small>
<!--The HTML <mark> element defines text that should be marked or highlighted:-->
<p>Do not forget to buy <mark>milk</mark> today.</p>
<!--The HTML <del> element defines text that has been deleted from a document. Browsers will usually strike a line through deleted text:-->
<p>My favorite color is <del>blue</del> red.</p>
<!--The HTML <ins> element defines a text that has been inserted into a document. Browsers will usually underline inserted text:-->
<p>My favorite color is <del>blue</del> <ins>red</ins>.</p>
<!--he HTML <sub> element defines subscript text. Subscript text appears half a character below the normal line,
and is sometimes rendered in a smaller font. Subscript text can be used for chemical formulas, like H2O:-->
<p>This is <sub>subscripted</sub> text.</p>
<!--The HTML <sup> element defines superscript text. Superscript text appears half a character above the normal line,
and is sometimes rendered in a smaller font. Superscript text can be used for footnotes, like WWW[1]:-->
<p>This is <sup>superscripted</sup> text.</p>
<!--Quotations-->
<!--The HTML <blockquote> element defines a section that is quoted from another source.
Browsers usually indent <blockquote> elements.-->
<p>Here is a quote from WWF's website:</p>
<blockquote cite="http://www.worldwildlife.org/who/index.html">
</blockquote>
<!--The HTML <q> tag defines a short quotation.
Browsers normally insert quotation marks around the quotation.-->
<p>WWF's goal is to: <q>Build a future where people live in harmony with nature.</q></p>
<!--The HTML <abbr> tag defines an abbreviation or an acronym, like "HTML", "CSS", "Mr.", "Dr.", "ASAP", "ATM".
Marking abbreviations can give useful information to browsers, translation systems and search-engines.
Tip: Use the global title attribute to show the description for the abbreviation/acronym when you mouse over the element. -->
<p>The <abbr title="World Health Organization">WHO</abbr> was founded in 1948.</p>
<!--The HTML <address> tag defines the contact information for the author/owner of a document or an article.
The text in the <address> element usually renders in italic, and browsers will always add a line break before and after the <address> element.-->
<address>
Written by John Doe.<br>
Visit us at:<br>
Example.com<br>
Box 564, Disneyland<br>
USA
</address>
<!--he HTML <cite> tag defines the title of a creative work (e.g. a book, a poem, a song, a movie, a painting, a sculpture, etc.).
A person's name is not the title of a work.
The text in the <cite> element usually renders in italic.-->
<p><cite>The Scream</cite> by Edvard Munch. Painted in 1893.</p>
<!--BDO stands for Bi-Directional Override.
The HTML <bdo> tag is used to override the current text direction:-->
<bdo dir="rtl">This text will be written from right to left</bdo>