HTML Basics
HTML Basics
1
MARK-U P LANGUAGES
Traditionally used to provide typesetting
information to printers where text should be
indented, margin sizes, bold text, special font
sizes and styles, etc.
Word processors like M S Word, and typesetting
2
HYPERTEXT M ARKUP L A N G UAG E
( H T M L )
describes the structure of the document
has
evolved to version 4.01.
www.w3.org
3
WEB BROWSER
Software when connected to the Internet is able
to access documents at remote locations and
display them locally in accordance with its
interpretation of markup instructions in the
document.
4
H T M L DOCUMENTS
Plain text files, with extension htm or html.
The extension tells the browser interpret the file
according to H T M L standards.
Browsers may display other types of files as well,
5
HTML
DOCUMENTS
No special software is needed; you may use any
plain text editor to create html files manually.
Mac Users:
⚫ TextEdit is all you need but since it is by default a
RTF editor, it must be configured to the plain
text mode in Preferences.
⚫ Textwrangler is one example of a nice alternative for
novice users who is not so comfortable with file
7
format.
A WORD OF CAUTION:
No matter which editor you use, if it is not
strictly plain text, some characters may cause
display errors.
*See their proper application in the "testpage.html" example in the next slide.
11
TEMPLATE
*Use the codes below to begin constructing your assignment document.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>***replace this text with course & section number and your full name
</title>
</head>
<body>
<!--Begin your content specification by adding your elements here. -->
</body>
12
</html>
BASIC H T M L D O C U M E NT
STRUCTURE
Html document consists of the head and the body.
⚫ The head contents are used by the browser/system.
⚫ The body elements are rendered (displayed) by the browser.
<body>
{ Main content here }
</body>
</html> 13
THE H EA D (HEADER)
SECTION
<head> (begin the head section)
</title>
</body>
15
BODY ELEMENTS
html documents consist of a number of elements
where text is placed in containers with a open/begin
tag and an close/end tag (tandem tags)
Invalid:
<p>This overlap is not <em> nested. </p> So it is invalid. </em>
Valid:
<p>This is correct <em>nesting.</em> It is valid.</p>
17
TEXT E L E M E N T
TAGS
18
P R E S E T FORMAT
</blockquote>
19
LISTS: N U M B E R E D O R
BULLETED
{Begin an Ordered List – numbered}
<ol>
<li> … </li> {1st list element}
<li> … </li> {2nd list element}
</ol> {End of Ordered List}
<! This is a comment line: you may place it anywhere in your document; the browser will ignore it.>
<title> H T M L document example</title>
</head>
<body>
<h3> This be a heading level 3</h3>
<p>This is a sentence in this document.</p>
<p>This is another sentence.</p>
<blockquote> <! The list below will be indented.>
<ol>
<li> First list item</li>
<li> Second list item</li>
<li> Third list item</li>
</ol>
</blockquote>
</body>
</html>
21
THE ANCHOR ELEMENT
The anchor element, the tag name, single
letter a, is used to connect or link different
documents or parts of one document.
23
GENERAL
FORM:
<a href = "URL"> anchor text </a>
24
E X A M P L E A (E XTERNAL ):
<a href = "http://www.yorku.ca">York University</a>
25
E X A M P L E B (L OCAL ):
<a href = "faves.html">My Favourite Things </a>
Attributes:
src = "filename…. ": Identifies the file to be
30
E.G. 1
<img src="../pix/selfie01.jpg">
32
E.G. 3
<img src = "/graphics/redbaloon.bmp" align =
"middle" height = "100" width = "200">
Loads a *.bmp file into the document, centers it vertically,
relative to the line, and gives it a height of 100 pixels and a
width of 200 pixels.
35
TA B L E S
Row 1
Row 2
Row 3
36
TABLES
37
TA B L E S
A table is defined by the tandem tag
container <table> … </table> .
<td><center><b> … </b></center></td>
39
Table Format [ 3 columns x 2 Rows ]
<table>
<tr>
<th> Row Header </th> <td> Data </td> <td> Data </td> </tr>
<tr> <td> Data </td> <td> Data </td> <td> Data </td> </tr>
</table>
40
< th > and <td> Attributes:
colspan = "x" : Forces the cell to cover "x" number of columns. Default = 1.
E . G . < td colspan = "3" > . . . </td>
rowspan = "y" : Forces the cell to cover "y" number of rows. Default = 1.
font whatever = ( as desired ) : font attribute such as color, size, family, etc.
41
Other Table Options:
<thead> … </thead>
• Defines a header section. Contains <tr> elements.
• If used, it M U S T precede a
<tbody> … </tbody>
• which contains the usual table rows, and this should be
followed by a footer.
<tfoot> … </tfoot>
42
More Table Format [ 3 columns x 2 Rows ]
<table>
<thead>
<tr> <th colspan = "3" align = "center"> Header </th> </tr>
</thead>
<tbody>
<tr> <th> Row Header </th> <td> Data </td> <td> Data </td> </tr>
<tr> <td> Data </td> <td> Data </td> <td> Data </td> <tr>
</tbody>
<tfoot>
<tr> <th colspan = "3" align = "center"> Footer </th> </tr>
</tfoot>
</table>
43
More Example Specifications
44
Table cells may contain many different
ordinary H T M L containers, making them
quite versatile as aids in layout and design.
Including:
Images
Hypertext Links
Lengthy Text
Other tables
Also, Applets & Objects
45
Table-in-a-table example:
<table>
<tr> <td>
<table>
<tr> <td> <img src = "somepicture.jpg"></td></tr>
<tr> <td><a href = "targetURL">Click ME!</td></tr>
</table>
</td></tr>
</table>
46
Mailto: – Linking to your E-mail client
47
Validating H T M L Codes
• H T M L 4.01 is the last standard version.
49
• If, instead, you see the Nu Html Checker page below, your
document is faulty.
51
• Once your document is error-free, you will see this page
with a green banner.
52
• Copy-paste the codes as the last element of your document;
save the updated version.
53
The index.html file
The file name "index.html", or "index.htm" is
reserved.
This is the file in a directory which will be used
automatically by default if a U R L ends in the
directory name instead of a file name.
On most servers, the use of this file as the default
helps prevent unauthorized access to the directory.
Some servers may have a hierarchy of default file
names.
54