Chapter 1 (Introduction To HTML)
Chapter 1 (Introduction To HTML)
Chapter 1 (Introduction To HTML)
HTML
HTML stands for Hypertext Markup Language, and it is the most widely used
language to write Web Pages.
Hypertext refers to the way in which Web pages (HTML documents) are linked together.
Markup Language which means you use HTML to simply "mark up" a text document with
tags that tell a Web browser how to structure it to display.
Originally, HTML was developed with the intent of defining the structure of
documents like headings, paragraphs, lists, and so forth to facilitate the sharing of
scientific information between researchers.
Now, HTML is being widely used to format web pages with the help of different tags
available in HTML language.
<html>
<head>
</head>
<body>
<h1>Company Profile</h1>
<p>We are a group of Software Professionals working in the field of Information technology.....</p>
</body>
</html>
Save it in an HTML file test.htm using your favorite text editor notepad. Finally open it
using a web browser like Internet Explorer or Google Chrome, or Firefox etc.
HTML Tags
As told earlier, HTML is a markup language and makes use of various tags to format
the content. These tags are enclosed within angle braces <Tag Name>. Except few tags,
most of the tags have their corresponding closing tags. For example <html> has its
closing tag </html> and <body> tag has its closing tag</body> tag etc.
Sun Infotech Solutions 2
HTML
To learn HTML, you will need to study various tags and understand how do they
behave while formatting a textual document. Learning HTML is simple.
We will study all the header and body tags in subsequent chapters, for now let's see
what is document declaration tag.
<!DOCTYPE html>
Paragraph Tag
The <p> tag offers a way to structure your text into different paragraphs. Each
paragraph of text should go in between an opening <p> and a closing </p> tag as
shown below in the example:
The <br /> tag has a space between the characters br and the forward slash. If you
omit this space, older browsers will have trouble rendering the line break, while if you
miss the forward slash character and just use <br> it is not valid in XHTML
Centering Content
You can use <center> tag to put any content in the center of the page or any table cell.
Horizontal Lines
Horizontal lines are used to visually break up sections of a document. The <hr> tag
creates a line from the current position in the document to the right margin and breaks
the line accordingly.
Sun Infotech Solutions 3
HTML
Again <hr /> tag is an example of the empty element, where you do not need opening and
closing tags, as there is nothing to go in between them.
In cases where you do not want the client browser to break text, you should use a non
breaking space entity instead of a normal space. For example, when coding the "12
Angry Men" in a paragraph, you should use something similar to the following code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
An HTML element is defined by a starting tag. If the element contains other content, it
ends with a closing tag, where the element name is preceded by a forward slash as
shown below with few tags:
<br />
HTML documents consist of a tree of these elements and they specify how HTML
documents should be built, and what kind of content should be placed in what part of
an HTML document.
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
HTML Attributes
We have seen few HTML tags and their usage like heading tags <h1>, <h2>,
paragraph tag <p> and other tags. We used them so far in their simplest form, but
most of the HTML tags can also have attributes, which are extra bits of information.
The name is the property you want to set. For example, the paragraph <p>
element in the example carries an attribute whose name is align, which you
can use to indicate the alignment of paragraph on the page.
The value is what you want the value of the property to be set and always put
within quotations. The below example shows three possible values of align
attribute:left, center and right.
Attribute names and attribute values are case-insensitive. However, the World Wide Web
Consortium (W3C) recommends lowercase attributes/attribute values in their HTML 4
recommendation.
Sun Infotech Solutions 5
HTML
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Core Attributes
The four core attributes that can be used on the majority of HTML elements
(although not all) are:
id
title
class
style
The id Attribute
The id attribute of an HTML tag can be used to uniquely identify any
element within an HTML page. There are two primary reasons that you
might want to use an id attribute on an element:
If you have two elements of the same name within a Web page (or style sheet),
you can use the id attribute to distinguish between elements that have the
same name.
EXAMPLE
<p id="html">This para explains what is HTML</p>
<p id="css">This para explains what is Cascading Style Sheet</p>
The behavior of this attribute will depend upon the element that carries it, although it is
often displayed as a tooltip when cursor comes over the element or while the element is
loading.
EXAMPLE
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Now try to bring your cursor over "Titled Heading Tag Example" and you will see that
whatever title you used in your code is coming out as a tooltip of the cursor.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
At this point of time, we are not learning CSS, so just let's proceed without
bothering much about CSS. Here you need to understand what are HTML attributes
and how they can be used while formatting content.
If you use a word processor, you must be familiar with the ability to make text
bold, italicized, or underlined; these are just three of the ten options available to
indicate how text can appear in HTML and XHTML.
Bold Text
Anything that appears within <b>...</b> element, is displayed in bold as
shown below:
Italic Text
Anything that appears within <i>...</i> element is displayed in italicized
Underlined Text
Anything that appears within <u>...</u> element, is displayed with
underline
Sun Infotech Solutions 8
HTML
Strike Text
Anything that appears within <strike>...</strike> element is displayed with
strikethrough, which is a thin line through the text as shown below:
Monospaced Font
The content of a <tt>...</tt> element is written in monospaced font. Most of the
fonts are known as variable-width fonts because different letters are of different
widths (for example, the letter 'm' is wider than the letter 'i'). In a monospaced
font, however, each letter has the same width.
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Superscript Text
The content of a <sup>...</sup> element is written in superscript; the font size
used is the same size as the characters surrounding it but is displayed half a
character's height above the other characters.
Subscript Text
The content of a <sub>...</sub> element is written in subscript; the font size
used is the same as the characters surrounding it, but is displayed half a
character's height beneath the other characters.
Inserted Text
Anything that appears within <ins>...</ins> element is displayed as inserted
text.
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Deleted Text
Anything that appears within <del>...</del> element, is displayed as deleted
text.
Larger Text
The content of the <big>...</big> element is displayed one font size larger than
the rest of the text surrounding it as shown below:
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
This will produce following result: This is word uses a big typeface.
Sun Infotech Solutions 10
HTML
Smaller Text
The content of the <small>...</small> element is displayed one font size
smaller than the rest of the text surrounding it as shown below:
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Grouping Content
The <div> and <span> elements allow you to group together several elements
to create sections or subsections of a page.
For example, you might want to put all of the footnotes on a page within a <div>
element to indicate that all of the elements within that <div> element relate to the
footnotes. You might then attach a style to this <div> element so that they appear
using a special set of style rules.
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<a href="/index.htm">HOME</a> |
<a href="/about/contact_us.htm">CONTACT</a> |
<a href="/about/index.htm">ABOUT</a>
Sun Infotech Solutions 11
HTML
</div>
<h5>Content Articles</h5>
</div>
</body>
</html>
CONTENT ARTICLES
The <span> element, on the other hand, can be used to group inline elements
only. So, if you have a part of a sentence or paragraph which you want to group
together, you could use the <span> element as follows
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
This is the example of span tag and the div tag alongwith CSS
These tags are commonly used with CSS to allow you to attach a style to a
section of a page.
Sun Infotech Solutions 12
HTML
Emphasized Text
Anything that appears within <em>...</em> element is displayed as emphasized
text.
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
This will produce following result: The following word uses a emphasized typeface.
Marked Text
Anything that appears with-in <mark>...</mark> element, is displayed as
marked with yellow ink.
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Strong Text
Anything that appears within <strong>...</strong> element is displayed as
important text.
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Text Abbreviation
You can abbreviate a text by putting it inside opening <abbr>and
closing </abbr> tags. If present, the title attribute must contain this full
description and nothing else.
Example
<!DOCTYPE html>
<html>
<head>
<title>Text Abbreviation</title>
</head>
<body>
</body>
</html>
Acronym Element
The <acronym> element allows you to indicate that the text between
<acronym> and </acronym> tags is an acronym.
Example
<!DOCTYPE html>
<html>
<head>
<title>Acronym Example</title>
</head>
<body>
</body>
</html>
Text Direction
The <bdo>...</bdo> element stands for Bi-Directional Override and it is
used to override the current text direction.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Special Terms
The <dfn>...</dfn> element (or HTML Definition Element) allows you to specify
that you are introducing a special term. It's usage is similar to italic words in the
midst of a paragraph.
Typically, you would use the <dfn> element the first time you introduce a key
term. Most recent browsers render the content of a <dfn> element in an italic
font.
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Quoting Text
When you want to quote a passage from another source, you should put it in
between <blockquote>...</blockquote> tags.
Text inside a <blockquote> element is usually indented from the left and right
edges of the surrounding text, and sometimes uses an italicized font.
<!DOCTYPE html>
<html>
<head>
<title>Blockquote Example</title>
</head>
Sun Infotech Solutions 16
HTML
<body>
<p>The following description of XHTML is taken from the W3C Web site:</p>
<blockquote>XHTML 1.0 is the W3C's first Recommendation for XHTML, following on from earlier
work on HTML 4.01, HTML 4.0, HTML 3.2 and HTML 2.0.</blockquote>
</body>
</html>
The following description of XHTML is taken from the W3C Web site:
XHTML 1.0 is the W3C's first Recommendation for XHTML, following on from earlier
work on HTML 4.01, HTML 4.0, HTML 3.2 and HTML 2.0.
Short Quotations
The <q>...</q> element is used when you want to add a double quote
within a sentence.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Text Citations
If you are quoting a text, you can indicate the source placing it between an
opening <cite> tag and closing </cite> tag
Example
<!DOCTYPE html>
<html>
<head>
<title>Citations Example</title>
</head>
<body>
</body>
</html>
Computer Code
Any programming code to appear on a Web page should be placed
inside <code>...</code> tags. Usually the content of the <code> element is
presented in a monospaced font, just like the code in most programming books.
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Keyboard Text
When you are talking about computers, if you want to tell a reader to enter some
text, you can use the <kbd>...</kbd>element to indicate what should be typed
in, as in this example.
Sun Infotech Solutions 18
HTML
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Programming Variables
This element is usually used in conjunction with the <pre> and<code> elements
to indicate that the content of that element is a variable.
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p><code>document.write("<var>user-name</var>")</code></p>
</body>
</html>
document.write("user-name")
Program Output
The <samp>...</samp> element indicates sample output from a program, and
script etc. Again, it is mainly used when documenting programming or coding
concepts.
Sun Infotech Solutions 19
HTML
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Address Text
The <address>...</address> element is used to contain any address.
Example
<!DOCTYPE html>
<html>
<head>
<title>Address Example</title>
</head>
<body>
</body>
</html>
The <meta> tag is used to provide such additional information. This tag is
an empty element and so does not have a closing tag but it carries
information within its attributes.
You can include one or more meta tags in your document based on what
information you want to keep in your document but in general, meta tags
do not impact physical appearance of the document so from appearance
point of view, it does not matter if you include them or not.
Attribute Description
Specifying Keywords
You can use <meta> tag to specify important keywords related to the
document and later these keywords are used by the search engines while
indexing your webpage for searching purpose.
Example
Following is an example where we are adding HTML, Meta Tags, Metadata
as important keywords about the document.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>Hello HTML5!</p>
</body>
</html>
Hello HTML5!
Document Description
You can use <meta> tag to give a short description about the document.
This again can be used by various search engines while indexing your
webpage for searching purpose.
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
Sun Infotech Solutions 22
HTML
<p>Hello HTML5!</p>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>Hello HTML5!</p>
</body>
</html>
Document Refreshing
A <meta> tag can be used to specify a duration after which your web page
will keep refreshing automatically.
Example
If you want your page keep refreshing after every 5 seconds then use the
following syntax.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>Hello HTML5!</p>
</body>
</html>
Page Redirection
You can use <meta> tag to redirect your page to any other webpage. You
can also specify a duration if you want to redirect the page after a certain
number of seconds.
Example
Following is an example of redirecting current page to another page after 5
seconds. If you want to redirect page immediately then do not
specify content attribute.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>Hello HTML5!</p>
</body>
</html>
Setting Cookies
Cookies are data, stored in small text files on your computer and it is
exchanged between web browser and web server to keep track of various
infromation based on your web application need.
You can use <meta> tag to store cookies on client side and later this
information can be used by the Web Server to track a site visitor.
Sun Infotech Solutions 24
HTML
Example
Following is an example of redirecting current page to another page after 5
seconds. If you want to redirect page immediately then do not
specify content attribute.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>Hello HTML5!</p>
</body>
</html>
If you do not include the expiration date and time, the cookie is considered
a session cookie and will be deleted when the user exits the browser.
Note: You can check PHP and Cookies tutorial for a complete detail on
Cookies.
Example
<!DOCTYPE html>
<html>
<head>
</head>
Sun Infotech Solutions 25
HTML
<body>
<p>Hello HTML5!</p>
</body>
</html>
Example
By default, Web servers and Web browsers use ISO-8859-1 (Latin1)
encoding to process Web pages. Following is an example to set UTF-8
encoding:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>Hello HTML5!</p>
</body>
</html>
To serve the static page with traditional Chinese characters, the webpage
must contain a <meta> tag to set Big5 encoding:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>Hello HTML5!</p>
</body>
</html>
HTML Comments
HTML comments are placed in between <!-- ... --> tags. So any content
placed with-in <!-- ... --> tags will be treated as comment and will be
completely ignored by the browser.
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
This will produce following result without displaying the content given as a
part of comments:
inside a comment except as part of the closing --> tag. You must also make
sure that there are no spaces in the start-of-comment string.
Example
Here given comment is a valid comment and will be wiped off by the
browser.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
But following line is not a valid comment and will be displayed by the
browser. This is because there is a space between the left angle bracket
and the exclamation mark.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Multiline Comments
So far we have seen single line comments, but HTML supports multi-line
comments as well.
You can comment multiple lines by the special beginning tag <!-- and
ending tag --> placed before the first line and end of the last line as shown
in the given example below.
Example
<!DOCTYPE html><html>
<head>
<title>Multiline Comments</title>
</head>
<body>
<!--
-->
</body>
</html>
Conditional Comments
Conditional comments only work in Internet Explorer (IE) on Windows but
they are ignored by other browsers. They are supported from Explorer 5
onwards, and you can use them to give conditional instructions to different
versions of IE.
<!DOCTYPE html><html>
<head>
<title>Conditional Comments</title>
<!--[if IE 6]>
<![endif]-->
Sun Infotech Solutions 29
HTML
</head>
<body>
</body>
</html>
You will come across a situation where you will need to apply a different
style sheet based on different versions of Internet Explorer, in such
situation conditional comments will be helpful.
Example
<!DOCTYPE html><html>
<head>
</head>
<body>
</body>
</html>
But if you are not using IE, then it will produce following result:
Example
<!DOCTYPE html><html>
<head>
<script>
<!--
document.write("Hello World!")
//-->
</script>
</head>
<body>
<p>Hello , World!</p>
</body>
</html>
Hello World!
Hello , World!
<!DOCTYPE html><html>
<head>
<style>
<!--
.example {
//-->
</style>
Sun Infotech Solutions 31
HTML
</head>
<body>
</body>
</html>
Hello , World!
Insert Image
You can insert any image in your web page by using <img> tag. Following
is the simple syntax to use this tag.
The <img> tag is an empty tag, which means that it can contain only list of
attributes and it has no closing tag.
Example
To try following example, let's keep our HTML file test.htm and image file
test.png in the same directory:
<html>
<head>
</head>
<body>
</body>
</html>
Example
Assuming our image location is "/html/image/test.png", try the following
example:
Example
<img src="/html/images/test.png" alt="Test Image" width="150" height="100"/>
Example
<img src="/html/images/test.png" alt="Test Image" border="3" align="right"/>
The HTML tables allow web authors to arrange data like text, images, links,
other tables, etc. into rows and columns of cells.
The HTML tables are created using the <table> tag in which the<tr> tag is
used to create table rows and <td> tag is used to create data cells.
Table Heading
Table heading can be defined using <th> tag. This tag will be put to
replace <td> tag, which is used to represent actual data cell. Normally you
will put your top row as table heading as shown below, otherwise you can
use <th> element in any row.
Example
<html>
<head>
</head>
<body>
<table border="1">
<tr>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>Ramesh Raman</td>
<td>5000</td>
</tr>
<tr>
<td>Shabbir Hussein</td>
<td>7000</td>
Sun Infotech Solutions 34
HTML
</tr>
</table>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
</table>
</body>
</html>
Row 3 Cell 1
Tables Backgrounds
You can set table background using one of the following two ways:
bgcolor attribute - You can set background color for whole table or just for one
cell.
background attribute - You can set background image for whole table or just
for one cell.
You can also set border color also using bordercolor attribute.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
</table>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
</table>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<tr>
</tr>
<tr>
Sun Infotech Solutions 37
HTML
</tr>
</table>
</body>
</html>
Table Caption
The caption tag will serve as a title or explanation for the table and it
shows up at the top of the table. This tag is deprecated in newer version of
HTML/XHTML.
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<tr>
</tr>
<tr>
</tr>
</table>
</body>
</html>
The three elements for separating the head, body, and foot of a table are:
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table</title>
</head>
<body>
<thead>
<tr>
</tr>
</thead>
<tfoot>
<tr>
</tr>
Sun Infotech Solutions 39
HTML
</tfoot>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</tbody>
</table>
</body>
</html>
Nested Tables
You can use one table inside another table. Not only tables you can use
almost all the tags inside table data tag <td>.
Example
Following is the example of using another table and other tags inside a
table cell.
<!DOCTYPE html>
<html>
<head>
<title>HTML Table</title>
</head>
<body>
<tr>
<td>
<tr>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>Ramesh Raman</td>
<td>5000</td>
</tr>
<tr>
<td>Shabbir Hussein</td>
<td>7000</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Name Salary
<ul> - An unordered list. This will list items using plain bullets.
<ol> - An ordered list. This will use different schemes of numbers to list
your items.
<dl> - A definition list. This arranges your items in the same way as they
are arranged in a dictionary.
HTML Unordered Lists
An unordered list is a collection of related items that have no special order or
sequence. This list is created by using HTML <ul>tag. Each item in the list is
marked with a bullet.
Example
<html>
<head>
</head>
<body>
<ul>
<li>LCD TV</li>
<li>Washing Machine</li>
<li>Music System</li>
<li>Water Purifier</li>
</ul>
</body>
</html>
<ul type="square">
<ul type="disc">
<ul type="circle">
Sun Infotech Solutions 42
HTML
<html>
<head>
</head>
<body>
<ol>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
1. Beetroot
2. Ginger
3. Potato
4. Radish
<head>
</head>
<body>
<dl>
<dt><b>HTML</b></dt>
<dt><b>HTTP</b></dt>
</dl>
</body>
</html>
HTML
HTTP
Linking Documents
A link is specified using HTML tag <a>. This tag is called anchor tag and anything
between the opening <a> tag and the closing </a> tag becomes part of the link
and a user can click that part to reach to the linked document. Following is the
simple syntax to use <a> tag.
Example
Let's try following example which links http://www.inspireeducation.com at
your page:
<html>
<head>
<title>Hyperlink Example</title>
</head>
<body>
</body>
</html>
We have used target attribute in our previous example. This attribute is used to
specify the location where linked document is opened. Following are possible
options:
Sun Infotech Solutions 45
HTML
Option Description
Following example makes use of <base> tag to specify base URL and later we can
use relative path to all the links instead of giving complete URL for every link.
<html>
<head>
<title>Hyperlink Example</title>
<base href="http://www.inspireglobaleducation.com/">
</head>
<body>
</body>
</html>
Sun Infotech Solutions 46
HTML
First create a link to the place where you want to reach with-in a webpage and
name it using <a...> tag as follows:
Second step is to create a hyperlink to link the document and place where
you want to reach:
Save the following in test.htm and open it in any web browser to see
how link, alink and vlink attribute work.
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
</head>
</body>
</html>
Download Links
You can create text link to make your PDF, or DOC or ZIP files downloadable. This
is very simple, you just need to give complete URL of the downloadable file as
follows:
<html>
Sun Infotech Solutions 47
HTML
<head>
<title>Hyperlink Example</title>
</head>
</body>
</html>
It's simple to use an image as hyperlink. We just need to use an image inside
hyperlink at the place of text as shown below:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</a>
</body>
</html>
This will produce following result, where you can click on the images to reach to
the home page of Tutorials Point.
This was the simplest way of creating hyperlinks using images. Next we will see
how we can create Mouse-Sensitive Image Links.
You can have other options to facilitate people to send you emails. One
option could be to use HTML forms to collect user data and then use PHP or
CGI script to send an email.
This code will generate following link which you can use to send email.
Send Email
Now if a user clicks this link, it launches one Email Client ( like Lotus Notes,
Outlook Express etc. ) installed on your user's computer. There is another
risk to use this option to send email because if user do not have email client
installed on their computer then it would not be possible to send email.
Default Settings
You can specify a default email subject and email body alongwith your email
address. Following is the example to use default subject and body.
<a href="mailto:[email protected]?subject=Feedback&body=Message">
Send Feedback
</a>
Sun Infotech Solutions 49
HTML
HTML Frames
HTML frames are used to divide your browser window into multiple sections
where each section can load a separate HTML document. A collection of
frames in the browser window is known as a frameset. The window is
divided into frames in a similar way the tables are organized: into rows and
columns.
Disadvantages of Frames
There are few drawbacks with using frames, so it's never recommended to
use frames in your webpages:
Some smaller devices cannot cope with frames often because their screen is not
big enough to be divided up.
The browser's back button might not work as the user hopes.
There are still few browsers that do not support frame technology.
Creating Frames
To use frames on a page we use <frameset> tag instead of <body> tag.
The <frameset> tag defines how to divide the window into frames.
The rows attribute of <frameset> tag defines horizontal frames
and cols attribute defines vertical frames. Each frame is indicated by
<frame> tag and it defines which HTML document shall open into the
frame.
Example
Following is the example to create three horizontal frames:
<!DOCTYPE html>
<html>
<head>
<title>HTML Frames</title>
</head>
<frameset rows="10%,80%,10%">
<noframes>
<body>
</body>
</noframes>
</frameset>
</html>
Example
Let's put above example as follows, here we replaced rows attribute by cols
and changed their width. This will create all the three frames vertically:
<!DOCTYPE html>
<html>
<head>
<title>HTML Frames</title>
</head>
<frameset cols="25%,50%,25%">
<noframes>
<body>
</body>
</noframes>
</frameset>
Sun Infotech Solutions 51
HTML
</html>
Attribute Description
rows This attribute works just like the cols attribute and
takes the same values, but it is used to specify the
rows in the frameset. For example to create two
horizontal frames, use rows="10%, 90%". You can
specify the height of each row in the same way as
explained above for columns.
Attribute Description
You can put some nice message for your user having old browsers. For
example Sorry!! your browser does not support frames. as shown in the
above example.
Let's see following example where a test.htm file has following code:
<!DOCTYPE html>
<html>
<head>
</head>
<noframes>
<body>
</body>
</noframes>
</frameset>
</html>
Here we have created two columns to fill with two frames. The first frame is
200 pixels wide and will contain the navigation menubar implemented
by menu.htm file. The second column fills in remaining space and will
contain the main part of the page and it is implemented by main.htm file.
For all the three links available in menubar, we have mentioned target
frame asmain_page, so whenever you click any of the links in menubar,
available link will open in main_page.
<!DOCTYPE html>
<html>
<body bgcolor="#4a7d49">
Sun Infotech Solutions 55
HTML
</body>
</html>
<!DOCTYPE html>
<html>
<body bgcolor="#b5dcb3">
<h3>This is main page and content from any link will be displayed here.</h3>
</body>
</html>
Now you can try to click links available in the left panel and see the result.
The target attribute can also take one of the following values:
Option Description
_parent Loads the page into the parent window, which in the
case of a single frameset is the main browser window.
Sun Infotech Solutions 56
HTML
HTML Blocks
All the HTML elements can be categorized into two categories (a)Block
Level Elements (b) Inline Elements
Block Elements
Block elements appear on the screen as if they have a line break before and
after them. For example the <p>, <h1>, <h2>, <h3>, <h4>, <h5>,
<h6>, <ul>, <ol>, <dl>, <pre>, <hr />, <blockquote>, and <address>
elements are all block level elements. They all start on their own new line,
and anything that follows them appears on its own new line.
Inline Elements
Inline elements, on the other hand, can appear within sentences and do not
have to appear on a new line of their own. The <b>, <i>, <u>, <em>,
<strong>, <sup>, <sub>, <big>, <small>, <li>, <ins>, <del>, <code>,
<cite>, <dfn>, <kbd>, and <var> elements are all inline elements.
Example
Following is a simple example of <div> tag. We will learn Cascading Style
Sheet (CSS) in a separate chapter but we used it here to show the usage of
<div> tag:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style="color:red">
<ul>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ul>
</div>
<div style="color:green">
<ul>
<li>Apple</li>
<li>Banana</li>
<li>Mango</li>
<li>Strawberry</li>
</ul>
</div>
Sun Infotech Solutions 58
HTML
</body>
</html>
Beetroot
Ginger
Potato
Radish
Apple
Banana
Mango
Strawberry
The difference between the <span> tag and the <div> tag is that the
<span> tag is used with inline elements where as the <div> tag is used
with block-level elements.
Example
Following is a simple example of <span> tag. We will learn Cascading Style
Sheet (CSS) in a separate chapter but we used it here to show the usage of
<span> tag:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
Sun Infotech Solutions 59
HTML
</body>
</html>
HTML Backgrounds
By default, your webpage background is white in color. You may not like it,
but no worries. HTML provides you following two good ways to decorate
your webpage background.
Now let's see both the approaches one by one using appropriate examples.
<tagname bgcolor="color_value"...>
Example
Here are the examples to set background of an HTML tag:
Sun Infotech Solutions 60
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<tr><td>
</td></tr>
</table>
<tr><td>
</td></tr>
</table>
<tr><td>
</td></tr>
</table>
</body>
</html>
The most frequently used image formats are JPEG, GIF and PNG images.
Example
Here are the examples to set background images of a table.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<tr><td>
</td></tr>
</table>
</body>
</html>
Example
Here are the examples to set background pattern of a table:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<tr><td>
</td></tr>
</table>
<tr><td>
</td></tr>
</table>
</body>
</html>
HTML Colors
Colors are very important to give a good look and feel to your website. You
can specify colors on page level using <body> tag or you can set colors for
individual tags using bgcolor attribute.
The <body> tag has following attributes which can be used to set different
colors:
vlink - sets a color for visited links - that is, for linked text that you have
already clicked on.
Color names - You can specify color names directly like green, blue or red.
Hex codes - A six-digit code representing the amount of red, green, and blue
that makes up the color.
Color decimal or percentage values - This value is specified using the rgb( )
property.
Standard 16 Colors
Here is the list of W3C Standard 16 Colors names and it is recommended to
use them.
EXAMPLE
Here are the examples to set background of an HTML tag by color name:
<!DOCTYPE html>
<html>
<head>
</head>
<p>Use different color names for for body and table and see the result.</p>
<table bgcolor="black">
<tr>
<td>
</td>
</tr>
</table>
</body>
</html>
A hexadecimal value can be taken from any graphics software like Adobe
Photoshop, Paintshop Pro or MS Paint.
#000000
#FF0000
#00FF00
#0000FF
#FFFF00
#00FFFF
#FF00FF
#C0C0C0
#FFFFFF
EXAMPLE
Here are the examples to set background of an HTML tag by color code in
hexadecimal:
<!DOCTYPE html>
<html>
<head>
</head>
<p>Use different color hexa for for body and table and see the result.</p>
<table bgcolor="#000000">
<tr>
Sun Infotech Solutions 66
HTML
<td>
</td>
</tr>
</table>
</body>
</html>
Note: All the browsers does not support rgb() property of color so it is recommended
not to use it.
rgb(0,0,0)
rgb(255,0,0)
rgb(0,255,0)
rgb(0,0,255)
rgb(255,255,0)
rgb(0,255,255)
rgb(255,0,255)
rgb(192,192,192)
rgb(255,255,255)
Sun Infotech Solutions 67
HTML
EXAMPLE
Here are the examples to set background of an HTML tag by color code
using rgb() values:
<!DOCTYPE html>
<html>
<head>
</head>
<p>Use different color code for for body and table and see the result.</p>
<table bgcolor="rgb(0,0,0)">
<tr>
<td>
</td>
</tr>
</table>
</body>
</html>
HTML Fonts
Fonts play very important role in making a website more user friendly and
increasing content readability. Font face and color depends entirely on the
computer and browser that is being used to view your page but you can use
HTML <font> tag to add style, size, and color to the text on your website.
You can use a<basefont> tag to set all of your text to the same size, face,
and color.
The font tag is having three attributes called size, color, andface to
customize your fonts. To change any of the font attributes at any time
within your webpage, simply use the <font> tag. The text that follows will
remain changed until you close with the </font> tag. You can change one
or all of the font attributes within one <font> tag.
Note: The font and basefont tags are deprecated and it is supposed to be removed in a
future version of HTML. So they should not be used rather, it's suggested to use CSS
styles to manipulate your fonts. But still for learning purpose, this chapter will explain
font and basefont tags in detail.
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
Sun Infotech Solutions 71
HTML
</html>
Font size="1"
Font size="2"
Font size="3"
Font size="4"
Font size="5"
Font size="6"
Font size="7"
Relative Font Size
You can specify how many sizes larger or how many sizes smaller than the
preset font size should be. You can specify it like <font size="+n"> or
<font size="-n">
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Font size="-1"
Font size="+1"
Font size="+2"
Sun Infotech Solutions 72
HTML
Font size="+3"
Font size="+4"
Setting Font Face
You can set font face using face attribute but be aware that if the user
viewing the page doesn't have the font installed, they will not be able to see
it. Instead user will see the default font face applicable to the user's
computer.
Example
<!DOCTYPE html>
<html>
<head>
<title>Font Face</title>
</head>
<body>
</body>
</html>
<font face="arial,helvetica">
When your page is loaded, their browser will display the first font face
available. If none of the given fonts are installed, then it will display the
default font face Times New Roman.
Note: You can check a complete list of HTML Color Name with Codes.
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
The <basefont> tag also takes color, size and face attributes and it will
support relative font setting by giving size a value of +1 for a size larger or
-2 for two sizes smaller.
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</font></p>
</font></p>
</body>
</html>
HTML Forms
HTML Forms are required when you want to collect some data from the site
visitor. For example during user registration you would like to collect
information such as name, email address, credit card, etc.
A form will take input from the site visitor and then will post it to a back-
end application such as CGI, ASP Script or PHP script etc. The back-end
application will perform required processing on the passed data based on
defined business logic inside the application.
There are various form elements available like text fields, textarea fields,
drop-down menus, radio buttons, checkboxes, etc.
The HTML <form> tag is used to create an HTML form and it has following
syntax:
</form>
Form Attributes
Apart from common attributes, following is a list of the most frequently
used form attributes:
Attribute Description
enctype
You can use the enctype attribute to specify how the
browser encodes the data before it sends it to the
Sun Infotech Solutions 76
HTML
application/x-www-form-urlencoded - This
is the standard method most forms use in
simple scenarios.
Note: You can refer to Perl & CGI for a detail on how form data upload
works.
Checkboxes Controls
Hidden Controls
Clickable Buttons
Single-line text input controls - This control is used for items that require
only one line of user input, such as search boxes or names. They are created
using HTML<input> tag.
Password input controls - This is also a single-line text input but it masks the
character as soon as a user enters it. They are also created using HTMl <input>
tag.
Sun Infotech Solutions 77
HTML
Multi-line text input controls - This is used when the user is required to give
details that may be longer than a single sentence. Multi-line input controls are
created using HTML <textarea> tag.
Example
Here is a basic example of a single-line text input used to take first name
and last name:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form >
<br>
</form>
</body>
</html>
First name:
Last name:
Attributes
Following is the list of attributes for <input> tag for creating text field.
Attribute Description
type Indicates the type of input control and for text input
control it will be set to text.
Sun Infotech Solutions 78
HTML
Example
Here is a basic example of a single-line password input used to take user
password:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form >
<br>
</form>
</body>
</html>
User ID :
Password:
Attributes
Following is the list of attributes for <input> tag for creating password field.
Attribute Description
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
Sun Infotech Solutions 80
HTML
</textarea>
</form>
</body>
</html>
Description :
Attributes
Following is the list of attributes for <textarea> tag.
Attribute Description
Checkbox Control
Checkboxes are used when more than one option is required to be selected.
They are also created using HTML <input> tag but type attribute is set
to checkbox.
Example
Here is an example HTML code for a form with two checkboxes:
<!DOCTYPE html>
<html>
Sun Infotech Solutions 81
HTML
<head>
<title>Checkbox Control</title>
</head>
<body>
<form>
</form>
</body>
</html>
Maths Physics
Attributes
Following is the list of attributes for <checkbox> tag.
Attribute Description
Example
Here is example HTML code for a form with two radio buttons:
Sun Infotech Solutions 82
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
</form>
</body>
</html>
Maths Physics
Attributes
Following is the list of attributes for radio button.
Attribute Description
value The value that will be used if the radio box is selected.
Example
Here is example HTML code for a form with one drop down box
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
<select name="dropdown">
<option value="Physics">Physics</option>
</select>
</form>
</body>
</html>
Maths
Attributes
Following is the list of important attributes of <select> tag:
Attribute Description
Attribute Description
value The value that will be used if an option in the select box
box is selected.
Here is example HTML code for a form with one file upload box:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
</form>
</body>
</html>
Attributes
Following is the list of important attributes of file upload box:
Attribute Description
Sun Infotech Solutions 85
HTML
Button Controls
There are various ways in HTML to create clickable buttons. You can also
create a clickable button using <input> tag by setting its type attribute
to button. The type attribute can take the following values:
Type Description
Here is example HTML code for a form with three types of buttons:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
</form>
</body>
</html>
Submit Reset
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
</form>
</body>
</html>
This is page 10
Sun Infotech Solutions 87
HTML
You can also include a <noembed> tag for the browsers which don't
recognize the <embed> tag. You could, for example, use <embed> to
display a movie of your choice, and <noembed> to display a single JPG
image if browser does not support <embed> tag.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</embed>
</body>
</html>
You can put any media file in src attribute. You can try it yourself by giving
various types of files.
Attribute Description
.swf files - are the file types created by Macromedia's Flash program.
.mpeg files - are movie files created by the Moving Pictures Expert Group.
<!DOCTYPE html>
Sun Infotech Solutions 89
HTML
<html>
<head>
</head>
<body>
</embed>
</body>
</html>
Background Audio
You can use HTML <bgsound> tag to play a soundtrack in the background
of your webpage. This tag is supported by Internet Explorer only and most
of the other browsers ignore this tag. It downloads and plays an audio file
when the host document is first downloaded by the user and displayed. The
background sound file also will replay whenever the user refreshes the
browser.
This tag is having only two attributes loop and src. Both these attributes
have same meaning as explained above.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<bgsound src="/html/yourfile.mid">
</bgsound>
</body>
</html>
Sun Infotech Solutions 90
HTML
This will produce blank screen. This tag does not display any component
and remains hidden.
Internet Explorer can also handle only three different sound format files:
wav, the native format for PCs; au, the native format for most Unix
workstations; and MIDI, a universal music-encoding scheme.
Example - 1
You can embed an HTML document in an HTML document itself as follows:
</object>
Here alt attribute will come into picture if browser does not
support object tag.
Example - 2
You can embed a PDF document in an HTML document as follows:
</object>
Example - 3
You can specify some parameters related to the document with
the <param> tag. Here is an example to embed a wav file:
</object>
Example - 4
You can add a flash document as follows:
</object>
Example - 5
You can add a java applet into HTML document as follows:
<object classid="clsid:8ad9c840-044e-11d1-b3e9-00805f499d93"
width="200" height="200">
</object>
The classid attribute identifies which version of Java Plug-in to use. You
can use the optional codebase attribute to specify if and how to download
the JRE.
Sun Infotech Solutions 92
HTML
HTML Marquees
An HTML marquee is a scrolling piece of text displayed either horizontally
across or vertically down your webpage depending on the settings. This is
created by using HTML <marquees> tag.
Note: The HTML <marquee> tag may not be supported by various browsers so its not
recommended to rely on this tag, instead you can use Javascript and CSS to create
such effects.
Syntax
A simple syntax to use HTML <marquee> tag is as follows:
</marquee>
Attribute Description
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
</head>
Sun Infotech Solutions 94
HTML
<body>
</body>
</html>
Examples - 3
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Another Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
HTML Header
We have learnt that a typical HTML document will have following structure:
<html>
<head>
</head>
Sun Infotech Solutions 95
HTML
<body>
</body>
</html>
This chapter will give a little more detail about header part which is
represented by HTML <head> tag. The <head> tag is a container of various
important tags like <title>, <meta>, <link>, <base>, <style>, <script>,
and <noscript> tags.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>Hello, World!</p>
</body>
</html>
Hello, World!
Following are few of the important usages of <meta> tag inside an HTML
document:
<!DOCTYPE html>
<html>
<head>
<!-- Tag to tell robots not to index the content of a page -->
</head>
<body>
<p>Hello, World!</p>
</body>
</html>
Hello, World!
For example, all the given pages and images will be searched after prefixing the
given URLs with base URL http://www.sun.com/ directory:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
HTML Tutorial
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>Hello, World!</p>
</body>
</html>
Hello, World!
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.myclass{
background-color: #aaa;
padding: 10px;
</style>
</head>
<body>
</body>
</html>
Hello, World!
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
Sun Infotech Solutions 99
HTML
function Hello(){
alert("Hello, World");
</script>
</head>
<body>
</body>
</html>
This will produce following result, where you can try to click on the given
button:
Cascading Style Sheets (CSS) describe how documents are presented on screens,
in print, or perhaps how they are pronounced. W3C has actively promoted the use
of style sheets on the Web since the Consortium was founded in 1994.
Cascading Style Sheets (CSS) provide easy and effective alternatives to specify
various attributes for the HTML tags. Using CSS, you can specify a number of style
properties for a given HTML element. Each property has a name and a value,
separated by a colon (:). Each property declaration is separated by a semi-colon
(;).
Example
First let's consider an example of HTML document which makes use of
<font> tag and associated attributes to specify text color and font size:
<!DOCTYPE html>
<html>
<head>
<title>HTML CSS</title>
</head>
<body>
</body>
</html>
Sun Infotech Solutions 100
HTML
We can re-write above example with the help of Style Sheet as follows:
<!DOCTYPE html>
<html>
<head>
<title>HTML CSS</title>
</head>
<body>
</body>
</html>
Hello, World!
You can use CSS in three ways in your HTML document:
External Style Sheet - Define style sheet rules in a separate .css file and then
include that file in your HTML document using HTML <link> tag.
Internal Style Sheet - Define style sheet rules in header section of the HTML
document using <style> tag.
Inline Style Sheet - Define style sheet rules directly along-with the HTML
elements using style attribute.
Let's see all the three cases one by one with the help of suitable examples.
Example
Consider we define a style sheet file style.css which has following rules:
.red{
color: red;
.thick{
Sun Infotech Solutions 101
HTML
font-size:20px;
.green{
color:green;
Here we defined three CSS rules which will be applicable to three different classes
defined for the HTML tags. I suggest you should not bother about how these rules
are being defined because you will learn them while studying CSS. Now let's make
use of the above external CSS file in our following HTML document:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
This is red
This is thick
This is green
If you want to apply Style Sheet rules to a single document only then you can
include those rules in header section of the HTML document using <style> tag.
Rules defined in internal style sheet overrides the rules defined in an external CSS
file.
Example
Let's re-write above example once again, but here we will write style sheet rules in
the same HTML document using <style> tag:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.red{
color: red;
.thick{
font-size:20px;
.green{
color:green;
</style>
</head>
<body>
</body>
</html>
This is red
This is thick
This is green
Rules defined inline with the element overrides the rules defined in an external
CSS file as well as the rules defined in <style> element.
Example
Let's re-write above example once again, but here we will write style sheet rules
along with the HTML elements using styleattribute of those elements.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
This is red
Sun Infotech Solutions 104
HTML
This is thick
This is green
HTML Javascript
A script is a small piece of program that can add interactivity to your website. For
example, a script could generate a pop-up alert box message, or provide a
dropdown menu. This script could be written using Javascript or VBScript.
You can write various small functions, called event handlers using any of the
scripting language and then you can trigger those functions using HTML attributes.
Now a days only Javascript and associated frameworks are being used by most of
the web developers, VBScript is not even supported by various major browsers.
You can keep Javascript code in a separate file and then include it whereever it's
needed, or you can define functionality inside HTML document itself. Let's see both
the cases one by one with suitable examples.
External Javascript
If you are going to define a functionality which will be used in various HTML
documents then it's better to keep that functionality in a separate Javascript file
and then include that file in your HTML documents. A Javascript file will have
extension as .js and it will be included in HTML files using <script> tag.
Example
Consider we define a small function using Javascript in script.jswhich has
following code:
function Hello()
alert("Hello, World");
Now let's make use of the above external Javascript file in our following HTML
document:
Sun Infotech Solutions 105
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
This will produce following result, where you can try to click on the given button:
Internal Script
You can write your script code directly into your HTML document. Usually we keep
script code in header of the document using <script> tag, otherwise there is no
restriction and you can put your source code anywhere in the document but inside
<script> tag.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function Hello(){
alert("Hello, World");
</script>
</head>
<body>
</body>
</html>
This will produce following result, where you can try to click on the given button:
Event Handlers
Sun Infotech Solutions 106
HTML
Event handlers are nothing but simply defined functions which can be called
against any mouse or keyboard event. You can define your business logic
inside your event handler which can vary from a single to 1000s of line
code.
Following example explains how to write an event handler. Let's write one
simple function EventHandler() in the header of the document. We will call
this function when any user brings mouse over a paragraph.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function EventHandler(){
</script>
</head>
<body>
</body>
</html>
Now this will produce following result. Bring your mouse over this line and
see the result:
JavaScript Example:
<script type="text/javascript">
<!--
Sun Infotech Solutions 107
HTML
document.write("Hello Javascript!");
//-->
</script>
VBScript Example:
<script type="text/vbscript">
<!--
document.write("Hello VBScript!")
'-->
</script>
JavaScript Example:
<script type="text/javascript">
<!--
document.write("Hello Javascript!");
//-->
</script>
VBScript Example:
<script type="text/vbscript">
<!--
document.write("Hello VBScript!")
'-->
</script>
Note that you can still override the default by specifying a language within the
script tag.
HTML Layouts
A webpage layout is very important to give better look to your website. It takes
considerable time to design a website's layout with great look and feel.
Now a days, all modern websites are using CSS and Javascript based framework to
come up with responsive and dynamic websites but you can create a good layout
using simple HTML tables or division tags in combination with other formatting
tags. This chapter will give you few examples on how to create a simple but
working layout for your webpage using pure HTML and its attributes.
For example, the following HTML layout example is achieved using a table
with 3 rows and 2 columns but the header and footer column spans both
columns using the colspan attribute:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<tr>
</td>
</tr>
<tr valign="top">
HTML<br />
PHP<br />
Sun Infotech Solutions 109
HTML
PERL...
</td>
</td>
</tr>
<tr>
<center>
</center>
</td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<tr valign="top">
HTML<br />
PHP<br />
PERL...
</td>
</td>
HTML<br />
PHP<br />
PERL...
</td>
</tr>
<table>
</body>
</html>
Although we can achieve pretty nice layouts with HTML tables, but tables weren't
really designed as a layout tool. Tables are more suited to presenting tabular data.
Note: This example makes use of Cascading Style Sheet (CSS), so before
understanding this example you need to have a better understanding on how CSS
works.
Example
Here we will try to achieve same result using <div> tag along with CSS,
whatever you have achieved using <table> tag in previous example.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style="width:100%">
</div>
<div><b>Main Menu</b></div>
HTML<br />
PHP<br />
Sun Infotech Solutions 112
HTML
PERL...
</div>
</div>
<div><b>Right Menu</b></div>
HTML<br />
PHP<br />
PERL...
</div>
<div style="background-color:#b5dcb3;clear:both">
<center>
</center>
</div>
</div>
</body>
</html>
HTML
PHP
PERL...
Right Menu
HTML
PHP
PERL...