Handout 02. HTML
Handout 02. HTML
HTML
Objectives
1
9/20/2024
Outline
1. Basic HTML
❖ hypertext
❖ tags & elements
❖ text formatting
❖ lists, hyperlinks, images
❖ tables, frames
2. HTML5
• HyperText Markup Language (HTML) is the language for specifying the static
content of Web pages (based on SGML, the Standard Generalized Markup
Language)
❖ hypertext refers to the fact that Web pages are more than just
text
➢ can contain multimedia, provide links for jumping within the
same document & to other documents
❖ markup refers to the fact that it works by augmenting text with
special symbols (tags) that identify the document structure and
content type
2
9/20/2024
3
9/20/2024
Structural Elements
<html>
<!–- First file----> HTML documents : <html> and </html> tags
<head>
<title>My first HTML document</title> Comments: <!-- and -->
</head>
<body> HEAD section: <head> and </head> tags
<p> Hello world! </p>
</body>
BODY section: <body> and </body>
</html>
view page
view page
• <head> element
• Title
• Cascading Style sheet information
• “Meta” data, such as who authored the page, keywords
• JavaScript code
• The <body> element
• Paragraphs
• Tables and lists
• Images
• JavaScript code
• PHP code
TRƯỜNG CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
School of Information and Communication Technology
4
9/20/2024
Text Layout
❑ For the most part, layout of the text is left to the <html>
<!–- CS443 page02.html 17.09.14 -->
browser <head>
<title>Text Layout</title>
❖ whitespace is interpreted as a single space </head>
</html>
view page
view page
TRƯỜNG CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
School of Information and Communication Technology
<hr/>
</html>
view page
view page
TRƯỜNG CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
School of Information and Communication Technology
10
10
5
9/20/2024
view page
11
11
Text Appearance
<html>
<!–- CS443 page25.html 15.08.06 -->
❑ can specify styles for fonts <head>
<title>Text Variations and Escape
❖<b>… </b> specify bold Sequences</title>
</head>
❖<i>… </i> specify italics <body>
<h1>Text Variations</h1>
❖<big>… </big> increase the size <p>We can use <b>simple</b> tags to
<i>change</i> the appearance of
❖<small>… </small> decrease the size <strong>text</strong> within
<tt>Web pages</tt>.
❖<em>…</em> put emphasis Even super<sup>script</sup>
and sub<sub>scripts</sub> are
<em>supported</em>.</p>
❖<strong>…</strong> put more emphasis
<h1>Text Escape Sequences</h1>
❖<sub>… </sub> specify a subscript <p>
& < > " ©
❖<sup>… </sup> a superscript </p>
<h1>Preformatted text</h1>
<pre>
University of Liverpool
Department of Computer Science
Ashton Building, Ashton Street
Liverpool, L69 3BX, UK
</pre>
</body> view page
12
12
6
9/20/2024
Lists
<html>
❑ There are 3 different types of list elements <!–- CS443page07.html 23.09.08 -->
❖ <ol>…</ol> specifies an ordered list
<head> <title>(Sort of) Simple Lists</title>
<style type="text/css">
➢ <li> identifies each list item .my_li:before { content: counter(list) ": ";
counter-increment: list; }
❖ <ul>…</ul> specifies unordered list (using a bullet </style> </head>
for each) <body>
13
13
Hyperlinks
<head>
❑ <a href="URL">…</a> <title>Hyperlinks</title>
➢ where URL is the Web address of the page </head>
➢ if the page is accessed over the Web, must start with http://
<body>
➢ if not there, the browser will assume it is the name of a local file
<p>
<a href="http://www.liv.ac.uk">
The University of Liverpool</a>
❖ <a href="URL" target="_blank">…</a> <br/>
➢ causes the page to be loaded in a new Window <a href="page07.html"
target="_blank">
Open page07 in a new window</a>
</p>
</body>
</html>
view page
view page
14
14
7
9/20/2024
Hyperlinks (cont.)
<html>
❑ for long documents, you can even have links to <!–- CS443 page09.html 21.09.12 -->
other locations in that same document <head>
<title>Internal Links in a Page</title>
❖ <xxxx id="ident">…</xxxx> </head>
15
15
Images
<html>
<!–- CS443 page10.html 18.09.13 -->
<head>
<title>Image example</title>
</head>
<body>
<img
src="http://www.csc.liv.ac.uk/~martin/teaching/comp519/HTML/Cathedral.jpg"
title="Liverpool's Anglican cathedral"
alt="image of Liverpool's Anglican Cathedral" width="400" />
view page
<img src="URL (or filename)" height="n" width="n" alt="text" title= "text" />
16
16
8
9/20/2024
Images (cont.)
17
17
Tables
<html>
<table>…</table> specify a table element <!–- CS443 page11.html 17.10.14 -->
<head>
<title>Tables</title>
<tr>…</tr> specify a row in the table </head>
<body>
<h2>A Simple Table</h2>
<td>…</td> specify table data (i.e., each column <table>
entry in the table) <tr>
<td> Left Column </td>
<td> Right Column </td>
</tr>
<tr>
<td> Some data </td>
<td> Some other data </td>
</tr>
</table>
</body>
</html>
view page
view page
18
18
9
9/20/2024
Layout in a Table
<html>
❑Border on tables using the “style” attribute <!-- CS443 page12.html 17.10.14 -->
<table style= "border: 1px solid;"> <head>
<title>Table Layout</title>
</head>
❑Horizontal & vertical layout within cells
<td style= "text-align:center"> <body>
<table style="border: 1px solid;">
<td style= "vertical-align: bottom"> <tr style="text-align: center;">
<td style="border: 1px solid;">
Left<br/>Column</td>
❑Layout to an entire row <td style="border: 1px solid;
<tr style="text-align: center"> vertical-align: top;">
Right Column</td>
<tr style="vertical-align: top"> </tr>
<tr>
<td style="border: 1px solid;">
Some data</td>
<td style="border: 1px solid;">
Some data</td>
</tr>
</table>
</body> view page
19
19
Table Width
view page
20
20
10
9/20/2024
</head>
❖Can have data that spans more than one column <body>
<table>
<td colspan="2"> <tr>
<th>HEAD1</th> <th>HEAD2</th>
<th>HEAD3</th>
</tr>
❖Can span more than one row <tr>
<td>one</td> <td>two</td> <td>three</td>
<td rowspan="2"> </tr>
<tr>
<td rowspan="2"> four </td>
<td colspan="2"> five </td>
</tr>
<tr>
<td> six </td> <td> seven </td>
</tr>
</table>
</body> view page
21
21
22
22
11
9/20/2024
❑ Style sheets can be used to specify how tables should be rendered, how lists should be
presented, what colors should be used on the webpage, what fonts should be used and how
big/small they are, etc.
❑ HTML style sheets are known as Cascading Style Sheets, since can be defined at three different
levels
1. inline style sheets apply to the content of a single HTML element
2. document style sheets apply to the whole BODY of a document
3. external style sheets can be linked and applied to numerous documents, might also specify how
things should be presented on screen or in print lower-level style sheets can override higher-level
style sheets
❑ User-defined style sheets can also be used to override the specifications of the webpage
designer. These might be used, say, to make text larger (e.g. for visually-impaired users).
23
23
24
24
12
9/20/2024
view page 25
25
<body>
<table style="font-family:Arial,sans-serif">
<caption style="color:red;
font-style:italic;
text-decoration:underline">
Student data. </caption>
<tr style="background-color:red">
<th> name </th> <th> age </th>
</tr>
<tr>
<td> Chris Smith </td> <td> 19 </td>
</tr>
<tr>
<td> Pat Jones </td> <td> 20 </td>
</tr>
<tr>
<td> Doogie Howser </td> <td> 9 </td>
</tr>
</table>
</body> view page
26
26
13
9/20/2024
27
27
28
28
14
9/20/2024
<head>
❑effectively separates content from presentation <title> Inline Style Sheets </title>
<style type="text/css">
❑ what if you wanted to right-justify the column of table {font-family:Arial,sans-serif}
caption {color:red;
numbers? font-style:italic;
❑ what if you changed your mind?
text-decoration:underline}
th {background-color:red}
</style>
</head>
<body>
<table>
<caption> Student data. </caption>
<tr><th> name </th> <th> age</th></tr>
<tr><td> Chris Smith </td> <td> 19 </td></tr>
<tr><td> Pat Jones </td> <td> 20 </td></tr>
<tr><td> Doogie Howser </td> <td> 9 </td></tr>
</table>
</body>
</html>
view page
view page
29
29
Pseudo-Elements
<html>
❑ pseudo-elements are used to address sub-parts of elements <!–- CS443 page23.html 17.10.14 -->
<body>
<p> Welcome to my Web page. I am so
happy you are here.
</p>
<p> Be sure to visit
<a href="http://www.cnn.com">CNN</a>
for late-breaking news.
</p>
</body>
</html> view page
view page
TRƯỜNG CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
School of Information and Communication Technology
30
30
15
9/20/2024
31
31
<body>
<h1>Centered Title</h1>
32
32
16
9/20/2024
❑ Problem: font properties apply to whole elements, which are often too large
❖ Solution: a new tag to define an element in the content of a larger element - <span>
❖ <span> is an inline element used to mark up a part of text
view page
33
33
Outline
1. Basic HTML
2. HTML5
34
34
17
9/20/2024
35
35
36
36
18
9/20/2024
Article
Footer
Footer
TRƯỜNG CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
School of Information and Communication Technology
37
37
<audio controls="true">
<source src="audiodemo.ogg" />
<source src=" audiodemo.mp3" />
<source src=" audiodemo.wav" />
Not supported.
</audio>
38
38
19
9/20/2024
❑ <canvas> element:
function draw() {
var ctx = document.getElementById('canvas').getContext('2d');
var img = new Image();
img.onload = function(){
ctx.drawImage(img,0,0);
ctx.beginPath();
ctx.moveTo(30,96);
ctx.lineTo(70,66);
ctx.lineTo(103,76);
ctx.lineTo(170,15);
ctx.stroke();
}
img.src = 'images/backdrop.png';
}
39
39
40
40
20