HTML Basics
HTML Basics
HTML stands for Hypertext Markup Language, and it is the most widely used language to write Web
Pages. As its name suggests, HTML is a markup language.
Hypertext refers to the way in which Web pages (HTML documents) are linked together. When
you click a link in a Web page, you are using hypertext.
Markup Language describes how HTML works. With a markup language, you 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.
All you need to do to use HTML is to learn what type of markup to use to get the results you want.
<h1>This is a heading</h1>
<p>Document description goes here.....</p>
</body>
</html>
Now you have created one HTML page and you can use a Web Browser to open this HTML file to see
the result. Hope you understood that Web Pages are nothing but they are simple HTML files with some
content which can be rendered using Web Browsers.
Here <html>, <head>,...<p>, <h1> etc. are called HTML tags. HTML tags are building blocks of an
HTML document nd we will learn all the HTML tags in subsequent chapters.
NOTE: One HTML file can have extension as .htm or .html. So you can use either of them based on
your comfort.
HTML is Forgiving?
A very good quality associated with all the browsers is that they would not give any error if you have
not put any HTML tag or attribute properly. They will just ignore that tag or attribute and will apply
only correct tags and attributes before displaying the result.
We can not say, HTML is forgiving because this is just a markup language and required to format
documents.
The basic structure for all HTML documents is simple and should include the following minimum
elements or tags:
Example:
Following is the example of head tag.
<head>
<title>HTML Basic tags</title>
<meta name="Keywords" content="HTML, Web Pages" />
<meta name="description" content="HTML Basic Tags" />
<base href="http://www.tutorialspoint.com" />
<link rel="stylesheet" type="text/css" href="tp.css" />
<script type="text/javascript">
_uacct = "UA-232293";
urchinTracker();
</script>
</head>
Example:
Here is the example of using title tag.
<head>
<title>HTML Basic tags</title>
</head>
Example:
Here is the example of using body tag.
<body>
<p>This is a paragraph tag.</p>
</body>
HTML lets you specify metadata - information about a document rather than document content -in a
variety of ways. The META element can be used to include name/value pairs describing properties of
the HTML document, such as author, Expiry Date, a list of key words, author etc.
The <meta> tag is an empty element and so does not have a closing tag, rather, <meta> tags carry
information within attributes, so you need a forward slash character at the end of the element.
Metadata provided by using meta tag is a very important part of the web. It can assist search engines in
finding the best match when a user performs a search. Search engines will often look at any metadata
attached to a page - especially keywords - and rank it higher than another page with less relevant
metadata, or with no metadata at all.
Description
Name
Name for the property. Can be anything. Examples include, keywords, description,
author, revised, generator etc.
content
scheme
Specifies a scheme to use to interpret the property's value (as declared in the content
attribute).
Used for http response message headers. For example http-equiv can be used to refresh
the page or to set a cookie. Values include content-type, expires, refresh and set-cookie.
NOTE: Core attributes for all the elements are discussed in next chapter.
http-equiv
Specifying Keywords:
We specify keywords which will be used by the search engine to search a web page. So using following
tag you can specify important keywords related to your page.
<head>
<meta name="keywords" content="HTML, meta tags, metadata" />
</head>
Document Description:
This is again important information and many search engine use this information as well while
searching a web page. So you should give an appropriate description of the page.
<head>
<meta name="description" content="Learn about Meta Tags." />
</head>
Document Refreshing:
You can specify a duration after which your web page will keep refreshing. If you want your page keep
refreshing after every 10 seconds then use the following syntax.
<head>
<meta http-equiv="refresh" content="10" />
</head>
Page Redirection:
You can specify a page redirection using Meta Tag. Following is an example of redirecting current page
to another page. You can specify a duration after which page will be redirected.
<head>
<meta http-equiv="refresh"
content="10; url=http://www.tutorialspoint.com" />
</head>
Setting Cookies:
You can use Meta Tag to store cookies on client side later information can be used by then Web Server
to track a site visitor.
<head>
<meta http-equiv="cookie" content="userid=xyz;
expires=Wednesday, 08-Aug-00 23:59:59 GMT; />
</head>
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.
Check PHP and Cookies tutorial for a complete detail on Cookies.
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.
Attributes are another important part of HTML markup. An attribute is used to define the
characteristics of an element and is placed inside the element's opening tag. All attributes are made up
of two parts: a name and a value:
The name is the property you want to set. For example, the <font> element in the example
carries an attribute whose name is face, which you can use to indicate which typeface you want
the text to appear in.
The value is what you want the value of the property to be. The first example was supposed to
use the Arial typeface, so the value of the face attribute is Arial.
The value of the attribute should be put in double quotation marks, and is separated from the name by
the equals sign. You can see that a color for the text has been specified as well as the typeface in this
<font> element:
<font face="arial" color="#CC0000">
Many HTML tags have a unique set of their own attributes. These will be discussed as each tag is
introduced throughout the tutorial. Right now we want to focus on a set of generic attributes that can be
used with just about every HTML Tag in existence.
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 can be used to uniquely identify any element within a page ( or style sheet ). There are
two primary reasons that you might want to use an id attribute on an element:
If an element carries an id attribute as a unique identifier it is possible to identify just that
element and its content.
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.
We will discuss style sheet in separate tutorial. For now, the id attribute could be used to distinguish
between two paragraph elements, like so:
<p id="html">This para explains what is HTML</p>
<p id="css">This para explains what is Casecading Style Sheet</p>
Note that there are some special rules for the value of the id attribute, it must:
Begin with a letter (A.Z or a.z) and can then be followed by any number of letters, digits (0.9),
hyphens, underscores, colons, and periods.
Remain unique within that document; no two attributes may have the same value within that
HTML document.
Internationalization Attributes:
There are three internationalization attributes, which are available to most (although not all) XHTML
elements.
dir
lang
xml:lang
Meaning
Left to right (the default value)
rtl
Right to left (for languages such as Hebrew or Arabic that are read right to left)
Example:
<html dir=rtl>
<head>
<title>Display Directions</title>
</head>
<body>
This is how IE 5 renders right-to-left directed text.
</body>
</html>
When dir attribute is used within the <html> tag, it determines how text will be presented within the
entire document. When used within another tag, it controls the text's direction for just the content of
that tag.
Generic Attributes:
Here's a table of some other attributes that are readily usable with many of HTML's tags.
Attribute
Options
Function
align
valign
bgcolor
background URL
id
User Defined
class
User Defined
width
Numeric Value
height
Numeric Value
title
User Defined
"Pop-up" title for your elements.
We will see related examples as we will proceed to study other HTML tags.
If you want people to read what you have written, then structuring your text well is even more
important on the Web than when writing for print. People have trouble reading wide, long, paragraphs
of text on Web sites unless they are broken up well.
This section will teach you basic text formatting elements like heading elements and paragraph
elements.
is
is
is
is
is
is
heading
heading
heading
heading
heading
heading
1</h1>
2</h2>
3</h3>
4</h4>
5</h5>
6</h6>
This is heading 1
This is heading 2
This is heading 3
This is heading 4
This is heading 5
This is heading 6
Nonbreaking Spaces:
Suppose you were to use the phrase "12 Angry Men." Here you would not want a browser to split the
"12" and "Angry" across two lines:
A good example of this technique appears in the movie "12 Angry Men."
In cases where you do not want the client browser to break text, you should use a nonbreaking space
entity ( ) instead of a normal space. For example, when coding the "12 Angry Men" paragraph,
you would use something similar to the following code:
<p>A good example of this technique appears in the movie "12 Angry Men."</p>
Soft Hyphens:
Occasionally, you will want to allow a browser to hyphenate long words to better justify a paragraph.
For example, consider the following code and its resulting output.
<p style="text-align: justify;"> The morbid fear of the number 13, or triskaidekaphobia, has plagued
some important historic figures like Mahamiya and Nanao.</p>
In cases where you want a client browser to be able to hyphenate a word if necessary, use the soft
hyphen entity (­) to specify where a word should be hyphenated. So above example should be
written as follows:
<p style="text-align: justify;"> Example for soft hyphen - The morbid fear of the number 13, or
tri­skai­deka­phobia, has plagued some important historic figures like Mahamiya and
Nanao.</p>
This will produce following result:
Example for soft hyphen - The morbid fear of the number 13, or triskaidekaphobia, has plagued some
important historic figures like Mahamiya and Nanao.
NOTE: This may notwork with some web browsers.
</pre>
Presentational Tags:
If you use a word processor, you are 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.
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 is the same width.
<p>The following word uses a <tt>monospaced</tt> typeface.</p>
This will produce following result:
The following word uses a monospaced typeface.
To Become more comfortable - Do Online Practice
Actual content goes here.....The <span> element, on the other hand, can be used to group inline
elements only. So, if you had a part of a sentence or paragraph you wanted to group together you
could use the <span> element.
<div><p>This is the example of <span style="color:green">span tag</span> and the <span
style="color:purple">div tag</span> alongwith CSS</p></div>
This will produce following result:
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.
To Become more comfortable - Do Online Practice
For a complete list of HTML Tags and related attributes please check reference to HTML Tags
Reference.
While some of these phrase elements are displayed in a similar manner to the <b>, <i>, <pre>, and <tt>
elements you have already seen, they are designed for specific purposes. For example, the <em> and
<strong> elements give text emphasis and strong emphasis respectively and there are several elements
for marking up quotes.
We will see all phrase tags in this section with examples.
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.
You can use the cite attribute on the <blockquote> element to indicate the source of the quote.
<p>The following description of XHTML is taken from the W3C Web site:</p>
<blockquote cite="http://www.w3.org/markup/"> 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>
To Become more comfortable - Do Online Practice
the <code> element is presented in a monospaced font, just like the code in most programming books.
<h1> <code>This is inside code element</code></h1>
But following line is not a valid comment and will be displayed by the borwser. This is because there is
a space between the left angle bracket and the exclamation mark.
< !--
Be careful if you use comments to "comment out" HTML that would otherwise be shown to the user,
since some older browsers will still pay attention to angle brackets inside the comment and close the
comment prematurely -- so that some of the text that was supposed to be inside the comment
mistakenly appears as part of the document.
Multiline Comments:
You have seen how to comment a single line in HTML. You can comment multiple lines by the special
beginning tag <!-- and ending tag --> placed before the first line and end of the lastline to be treated as
a comment.
For example:
<!-This is a multiline comment <br />
and can span through as many as lines you like.
-->
Conditional Comments :
Conditional comments only work in Explorer on Windows, and are thus excellently suited to give
special instructions meant only for Explorer on Windows. They are supported from Explorer 5
onwards, and it is even possible to distinguish between 5.0, 5.5 and 6.0.
Conditional comments work as follows:
<!--[if IE 6]>
Special instructions for IE 6 here
<![endif]-->
Their basic structure is the same as an HTML comment (<!-- -->). Therefore all other browsers
will see them as normal comments and will ignore them entirely.
Explorer Windows, though, has been programmed to recognize the special <!--[if IE]> syntax,
resolves the if and parses the content of the conditional comment as if it were normal page
content.
Since conditional comments use the HTML comment structure, they can only be included in
HTML files, and not in CSS files.
Similarly if you are using Casecading Style Sheet in your HTML code then it is recommended to put
that style sheet code inside proper HTML Comments to make old browser works properly.
For example:
<style>
<!-img{
border:0px;
}
//-->
</style>
NOTE: To become familiar with JAVA Script and Cascading Style Sheet you need to refer different
tutorial.
Font face and color depends entirely on the computer and browser that is being used to view your page.
But the <font> tag is used to add style, size, and color to the text on your site. 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, and face to customize your fonts.
To change any of the font attributes at any time within your page, simply use the <font> tag. The text
that follows will remain changed until you close with the </font> tag. You can change any or all of the
font attributes at the one time, by including all the required changes within the 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 it should not be used. Its is suggested to use css styles to manipulate your
font.
Font Size:
You can set the size of your font with size attribute. The range of accepted values is from 1(smallest) to
7(largest). The default size of a font is 3.
Example:
<font
<font
<font
<font
<font
<font
<font
size="1">Font
size="2">Font
size="3">Font
size="4">Font
size="5">Font
size="6">Font
size="7">Font
size="1"</font>
size="2"</font>
size="3"</font>
size="4"</font>
size="5"</font>
size="6"</font>
size="7"</font>
Font size="2"
Font size="3"
Font size="4"
Font size="5"
Font size="6"
Font size="7"
SPECIFY THE RELATIVE FONT SIZE. <font size="+n"> or <font size="-n">:
You can specify how many sizes larger or how many sizes smaller than the preset font size should be.
Example:
<font
<font
<font
<font
<font
size="-1">Font
size="+1">Font
size="+2">Font
size="+3">Font
size="+4">Font
size="-1"</font>
size="+1"</font>
size="+2"</font>
size="+3"</font>
size="+4"</font>
Font size="+1"
Font size="+2"
Font size="+3"
Font size="+4"
Font Face:
You can set any font you like 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 they will default to Times New Roman of
your font with size attribute. See below few examples on using different font face
Example:
<font
<font
<font
<font
<font
When your page is loaded, their browser will display the first font face that it has available. If none of
your selections are installed....then it will display the default font face Times New Roman.
Check a complete list of HTML Standard Fonts.
Font Color:
You can set any font color you like using color attribute. You can specify the color that you want by
either the color name or hexadecimal code for that color. Check a complete list of HTML Color Name
with Codes.
Example:
<font color="#FF00FF">This text is hexcolor #FF00FF</font>
<font color="red">This text is red</font>
Example:
<basefont face="arial, verdana, sans-serif" size="2" color="#ff0000">
<p>This is the page's default font.</p>
<h2>Example of the <basefont> Element</h2>
<p><font size="+2" color="darkgray">Here is some darkgray text
two sizes larger</font></p>
<p><font face="courier" size="-1" color="#000000">Here is a courier
font, a size smaller, in black</font></p>
As you can see, the default font now takes on the properties specified in the <basefont> element. It is
red, size 2, and uses the Arial typeface.
The paragraph after the <h2> element uses a font size two sizes larger than the default size and is gray
text, whereas the following paragraph uses a font one size smaller than the default font. You can also
see that the color of this font is black (overriding the default).
A HTML marquee is a scrolling piece of text displayed either horizontally across or vertically down
your web site page depending on the settings. This is created by using HTML tag <marquees>.
NOTE: The HTML <marquee> is an MSIE extension, but is now supported by NS 7 also. So please
check if your browser supports this tag or not.
Syntax:
A simple syntax to use marquee is as follows:
<marquee attribute_name="attribute_value"....more attributes>
One or more lines or text message or image
</marquee>
Attrubutes:
A HTML marquee can have following attributes:
width: how wide the marquee is. This will have a value like 10 or 20%etc.
height: how tall the marquee is. This will have a value like 10 or 20% etc.
direction: which direction the marquee should scroll. This will have value either up, down, left
or right.
behavior: what type of scrolling. This will have value scroll, slid and alternate.
scrolldelay: how long to delay between each jump. This will have a value like 10 etc.
scrollamount: how far to jump. This will have a value like 10 etc.
loop: how many times to loop. The default value is INFINITE, which means that the marquee
loops endlessly.
bgcolor: background color. This will have any color name or color hex value.
hspace: horizontal space around the marquee. This will have a value like 10 or 20%etc.
vspace: vertical space around the marquee. This will have a value like 10 or 20%etc.
Examples:
Here are few examples to demonstrate the usage of marquee tag.
To Become more comfortable - Do Online Practice
<marquee>This is basic example of marquee</marquee>
This will produce following result:
Image Attributes:
Following are most frequently used attributes for <img> tag.
width: sets width of the image. This will have a value like 10 or 20%etc.
height: sets height of the image. This will have a value like 10 or 20% etc.
border: sets a border around the image. This will have a value like 1 or 2 etc.
src: specifies URL of the image file.
alt: this is an alternate text which will be displayed if image is missing.
align: this sets horizontal alignment of the image and takes value either left, right or center.
valign: this sets vertical alignment of the image and takes value either top, bottom or center.
hspace: horizontal space around the image. This will have a value like 10 or 20%etc.
vspace: vertical space around the image. This will have a value like 10 or 20%etc.
name: name of the image with in the document.
id: id of the image with in the document.
style: this will be used if you are using CSS.
title: specifies a text title. The browser, perhaps flashing the title when the mouse passes over
the link.
ismap and usemap: These attributes for the <img> tag tell the browser that the image is a
special mouse-selectable visual map of one or more hyperlinks, commonly known as an image
map. We will see how to use these attributes in Image Links chapter.
A Simple Example:
<img src="http://www.tutorialspoint.com/images/html.gif" alt="HTML Tutorial" />
This will produce following result:
Remember that all the images will have a border by default. In our examples its not showing because
our global style sheet has set img {border:0px;} which means that no border will be displayed till it is
mentioned explicitly.
You can remove an image border by setting border="0" or through CSS by setting img
{border:0px;}.
To Become more comfortable with other image attributes - Do Online Practice
The image will appear along the right hand side of the paragraph. As you can see this is very nice for
adding a little eye candy that relates to the specified paragraph.</p>
<p>The left and right image-alignment values tell the browser to place an image against the left or
right margin, respectively, of the current text flow. The browser then renders subsequent document
content in the remaining portion of the flow adjacent to the image. The net result is that the document
content following the image gets wrapped around the image. </p>
This will produce following result:
This is the first paragraph that appears above the paragraph with the image!
The image will appear along the right hand side of the paragraph. As you can see this is very nice for
adding a little eye candy that relates to the specified paragraph.
The left and right image-alignment values tell the browser to place an image against the
left or right margin, respectively, of the current text flow. The browser then renders
subsequent document content in the remaining portion of the flow adjacent to the image.
The net result is that the document content following the image gets wrapped around the image.
Example 2:
You can use vspace or hspace attributes if you want to keep some distance between text and image. Let
us revise above example:
<p>This is the first paragraph that appears above the paragraph with the image!</p>
<p><img src="http://www.tutorialspoint.com/images/html.gif" vspace="10" hspace="15" width="75"
height="75" alt="HTML Tutorial" align="right">
The image will appear along the right hand side of the paragraph. As you can see this is very nice for
adding a little eye candy that relates to the specified paragraph.</p>
<p>The left and right image-alignment values tell the browser to place an image against the left or
right margin, respectively, of the current text flow. The browser then renders subsequent document
content in the remaining portion of the flow adjacent to the image. The net result is that the document
content following the image gets wrapped around the image. </p>
This will produce following result:
This is the first paragraph that appears above the paragraph with the image!
The image will appear along the right hand side of the paragraph. As you can see this is very nice for
adding a little eye candy that relates to the specified paragraph.
The left and right image-alignment values tell the browser to place an image against the left or right
margin, respectively, of the current text flow. The browser then renders subsequent document content
in the remaining portion of the flow adjacent to the image. The net result is that the document content
following the image gets wrapped around the image.
For a complete list of image attributes please check reference to HTML Image Tag.
Image Attributes:
Following are most frequently used attributes for <img> tag.
width: sets width of the image. This will have a value like 10 or 20%etc.
height: sets height of the image. This will have a value like 10 or 20% etc.
border: sets a border around the image. This will have a value like 1 or 2 etc.
src: specifies URL of the image file.
A Simple Example:
<img src="http://www.tutorialspoint.com/images/html.gif" alt="HTML Tutorial" />
This will produce following result:
Remember that all the images will have a border by default. In our examples its not showing because
our global style sheet has set img {border:0px;} which means that no border will be displayed till it is
mentioned explicitly.
You can remove an image border by setting border="0" or through CSS by setting img
{border:0px;}.
To Become more comfortable with other image attributes - Do Online Practice
right margin, respectively, of the current text flow. The browser then renders subsequent document
content in the remaining portion of the flow adjacent to the image. The net result is that the document
content following the image gets wrapped around the image. </p>
This will produce following result:
This is the first paragraph that appears above the paragraph with the image!
The image will appear along the right hand side of the paragraph. As you can see this is very nice for
adding a little eye candy that relates to the specified paragraph.
The left and right image-alignment values tell the browser to place an image against
the left or right margin, respectively, of the current text flow. The browser then
renders subsequent document content in the remaining portion of the flow adjacent
to the image. The net result is that the document content following the image gets
wrapped around the image.
For a complete list of image attributes please check reference to HTML Image Tag.
This was the simpletest way of creating hyperlinks using images. Next we will see how we can create
Mouse-Sensitive Images:
The HTML and XHTML standards provide a feature that lets you embed many different links inside
the same image. Clicking different areas of the image causes the browser to link to different target
documents. Such mouse-sensitive images known as image maps.
There are two ways to create image maps:
A server-side image maps: is enabled by the ismap attribute for the <img> tag and requires
access to a server and related image-map processing applications.
A client-side image maps: is created with the usemap attribute for the <img> tag, along with
corresponding <map> and <area> tags.
Then the browser sends the following search parameters to the HTTP server which can be processed by
cgi script or map file and you can link whatever you like to these coordinates:
/cgi-bin/logo.map?50,30
The actual value of coords is totally dependent on the shape in question. Here is a summary, to be
followed by detailed examples:
rect = x1 , y1 , x2 , y2
x1 and y1 are the coordinates of the upper left corner of the rectangle; x2 and y2 are the
coordinates of the lower right corner. Therefore, a rectangle which goes from 10,5 to 20,25 would
have the attribute coords="10,5,20,25". A rectangle which defines the upper-left quarter of an
image might use coords="0,0,50%,50%".
circle = xc , yc , radius
xc and yc are the coordinates of the center of the circle, and radius is the circle's radius. A circle
centered at 200,50 with a radius of 25 would have the attribute coords="200,50,25"; one centered
at the image's center and having a diameter of half the image would be defined by
coords="50%,50%,25%".
poly = x1 , y1 , x2 , y2 , x3 , y3 , ... xn , yn
The various x-y pairs define vertices (points) of the polygon, with a "line" being drawn from one
point to the next point. A diamond-shaped polygon with its top point at 20,20 and 40 pixels across
at its widest points would have the attribute coords="20,20,40,40,20,60,0,40". A "line" is always
drawn from the coordinates of the last point to the coordinates of the first point in order to close
the polygon.
All coordinates are relative to the upper-left corner of the image (0,0). Each shape has a related
URL.You can use any image software to know the coordinates of different positions.
To Become more comfortable - Do Online Practice
NOTE: Following image crop utility can help you to identify image cordinates online Image Crop
Utility. Just upload your image and click the area to identify cordinates of that area.
This is very easy to put an HTML email link on your page. But while doing so, you need to put your
email address on your web page which can cause a spamming problem for your email account. There
are many guys over the internet who can run programs to harvest these types of emails for spamming.
So if you are going to put your email link on a public website then you have be prepared for antispamming as well.
You can have another option to facilitate people to send you emails. This option is to use HTML forms
to take user data and then use CGI script to send an email.
A simple example, check our Contact Us Form. We take user feedback using this form and then we are
using one CGI program which is collecting this information and sending email to one given email ID.
You will learn about HTML Forms in HTML Forms and you can learn about CGI in our another
tutorial PERL & CGI.
Tables are very useful to arrange in HTML and they are used very frequently by almost all web
developers. Tables are just like spreadsheets and they are made up of rows and columns.
You will create a table in HTML/XHTML by using <table> tag. Inside <table> element the table is
written out row by row. A row is contained inside a <tr> tag . which stands for table row. And each cell
is then written inside the row element using a <td> tag . which stands for table data.
Example:
<table border="1">
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
</tr>
</table>
This will produce following result. You can see its making heading as a bold one:
Name
Salary
Ramesh Raman 5000
Salary
Ramesh Raman
5000
Shabbir Hussein
7000
</table>
Column 2
Column 3
Row 1 Cell 2 Row 1 Cell 3
Row 1 Cell 1
Row 2 Cell 2 Row 2 Cell 3
Row 3 Cell 1
To Become more comfortable - Do Online Practice
Tables Backgrounds
You can set table background using of the following two ways:
Using bgcolor attribute - You can set background color for whole table or just for one cell.
Using background attribute - You can set background image for whole table or just for one cell.
NOTE:You can set border color also using bordercolor attribute.
Here is an example of using bgcolor attribute:
<table border="5" bordercolor="green" bgcolor="gray">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr><td rowspan="2">Row 1 Cell 1</td>
<td bgcolor="red">Row 1 Cell 2</td><td>Row 1 Cell 3</td></tr>
<tr><td>Row 2 Cell 2</td><td>Row 2 Cell 3</td></tr>
<tr><td colspan="3">Row 3 Cell 1</td></tr>
</table>
Column 2
Column 3
Row 1 Cell 2 Row 1 Cell 3
Row 1 Cell 1
Row 2 Cell 2 Row 2 Cell 3
Row 3 Cell 1
To Become more comfortable - Do Online Practice
Here is an example of using background attribute:
<table border="1" background="/images/home.gif">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr><td rowspan="2">Row 1 Cell 1</td>
<td bgcolor="red">Row 1 Cell 2</td><td>Row 1 Cell 3</td></tr>
<tr><td>Row 2 Cell 2</td><td>Row 2 Cell 3</td></tr>
<tr><td colspan="3" background="/images/pattern1.gif">
Row 3 Cell 1
</td></tr>
</table>
Column 2
Column 3
Row 1 Cell 2 Row 1 Cell 3
Row 1 Cell 1
Row 2 Cell 2 Row 2 Cell 3
Row 3 Cell 1
To Become more comfortable - Do Online Practice
width="400" height="150">
1</td>
2</td>
1</td>
2</td>
Row 1, Column 2
Row 2, Column 2
</tr>
</table>
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>.
Following is the example of using another table and other tags inside a table cell.
<table border="1">
<tr>
<td>
<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>
</tr>
</table>
</td>
<td>
<ul>
<li>This is another cell</li>
<li>Using list inside this cell</li>
</ul>
</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
</tr>
</table>
Name
Row 2, Column 1This is
another cell
Using list inside
this cell
Salary
Ramesh Raman 5000
Shabbir Hussein 7000
Row 2, Column 2
Frames divide a browser window into several pieces or panes, each pane containing a separate
XHTML/HTML document. One of the key advantages that frames offer is that you can then load and
reload single panes without having to reload the entire contents of the browser window. A collection of
frames in the browser window is known as a frameset.
The window is divided up into frames in a similar pattern to the way tables are organized: into rows
and columns. The simplest of framesets might just divide the screen into two rows, while a complex
frameset could use several rows and columns.
There are few drawbacks also you should be aware of with frames are as follows:
Some browsers do not print well from framesets.
Some smaller devices cannot cope with frames, often because their screen is not big enough to
be divided up.
Some time your page will be displayed differently on different computers due to different screen
resolution.
The browser's back button might not work as the user hopes.
There are still few browsers who do not support farme technology.
To create a frameset document, first you need the <frameset> element, which is used instead of the
<body> element. The frameset defines the rows and columns your page is divided into, which in turn
specify where each individual frame will go. Each frame is then represented by a <frame> element.
You also need to learn the <noframes> element, which provides a message for users whose browsers do
not support frames.
Now we will discuss these tags in detail one by one.
created.
The values of the rows/columns indicate the amount of screen area each row/column will
occupy.
Each farme is indicated by <frame> tag and it defines what HTML document to put into the
frame.
Example:
Following is the example to create three horizontal frames:
<html>
<head>
<title>Frames example</title>
</head>
<frameset rows="10%,80%,10%">
<frame src="/html/top_frame.htm" />
<frame src="/html/main_frame.htm" />
<frame src="/html/bottom_frame.htm" />
<noframes>
<body>
Your browser does not support frames.
</body>
</noframes>
</frameset>
</html>
Now create three HTML files called top_frame.htm, main_frame.htm and bottom_frame.htm to be
loaded into three frames with some content.
To become more comfortable - Do Online Practice
rows: attribute works just like the cols attribute and can take 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.
border: attribute specifies the width of the border of each frame in pixels. For example
border="5". A value of zero specifies that no border should be there.
frameborder: specifies whether a three-dimensional border should be displayed between
frames. This attrubute takes value either 1 (yes) or 0 (no). For example frameborder="0"
specifies no border.
framespacing: specifies the amount of space between frames in a frameset. This can take any
integer value. For example framespacing="10" means there should be 10 pixels spacing
between each frames.
frame. The noresize attribute prevents a user from being able to resize the frame. For example
noresize="noresize".
scrolling: controls the appearance of the scrollbars that appear on the frame. This takes values
either "yes", "no" or "auto". For example scrolling="no" means it should not have scroll bars.
longdesc: allows you to provide a link to another page containing a long description of the
contents of the frame. For example longdesc="framedescription.htm"
There are two columns in this example. The first is 200 pixels wide and will contain the navigation bar.
The second column or frame will contain the main part of the page. The links on the left side
navigation bar will load pages into the right side main page.
Keep some content in main.htm file and the links in the menu.htm file look like this:
<a href="http://www.google.com" target="main_page">Google</a>
<br /><br />
<a href="http://www.microsoft.com" target="main_page">Microsoft</a>
<br /><br />
<a href="http://news.bbc.co.uk/" target="main_page">BBC News</a>
Vlaue
Description
_self
_blank
_parent
Loads the page into the parent window, which in the case of a single frameset is the main
browser window.
_top
Loads the page into the browser window, replacing any current frames..
The align attribute lets you control where the frame gets placed in line with the adjacent text or moved
to the edge of the document, allowing text to flow around the frame.
For inline alignment, use top, middle, or bottom as the value of this attribute. The frame is aligned with
the top, middle, or bottom of the adjacent text, respectively. To allow text to flow around the inline
frame, use the left or right values for this attribute. The frame is moved to the left or right edge of the
text flow, respectively, and the remaining content of the document is flowed around the frame. A value
of center places the inline frame in the middle of the display, with text flowing above and below.
You can list out your items, subjects or menu in the form of a list. HTML gives you three different
types of lists.
<ul> - An unordered list. This will list items using bullets
<ol> - A ordered list. This will use different schemes of numbers to list your items
<dl> - A definition list. This is arrange your items in the same way as they are arranged in a
dictionary.
Movie List
You can use type attribute to specify the type of bullet you like. By default its is a disc. Following are
the possible way:
<ul type="square">
<ul type="disc">
<ul type="circle">
Hindi
English
Maths
Physics
Hindi
English
Maths
Physics
items are numbered instead of bulleted. The numbering starts at one and is incremented by one for each
successive ordered list element tagged with <li>
This list is created by using <ol> tag. Each item in the list is marked with a number.
One Movie list is given below:
<center>
<h2>Movie List</h2>
</center>
<ol>
<li>Ram Teri Ganga Meli</li>
<li>Mera Naam Jocker</li>
<li>Titanic</li>
<li>Ghost in the ship</li>
</ol>
Movie List
1.
2.
3.
4.
You can use type attribute to specify the type of numbers you like. By default its is a generic numbers.
Following are the other possible way:
<ol
<ol
<ol
<ol
type="I">
type="i">
type="a">
type="A">
Upper-Case
Lower-Case
Lower-Case
Upper-Case
Numerals.
Numerals.
Letters.
Letters.
i. Hindi
ii. English
iii.Maths
iv. Physics
a.
b.
c.
d.
Hindi
English
Maths
Physics
A. Hindi
B. English
C. Maths
D. Physics
You can use start attribute to specify the beginning of any index. By default its is a first number or
character. In the following example index starts from 5:
<center>
<h2>Movie List</h2>
</center>
<ol start="5">
<li>Ram Teri Ganga Meli</li>
<li>Mera Naam Jocker</li>
<li>Titanic</li>
Movie List
5.
6.
7.
8.
Example:
<dl>
<dt><b>HTML</b></dt>
<dd>This stands for Hyper Text Markup Language</dd>
<dt><b>HTTP</b></dt>
<dd>This stands for Hyper Text Transfer Protocol</dd>
</dl>
</td>
<td style="background-color:#eeeeee;height:200px;
width:300px;text-align:top;">
Technical and Managerial Tutorials
</td>
</tr>
<tr>
<td colspan="2" style="background-color:#CC99FF;">
<center>
Copyright 2007 Tutorialspoint.com
</center>
</td>
</tr>
</table>
PHP<br />
PERL...
</td>
</tr>
<table>
Right Menu
HTML
PHP
PERL...
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.
The <body> tag has following attributes which can be used to set different colors:
bgcolor: Sets a color for the background of the page.
text: Sets a color for the body text.
alink: Sets a color for active links or selected links.
link: Sets a color for linked text.
vlink: Sets a color for visited links - that is, for linked text that you have already clicked on.
NOTE: It is recommended to use CSS to set background or text colors.
Gray
Silver
White
Yellow
Lime
Aqua
Fuchsia
Red
Green
Blue
Purple
Maroon
Olive
Navy
Teal
To Become more comfortable - Do Online Practice
Color HEX
#000000
#FF0000
#00FF00
#0000FF
#FFFF00
#00FFFF
#FF00FF
#C0C0C0
#FFFFFF
To Become more comfortable - Do Online Practice
Color RGB
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)
To Become more comfortable - Do Online Practice
000033
000066
000099
0000CC
0000FF
003300
003333
003366
003399
0033CC
0033FF
006600
006633
006666
006699
0066CC
0066FF
009900
009933
009966
009999
0099CC
0099FF
00CC00
00CC33
00CC66
00CC99
00CCCC
00CCFF
00FF00
00FF33
00FF66
00FF99
00FFCC
00FFFF
330000
330033
330066
330099
3300CC
3300FF
333300
333333
333366
333399
3333CC
3333FF
336600
336633
336666
336699
3366CC
3366FF
339900
339933
339966
339999
3399CC
3399FF
33CC00
33CC33
33CC66
33CC99
33CCCC
33CCFF
33FF00
33FF33
33FF66
33FF99
33FFCC
33FFFF
660000
660033
660066
660099
6600CC
6600FF
663300
663333
663366
663399
6633CC
6633FF
666600
666633
666666
666699
6666CC
6666FF
669900
669933
669966
669999
6699CC
6699FF
66CC00
66CC33
66CC66
66CC99
66CCCC
66CCFF
66FF00
66FF33
66FF66
66FF99
66FFCC
66FFFF
990000
990033
990066
990099
9900CC
9900FF
993300
993333
993366
993399
9933CC
9933FF
996600
996633
996666
996699
9966CC
9966FF
999900
999933
999966
999999
9999CC
9999FF
99CC00
99CC33
99CC66
99CC99
99CCCC
99CCFF
99FF00
99FF33
99FF66
99FF99
99FFCC
99FFFF
CC0000
CC0033
CC0066
CC0099
CC00CC
CC00FF
CC3300
CC3333
CC3366
CC3399
CC33CC
CC33FF
CC6600
CC6633
CC6666
CC6699
CC66CC
CC66FF
CC9900
CC9933
CC9966
CC9999
CC99CC
CC99FF
CCFF33
CCFF66
CCFF99
CCFFCC
CCFFFF
FF0000
FF0033
FF0066
FF0099
FF00CC
FF00FF
FF3300
FF3333
FF3366
FF3399
FF33CC
FF33FF
FF6600
FF6633
FF6666
FF6699
FF66CC
FF66FF
FF9900
FF9933
FF9966
FF9999
FF99CC
FF99FF
FFCC00
FFCC33
FFCC66
FFCC99
FFCCCC
FFCCFF
FFFF00
FFFF33
FFFF66
FFFF99
FFFFCC
FFFFFF
HTML Forms are required when you want to collect some data from the site visitor. For example
registration information: name, email address, credit card, etc.
A form will take input from the site visitor and then will post your back-end application such as CGI,
ASP Script or PHP script etc. Then your back-end application will do required processing on that data
in whatever way you like.
Form elements are like text fields, textarea fields, drop-down menus, radio buttons, checkboxes, etc.
which are used to take information from the user.
A simple syntax of using <form> is as follows:
<form action="back-end script" method="posting method">
form elements like input, textarea etc.
</form>
Enter description
here...
submit
Reset
Button
Physics
Select Subject
Physics
Select Subject
This is page 10
Next Page
This will produce following result. Type something and click reset button.
First name:
Last name:
submit
Reset
You can add music or video into your web page. The easiest way to add video or sound to your web site
is to include the special HTML tag called <embed>. This tag causes the browser itself to include
controls for the multimedia automatically. You do not need to have any ActiveX, Java VM, VBscript or
JavaScript to support this <embed> tag.
t's also a good idea to include the <noembed> tag to support 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.
Here is a simple example to play embed a midi file:
<embed src="/html/yourfile.mid" width="100%" height="60" >
<noembed><img src="yourimage.gif" ></noembed>
</embed>
You can put any media file in src attribute. You can try it yourself by giving various files.
Attributes:
Following is the list of important attributes for <embed> element.
align - Determines how to align the object. It takes either center, left or right.
autostart - Indicates if the media should start automatically. Netscape default is true, Internet
Explorer is false.
loop - Specifies if the sound should be played continuously (set loop to true), a certain number
of times (a positive value) or not at all (false). This is supported by Netscape only.
playcount - Specifies the number of times to play the sound. This is alternat option for loop if
you are usiong IE.
hidden - Defines if the object shows on the page. A false value means no and true means yes.
height - Height of the object in pixels or en.
width - Width of the object in pixels or en.
pluginspage - Specifies the URL to get the plugin software.
name - A name used to reference the object.
src - URL of the object to be embedded. This can be any recognizable by the user's browser. It
could be .mid, .wav, .mp3, .avi and so on).
volume - Controls volume of the sound. Can be from 0 (off) to 100 (full volume). This attribute
is supported by Netscape only.
.swf files - are the file types created by Macromedia's Flash program.
.wmv files - are Microsoft's Window's Media Video file types.
.mov files - are Apple's Quick Time Movie format.
.mpeg files - are movie files created by the Moving Pictures Expert Group.
This will produce following result. Select a picture and paint it using virtual bursh.
<img src="yourimage.gif"
alt="yourimage.gif" />
This will produce blank screen. This tag does not display any component and remains hidden.
<img src="yourimage.gif" alt="Your Image Will Display Here" />
Currently, Internet Explorer can handle 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.
Here alt attribute will come into picture if browser does not support object tag.
You can embed a PDF document in an HTML document as follows:
<object data="data/test.htm" type="application/pdf"
width="300" height="200">
alt : <a href="data/test.pdf">test.pdf</a>
</object>
You can specify some parameters related to the document with the param tag. IE sometimes needs a src
parameter to understand the location. Here is an exmaple to embed a wav file:
<object type="audio/x-wav" data="data/test.wav"
width="200" height="20">
<param name="src" value="data/test.wav">
<param name="autoplay" value="false">
<param name="autoStart" value="0">
alt : <a href="data/test.wav">test.wav</a>
</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.
For a complete list of attributes of this object please check HTML Object Tag.
Just like any referenced document, the server delivers the desired multimedia object to the browser
when the user selects the link. If the browser finds that the document is not HTML or XHTML but
rather some other format, it automatically invokes an appropriate rendering tool to display or otherwise
convey the contents of the object to the user.
Browsers identify and specially handle multimedia files from one of two different hints: either from the
file's Multipurpose Internet Mail Extension (MIME) type, provided by the server, or from a special
suffix in the file's name. The browser prefers MIME because of its richer description of the file and its
contents, but it will infer the file's contents (type and format) from the file suffix: .gif or .jpg, for GIF
and JPEG encoded images, for example, or .au for a special sound file.
Style sheets 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) is a style sheet mechanism that has been specifically developed to meet
the needs of Web designers and users.
With 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 (;).
<p style="color:red;font-size:24px;">Using Style Sheet Rules</p>
This will produce following result:
</head>
External Script:
If you have to use a single script functionality among many HTML pages then it is a good idea to keep
that function in a single script file and then include this file in all the HTML pages. You can incluse a
style sheet file into HTML document using <script> element. Below is an example:
<head>
<script src="yourfile.js" type="text/javascript" />
</head>
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. You can specify whether to make a script run automatically (as
soon as the page loads), or after the user has done something (like click on a link). Below is an example
this would write a Hello Javascript! message as soon as the page loads.:
<head>
<title>Internal Script</title>
</head>
<body>
<script type="text/javascript">
document.write("Hello Javascript!")
</script>
</body>
Now this will produce following result. Bring your mouse over this line and see the result:
Bring your mouse here to see an alert
To become more comfortable - Do Online Practice
Note that you can still override the default by specifying a language within the script tag.