HTML
HTML
What is HTML?
HTML is a language for describing web pages.
HTML Tags
HTML markup tags are usually called HTML tags.
HTML tags are keywords (tag names) surrounded by angle brackets like <html>
HTML tags normally come in pairs like <p> and </p>
The first tag in a pair is the start tag, the second tag is the end tag
The end tag is written like the start tag, with a slash before the tag name
Start and end tags are also called opening tags and closing tags
<tagname>content</tagname>
HTML Elements
In HTML, most elements are written with a start tag (e.g. <p>) and an end tag (e.g. </p>),
with the content in between:
<p>This is a paragraph.</p>
HTML Element Syntax
An HTML element starts with a start tag / opening tag
An HTML element ends with an end tag / closing tag
The element content is everything between the start and the end tag
Some HTML elements have empty content
Empty elements are closed in the start tag
Most HTML elements can have attributes
The browser does not display the HTML tags, but uses the tags to determine how the
content of the HTML page is to be presented/displayed to the user.
HTML Attributes
Attributes provide additional information about HTML elements.
• The BODY element of a web page is an important element in regards to the page’s appearance.
Here are the attributes of the BODY tag to control all the levels:
TEXT="#RRGGBB" to change the color of all the text on the page (full page text color.)
This element contains information about the page’s background color, the background image, as
well as the text and link colors.
• Background Color
It is very common to see web pages with their background color set to white or some other
colors.
To set your document’s background color, you need to edit the <BODY> element by adding the
BGCOLOR attribute. The following example will display a document with a white background
color:
<BODY BGCOLOR=“#FFFFFF”></BODY>
• TEXT Color
The TEXT attribute is used to control the color of all the normal text in the document. The
default color for text is black. The TEXT attribute would be added as follows:
In this example the document’s page color is white and the text would be red.
The BODY element also gives ability of setting an image as the document’s background.
1. H1: should be used as the highest level of heading, H2 as the next highest, and so forth.
2. You should not skip heading levels: e.g., an H3 should not appear after an H1, unless there is an
H2 between them.
<HTML>
<HEAD>
<TITLE> Example Page</TITLE>
</HEAD>
<BODY>
<H1> Heading 1 </H1>
<H2> Heading 2 </H2>
<H3> Heading 3 </H3>
<H4> Heading 4 </H4>
<H5> Heading 5 </H5>
<H6> Heading 6 </H6>
</BODY>
</HTML>
Paragraphs allow you to add text to a document in such a way that it will automatically adjust
the end of line to suite the window size of the browser in which it is being displayed. Each line of
text will stretch the entire length of the window.
Break, <BR>
Line breaks allow you to decide where the text will break on a line or continue to the end of the
window.
A <BR> is an empty Element, meaning that it may contain attributes but it does not contain
content.
• Break, <BR>
<HTML>
<HEAD>
<TITLE> Example Page</TITLE>
</HEAD>
<BODY>
<H1> Heading 1 </H1>
<P>Paragraph 1, <BR>
Line 2 <BR> Line 3 <BR>….
</P>
</BODY>
</HTML>
Horizontal Rule, <HR>
The <HR> element causes the browser to display a horizontal line (rule) in your document.
<HTML>
<HEAD>
<TITLE> Example Page</TITLE>
</HEAD>
<BODY>
<H1> Heading 1 </H1>
<P>Paragraph 1, <BR>
Line 2 <BR>
<HR>Line 3 <BR>
</P>
</BODY>
</HTML>
Character Formatting
To enhance your page with Bold, Italics, and other character formatting options.
The size attribute can be set as an absolute value from 1 to 7 or as a relative value using the “+”
or “-” sign. Normal text size is 3 (from -2 to +4).
Color = “#RRGGBB” The COLOR attribute of the FONT element. E.g., <FONT
COLOR=“#RRGGBB”>this text has color</FONT>
<PRE> Preformatted </PRE> Text enclosed by PRE tags is displayed in a mono-spaced font.
Spaces and line breaks are supported without additional elements or special characters.
<TT> TELETYPE </TT> Text is displayed in a mono-spaced font. A typewriter text, e.g. fixed-width
font.
<CITE> Citation </CITE> represents a document citation (italics). For titles of books, films, etc.
Typically displayed in italics. (A Beginner's Guide to HTML)
<EM> Emphasized</EM> - <STRONG> Strong </STRONG> - <TT> Tele Type </TT> <BR>
Alignment
Some elements have attributes for alignment (ALIGN) e.g. Headings, Paragraphs and Horizontal
Rules.
<DIV ALIGN=“value”></DIV> Represents a division in the document and can contain most other
element type. The alignment attribute of the DIV element is well supported.
<TABLE></TABLE> Inside a TABLE, alignment can be set for each individual cell.
These Characters are recognized in HTML as they begin with an ampersand and end with a semi-
colon e.g. &value; The value will either be an entity name or a standard ASCII character number.
They are called escape sequences.
• The next table represents some of the more commonly used special characters.
• ñ
• È
NOTE: Unlike the rest of HTML, the escape sequences are case sensitive. You cannot, for instance, use
< instead of <.
• Example
Lists
HTML supplies several list elements. Most list elements are composed of one or more <LI> (List
Item) elements.
UL : Unordered List. Items in this list start with a list mark such as a bullet. Browsers will usually
change the list mark in nested lists.
<UL>
<LI> List item …</LI>
<LI> List item …</LI>
</UL>
List Elements
You have the choice of three bullet types: disc(default), circle, square.
These are controlled in Netscape Navigator by the “TYPE” attribute for the <UL> element.
<UL TYPE=“square”>
<LI> List item …</LI>
<LI> List item …</LI>
<LI> List item …</LI>
</UL>
OL: Ordered List. Items in this list are numbered automatically by the browser.
<OL>
<LI> List item …</LI>
<LI> List item …</LI>
<LI> List item …</LI>
</OL>
The choice of setting the TYPE Attribute to one of five numbering styles.
<DL>
<DT> HTML </DT>
<DD> Hyper Text Markup Language </DD>
<DT> DOG </DT>
<DD> A human’s best friend!</DD>
</DL>
Nesting Lists
Nesting lists by inserting a UL, OL, etc., inside a list item (LI).
EXample
Image File (SRC:source): This value will be a URL (location of the image) E.g.
http://www.domain.com/dir/file.ext or /dir/file.txt.
Alternate Text (ALT): This is a text field that describes an image or acts as a label. It is displayed
when they position the cursor over a graphic image.
Alignment (ALIGN): This allows you to align the image on your page.
HSPACE: is for Horizontal Space on both sides of the image specified in pixels. A setting of 5 will
put 5 pixels of invisible space on both sides of the image.
VSPACE: is for Vertical Space on top and bottom of the image specified in pixels. A setting of 5
will put 5 pixels of invisible space above and bellow the image.
• TO MAKE A LINK
1) The tags used to produce links are the <A> and </A>. The <A> tells where the link should start and
the </A> indicates where the link ends. Everything between these two will work as a link.
2) The example below shows how to make the word ‘Here’ work as a link to yahoo.
• More on LINKs
• LINK - standard link - to a page the visitor hasn't been to yet. (standard color is blue -
#0000FF).
VLINK - visited link - to a page the visitor has been to before. (standard color is purple -
#800080).
ALINK - active link - the color of the link when the mouse is on it. (standard color is red -
#FF0000).
Image Maps
Image maps are images, usually in gif format that have been divided into regions; clicking in a
region of the image cause the web surfer to be connected to a new URL. Image maps are
graphical form of creating links between pages.
Both types of image maps involve a listing of co-ordinates that define the mapping regions and which
URLs those coordinates are associated with. This is known as the map file.
Client-side image maps (USEMAP) use a map file that is part of the HTML document (in an
element called MAP), and is linked to the image by the Web browser.
<MAP NAME="map1">
<AREA SHAPE="RECT" COORDS="0,0,90,90"
HREF="hi.html" ALT="see me…">
<AREA SHAPE="RECT" COORDS="100,100,160,160"
HREF="divPara.html" ALT="see him…" >
<AREA SHAPE="CIRCLE" COORDS="150,50,20"
HREF="house.html" ALT="see it…" >
</MAP>
Shapes, Coords
• Types of Shapes
• Poly à depends on the number of corners of the shape( 2 numbers for each
corner)
Tables
1. Table Row<TR></TR>.
4. Caption <CAPTION></CAPTION>.
The table row elements usually contain table header elements or table data elements.
<table border=“1”>
<tr>
<th> Column 1 header </th>
<th> Column 2 header </th>
</tr>
<tr>
<td> Row1, Col1 </td>
<td> Row1, Col2 </td>
</tr>
<tr>
<td> Row2, Col1 </td>
<td> Row2, Col2 </td>
</tr>
</table>
• Tables
• Tables Attributes
Width: you can specify the table width as an absolute number of pixels or a percentage of the
document width. You can set the width for the table cells as well.
Border: You can choose a numerical value for the border width, which specifies the border in
pixels.
CellSpacing: Cell Spacing represents the space between cells and is specified in pixels.
• Table Attributes
CellPadding: Cell Padding is the space between the cell border and the cell contents and is
specified in pixels.
BorderColor, BorderColorDark.
• Table Caption
A table caption allows you to specify a line of text that will appear centered above or bellow the
table.
The Caption element has one attribute ALIGN that can be either TOP (Above the table) or
BOTTOM (below the table).
• Table Header
Table Data cells are represented by the TD element. Cells can also be TH (Table Header)
elements which results in the contents of the table header cells appearing centered and in bold
text.
Colspan: Specifies how many cell columns of the table this cell should span.
Rowspan: Specifies how many cell rows of the table this cell should span.
Width: you can specify the width as an absolute number of pixels or a percentage of the
document width.
Height: You can specify the height as an absolute number of pixels or a percentage of the
document height.
Frames
A framed page is actually made up of multiple HTML pages. There is one HTML document that
describes how to break up the single browser window into multiple windowpanes. Each
windowpane is filled with an HTML document.
For Example to make a framed page with a windowpane on the left and one on the right
requires three HTML pages. Doc1.html and Doc2.html are the pages that contain content.
Frames.html is the page that describes the division of the single browser window into two
windowpanes.
A <FRAMESET> element is placed in the html document before the <BODY> element. The
<FRAMESET> describes the amount of screen real estate given to each windowpane by dividing
the screen into ROWS or COLS.
The <FRAMESET> will then contain <FRAME> elements, one per division of the browser
window.
Note: Because there is no BODY container, FRAMESET pages can't have background images and
background colors associated with them.
<HTML>
<HEAD>
<TITLE> Framed Page </TITLE>
<FRAMeSET COLS=“23%,77%”>
<FRAME SRC=“Doc1.html”>
<FRAME SRC=“Doc2.html”>
</FRAMeSET >
</HEAD>
</HTML>
<FRAMESET> Container
<FRAMESET> : The FRAMESET element creates divisions in the browser window in a single direction.
This allows you to define divisions as either rows or columns.
ROWS : Determines the size and number of rectangular rows within a <FRAMESET>. They are
set from top of the display area to the bottom.
Proportional values using the asterisk (*). This is often combined with a value in pixels , e.g.
“360,*”.
<Frameset cols=“200,20%,*,2*”>
COLS: Determines the size and number of rectangular columns within a <FRAMESET>. They are
set from left to right of the display area.
Proportional values using the asterisk (*). This is often combined with a value in pixels , e.g.
“480,*”.
FRAMEBORDER : Possible values 0, 1, YES, NO. A setting of zero will create a borderless frame.
FRAMESPACING: This attribute is specified in pixels. If you go to borderless frames you will need
to set this value to zero as well, or you will have a gap between your frames where the border
used to be.
BORDER(thickness of the Frame): This attribute specified in pixels. A setting of zero will create a
borderless frame. Default value is 5.
BORDERCOLOR: This attribute is allows you choose a color for your border. This attribute is
rarely used.
<FRAME>
<FRAME>: This element defines a single frame within a frameset. There will be a FRAME element for
each division created by the FRAMESET element. This tag has the following attributes:
SRC: Required, as it provides the URL for the page that will be displayed in the frame.
NAME: Required for frames that will allow targeting by other HTML documents. Works in
conjunction with the target attribute of the <A>, <AREA>, <BASE>, and <FORM> tags.
MARGINWIDTH: Optional attribute stated in pixels. Determines horizontal space between the
<FRAME> contents and the frame’s borders.
MARGINHEIGHT: Optional attribute stated in pixels. Determines vertical space between the
<FRAME> contents and the frame’s borders.
<FRAME>
NORESIZE: Optional – prevents viewers from resizing the frame. By default the user can stretch
or shrink the frame’s display by selecting the frame’s border and moving it up, down, left, or
right.
<NOFRAMES>
<NOFRAMES>: Frame – capable browsers ignore all HTML within this tag including the contents
of the BODY element. This element does not have any attributes.
<HTML>
<HEAD>
<TITLE> Framed Page </TITLE>
</HEAD>
• <NOFRAMES>
<FRAMESET COLS="23%,77%">
<FRAME SRC="" NAME="left_pane“>
<FRAME SRC="" NAME="right_pane">
<NOFRAMES>
<P> This is a Framed Page. Upgrade your browser to support frames.</P>
</NOFRAMES></FRAMESET>
In this case a second FRAMESET element will be inserted in the place of the FRAME element
that would describe the second row.
The second FRAMESET element will divide the remaining screen real estate into 2 columns.
This nested FRAMESET will then be followed by 2 FRAME elements to describe each of the
subsequent frame divisions created.
<html>
<head>
<title> Compound Frames Page</title>
</head>
<frameset rows=“120,*”>
<frame src=“banner_file.html” name”banner”>
<frameset cols=“120,*”>
<frame src=“links_file.html” name=“links”>
<frame src=“content_file.html” name=“content”>
<noframes>
<p>
Default message
</p>
</noframes>
</frameset>
</frameset>
</head>
<HEAD>
<FRAMESET ROWS="25%,50%,25%”
<FRAME SRC="">
<FRAMESET COLS="25%,*">
<FRAME SRC="">
<FRAME SRC="">
</FRAMESET>
<FRAME SRC="">
</FRAMESET>
</HEAD>
Frame Formatting
• Example:
So what are the space-allocation priorities? Absolute pixel values are always assigned space first, in
order from left to right. These are followed by percentage values of the total space. Finally, proportional
values are divided based upon what space is left.
• The <FRAME> tag has six associated attributes: SRC, NAME, MARGINWIDTH, MARGINHEIGHT,
SCROLLING, and NORESIZE. Here's a complete generic FRAME:
NORESIZE>
<FRAME SRC=“”>
<FRAME SRC=“”>
<FRAME SRC=“”>
<FRAME SRC=“”>
<FRAME SRC=“”>
<FRAME SRC=“”>
</FRAMESET>
• Targets
When you use links for use in a frames environment you will need to specify an additional
attribute called TARGET.
The TARGET attribute uses the NAME attribute of the FRAME element.
If we were to place a link in doc1.html that linked to doc3.html and we wanted doc3.html to be
displayed in the right windowpane; the HTML code would appear in doc1.html as follows:
• Special Targets
• There are 4 special target names that cannot be assigned by the NAME attribute of the FRAME
tag.
1. TARGET=“_top” :
This loads the linked document into the full browser window with the URL specified by the HREF
attribute. All frames disappear, leaving the new linked page to occupy the entire window. The back is
turned on.
2. TARGET=“_blank” :
Opens an unnamed new browser window and loads the document specified in the URL attribute into the
new window (and your old window stays open). The back is turned off. Other windows remains on.
3. TARGET=“_self” :
Loads the document in the same window where the anchor was {Clicked}. This is the default setting for
linking elements.
4. TARGET=“_parent” :
the _parent frame is a prior frameset that the current frameset was “spawned” from. If there isn’t one it
is the browser window. The document is loaded into the area occupied by the columns or rows frameset
containing the frame that contains the link. The back is turned on. All windows disappear.
• Forms
Forms add the ability to web pages to not only provide the person viewing the document with
dynamic information but also to obtain information from the person viewing it, and process the
information.
Objectives:
1. Create a FORM.
• Forms
To insert a form we use the <FORM></FORM> tags. The rest of the form elements must be
inserted in between the form tags.
<HTML> <HEAD>
</HEAD>
<BODY BGCOLOR=“FFFFFF”>
</FORM>
</BODY> </HTML>
ACTION: is the URL of the CGI (Common Gateway Interface) program that is going to accept the
data from the form, process it, and send a response back to the browser.
METHOD: GET (default) or POST specifies which HTTP method will be used to send the form’s
contents to the web server. The CGI application should be written to accept the data from either
method.
JavaScripts.
TARGET: is the target frame where the response page will show up.
• Form Elements
Form elements have properties: Text boxes, Password boxes, Checkboxes, Option(Radio)
buttons, Submit, Reset, File, Hidden and Image.
The properties are specified in the TYPE Attribute of the HTML element <INPUT></INPUT>.
• Form Elements
• Text Box
Text boxes: Used to provide input fields for text, phone numbers, dates, etc.
TYPE: text.
MAXLENGHT : determines the maximum number of characters that the field will accept.
<TITLE>Form_Text_Type</TITLE>
</HEAD> <BODY>
<FORM name="fome1" Method= " get " Action= " URL " >
SIZE="15" MAXLENGTH="25"><BR>
SIZE="15" MAXLENGTH="25"><BR>
SIZE="25" MAXLENGTH="25"><BR>
SIZE="15" MAXLENGTH="12"><BR>
• Password
display.
TYPE: password.
<HTML><HEAD>
<TITLE>Form_Password_Type</TITLE></HEAD>
<BODY>
enter:</font></h1>
SIZE="15" MAXLENGTH="25"><BR>
MAXLENGTH="25"><BR>
</FORM></BODY> </HTML>
• Output
• Hidden
Hidden: Used to send data to the CGI application that you don’t want the web surfer to see,
change or have to enter but is necessary for the application to process the form correctly.
<INPUT TYPE=“HIDDEN”>
TYPE: hidden.
• Check Box
Check Box: Check boxes allow the users to select more than one option.
<INPUT TYPE=“CHECKBOX”>
TYPE: checkbox.
status.
CGI application.
• Output
• Radio Button
TYPE: radio.
checked
CGI application.
• Output
• Push Button
<INPUT TYPE=“BUTTON”>
TYPE: button.
in scripting.
<DIV align=center><BR><BR>
<FORM>
<FONT Color=red>
<FONT Color=blue>
<FONT Color=green>
<FONT Color=yellow>
</FORM></DIV>
• Submit Button
Submit: Every set of Form tags requires a Submit button. This is the element causes the browser
to send the names and values of the other elements to the CGI Application specified by the
ACTION attribute of the FORM element.
<INPUT TYPE=“SUBMIT”>
TYPE: submit.
VALUE: determines the text label on the button, usually Submit Query.
• Reset Button
• Reset: It is a good idea to include one of these for each form where users are entering data. It
allows the surfer to clear all the input in the form.
• <INPUT TYPE=“RESET”>
• TYPE: reset.
• VALUE: determines the text label on the button, usually Reset.
Image Submit Button: Allows you to substitute an image for the standard submit button.
TYPE: Image.
• <form>
<H1><font color=blue>
Click to go Jordan’s Map:
<INPUT TYPE="IMAGE" SRC="jordan.gif">
</form>
• File
• File Upload: You can use a file upload to allow surfers to upload files to your web server.
• <INPUT TYPE=“FILE”>
• TYPE: file.
CGI application.
textbox in characters.
<BODY bgcolor=lightblue>
<form>
<H3><font color=forestgreen>
Please attach your file here to for uploading to
</form>
</BODY>
The two following examples are <SELECT></SELECT> elements, where the attributes are set
differently.
MULTIPLE: the presence of this attribute signifies that the user can make multiple selections. By
default only one selection is allowed.
Size: 1.
Option
The list items are added to the <SELECT> element by inserting <OPTION></OPTION> elements.
SELECTED: When this attribute is present, the option is selected when the document is initially
loaded. It is an error for more than one option to be selected.
VALUE: Specifies the value the variable named in the select element.
</HEAD>
<BODY>
<FORM>
<OPTION
value="IBM" SELECTED> IBM</OPTION>
<OPTION
value="INTEL"> INTEL</OPTION>
<OPTION value="
Apple"> Apple</OPTION>
<OPTION
value="Compaq"> Compaq</OPTION>
</SELECT>
</FORM></BODY></HTML>
<HEAD> <TITLE>SELECT with Mutiple </TITLE> </HEAD>
<BODY>
<FORM>
<OPTION
value="IBM" > IBM</OPTION>
<OPTION
value="INTEL"> INTEL</OPTION>
<OPTION value="
Apple"> Apple</OPTION>
<OPTION
value="Compaq" SELECTED> Compaq</OPTION>
<OPTION value="
other"> Other</OPTION>
</SELECT>
</FORM></BODY></HTML>