Chapter02 HTML
Chapter02 HTML
2
HTML (Hyper Text Markup Language)
What is HTML?
Tags are ;
surrounded with angle brackets like this
<B> or <I>.
Most tags come in pairs
exceptions: <P>, <br>, <li> tags …
The first tag turns the action on, and the second turns it off.
3
HTML
4
Structural Tags
<HTML>
These tags enclose the entire Web page document.
</HTML>
<HEAD>
These tags enclose the Head part of the document. Within the head, more tags
can be used to specify title of the page, meta-information, etc.
</HEAD>
<TITLE>
These tags enclose the title of the document. This text appears in the title bar in
the browser and on the bookmark list if someone bookmarks your web page.
</TITLE>
Our First Example
• If you are running Windows, start Notepad
• If you are on a Mac, start SimpleText
• If you telnet to csupomona.edu, use “pico”
• Type in the following:
<html>
<head>
<title>Title of page</title>
</head>
<body>
This is my first homepage. <b>This text is bold</b>
• Open this file using a browser, and you will see…
</body>
</html>
• <title>
• defines a title in the browser tab
• provides a title for the page when it is added to favourites
• displays a title for the page in search engine results
HTML
7
HTML
Basic HTML Document Format
<html>
<html>
<title>personal
<title>personal website</title>
website</title> See what it
<body
<body bgcolor="SILVER">
bgcolor="SILVER"> looks like:
<center><h1><FONT
<center><h1><FONT
COLOR="RED">SRM
COLOR="RED">SRM
UNIVERSITY</FONT></h1></center
UNIVERSITY</FONT></h1></center
>>
</body>
</body>
</html>
</html>
11
Breaking Lines and Paragraphs
Example: text a
<p>text a</p>
<p>text b</p> text b
<br>text c
<br>text d text c
text d
Text Formatting Tags
Tag Result
Web creators can also change the way text looks by using the <FONT> tag
Big Small
<html>
<head>
<title>Page Title</title>
</head>
<body bgcolor=“grey”>
<h1><font color=“red” size=7>This is a Heading</font></h1>
<p><font color=“blue”>This is a paragraph.</font></p>
</body>
</html>
Lists -- Unordered Lists
Unordered lists:
<UL>
<LI>Item One • Item One
<LI>Item Two • Item Two
<LI>Item Three • Item Three
<LI>Item Four • Item Four
</UL>
This attribute lets you specify which number/letter will start the list
Anchor <a> tab(Links)
The anchor tag <A> is used to link one document to another or from one part of a
document to another part of the same document.
Basic Links:
<A HREF="http://www.srmap.edu.in/">SRM University-AP</A>
Email links:
<A HREF="mailto:[email protected]">Email
[email protected]</A>
Graphics
To have a graphic appear on a webpage, web designers must to put the <IMG> tag
in with the address where the graphic "lives":
<IMG SRC="http://www.someplace.com/images/fish.gif">
Graphics attributes:
width="xx/xx%": width in pixels/percentage
height="xx/xx%": height in pixels/percentage
border="xx": pixel length of the border surrounding the image.
hspace="xx": places a buffer of space horizontally around the image
vspace="xx": places a buffer of space vertically around the image
align="top/middle/bottom/right/left": aligns image in relation to the text (see next 2 slides)
Graphics (cont.)
<html>
<title>personal website</title>
<body bgcolor=000000>
<h1><FONT COLOR="RED">SRM UNIVERSITY</FONT></h1>
<hr size=10 align="left" width=10>
</body>
</html>
<pre> tag
<html>
<title>personal website</title>
<body>
<h1><FONT COLOR="RED">SRM UNIVERSITY</FONT></h1>
<pre>
SRM University, Andhra Pradesh (SRM AP), also known as SRM University, Amaravati, is
a private university[3] located near Neerukonda village in Mangalagiri mandal of
Guntur district in Andhra Pradesh, India, in the area of the planned capital city
Amaravati. The university was established in 2017 by the SRM Trust through the
Andhra Pradesh Private Universities (Establishment and Regulation) Act, 2016.[4] It
offers undergraduate, postgraduate courses and Ph.D programmes in engineering,
liberal arts and basic sciences.[5]
</pre>
</body>
</html>
Defining a Table Structure
25
Using the <table>,
<tr>, and <td> Tags
• Graphical tables are enclosed within a two-sided <table> tag that
identifies the start and ending of the table structure.
• Each row of the table is indicated using a two-sided <tr> (for table
row).
• Within each table row, a two-sided <td> (for table data) tag
indicates the presence of individual table cells.
26
The General Table Syntax
<table border=1>
<tr>
<td> First Cell </td>
<td> Second Cell </td>
</tr>
<tr>
<td> Third Cell </td>
<td> Fourth Cell </td>
</tr>
</table>
two rows
two columns
27
Columns within a Table
28
HTML Structure of a Table
beginning of the
table structure
table cells
29
Creating Headings with the <th> Tag
30
Adding Table Headings to the Table
Text in cells formatted
with the <th> tag is bold
and centered above each
table column.
table
headings
31
Creating a Table Caption
• HTML allows you to specify a caption for a table.
• The syntax for creating a caption is: <caption
align=“alignment”>caption text</caption>
• alignment indicates the caption placement
• a value of “bottom” centers the caption below the table
• a value of “top” or “center” centers the caption above the table
• a value of “left” or “right” place the caption above the table to
the left or right
• The <caption> tag works only with tables, the tag must be
placed within the table structure.
• Captions are shown as normal text without special formatting.
• Captions can be formatted by embedding the caption text
within other HTML tags.
• for example, place the caption text within a pair of <b> and <i>
tags causes the caption to display as bold and italic 32
Result of a Table Caption
caption text
caption will be
centered above
the table
33
Modifying the Appearance of a Table
34
Adding a Table Border
35
Tables with Different Borders Values
This figure shows the effect on a table’s border when the border size is varied.
36
Adding a 5-Pixel Border to a Table
37
Controlling Cell Spacing
<table cellspacing=“value”>
38
Defining Cell Padding
• To control the space between the table text and the cell borders, add the
cellpadding attribute to the table tag.
• The syntax for this attribute is:
<table cellpadding=“value”>
• value is the distance from the table text to the cell border, as measured in pixels
• the default cell padding value is 1 pixel
39
Tables with Different
Cell Spacing Values
different cell spacing values
40
<rule> attribute
• The rule attribute lets you control how the table gridlines are drawn.
• The syntax of the rules attribute is:
<table rules=“type”>
• type is either “all”, “rows”, “cols”, or “none”
41
Working with Table and Cell Size
43
Setting the Width of the
Table to 500 Pixels
44
Defining Cell and Column Sizes
• To set the width of an individual cell, add the width attribute to
either the <td> or <th> tags.
• The syntax is: width=“value”
• value can be expressed in pixels or as a percentage of the table
width
• The height attribute can also be used in the <td> or <th> tags
to set the height of individual cells.
• The height attribute is expressed either in pixels or as a percentage
of the height of the table.
45
Aligning a Table on the Web Page
46
Results of a Right-Aligned Table
47
Values of the Align
and Valign Attributes
48
Spanning Rows and Columns
• To merge several cells into one, you need to create a spanning cell.
• A spanning cell is a cell that occupies more than one row or column
in a table.
• Spanning cells are created by inserting the rowspan and colspan
attribute in a <td> or <th> tag.
• The syntax for these attributes is: rowspan=“value”
colspan=“value”
• value is the number of rows or columns that the cell
spans in the table
49
A Table Structure with a
Row-Spanning Cell
four table cells
in the first row
HTML code
resulting table
50
Adding Spanning Cells to a Table
51
Another Example of Spanning Cells
52
Another Example of Spanning Cells
53
Try yourself
This cell
spans two this cell
columns and spans three
two rows columns
This cell
spans three
rows
54
Applying a Background Color
55
Specifying Table, Row, and Cell Colors
The bordercolor Attribute
• By default, table borders are displayed in two shades of gray
that create a three-dimensional effect.
• The syntax for the bordercolor attribute is:
<table bordercolor=“color”>
• color is an HTML color name or hexadecimal color value
• Internet Explorer and Netscape apply this attribute differently.
parch.jpg
58
Comments in HTML