HTML
HTML
Before you begin, it's important that you know Windows or Unix. A working knowledge of Windows
or Unix makes it much easier to learn HTML.
← Basic understaning on internet browsing using a browser like Internet Explorer or Firefox
etc.
Introducing HTML:
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.
Creating an HTML document is easy. To begin coding HTML you need only two things: a simple-text
editor and a web browser. Notepad is the most basic of simple-text editors and you will probably
code a fair amount of HTML with it.
You can use our HTML Online Editor to learn HTML. Here are the simple steps to create a baisc
HTML document:
← On the next line, indent five spaces and now add the opening header tag: <head>.
← On the next line, indent ten spaces and type <title> </title>.
← Go to the next line, indent five spaces from the margin and insert the closing header tag:
</head>.
← Now drop down another line and type the closing tag right below its mate: </body>.
← Click Save.
You have basic HTML document now, to see some result put the
following code in title and body tags.
<html>
<head>
<title>This is document title</title>
</head>
<body>
<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.
An HTML document starts and ends with <html> and >/html> tags. These tags tell the browser
that the entire document is composed in HTML. Inside these two tags, the document is split into two
sections:
← The <head>...</head> elements, which contain information about the document such as
title of the document, author of the document etc. Information inside this tag does not
display outside.
← The <body>...</body> elements, which contain the real content of the document that you
see on your screen.
HTML Tags and Elements:
HTML language is a markup language and we use many tags to markup text. In the above example
you have seen <html>, <body> etc. are called HTML tags or HTML elements.
Every tag consists of a tag name, sometimes followed by an optional list of tag attributes , all
placed between opening and closing brackets (< and >). The simplest tag is nothing more than a
name appropriately enclosed in brackets, such as <head> and <i>. More complicated tags contain
one or more attributes , which specify or modify the behavior of the tag.
According to the HTML standard, tag and attribute names are not case-sensitive. There's no
difference in effect between <head>, <Head>, <HEAD>, or even <HeaD>; they are all equivalent.
But with XHTML, case is important: all current standard tag and attribute names are in lowercase.
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.
HTML Basic Tags
The basic structure for all HTML documents is simple and should include the following minimum
elements or tags:
Remember that before an opening <html> tag, an XHTML document can contain the optional XML
declaration, and it should always contain a DOCTYPE declaration indicating which version of XHTML
it uses.
Now we will explain each of these tags one by one. In this tutorial you will find the terms element
and tag are used interchangeably.
The <html> element is the containing element for the whole HTML document. Each HTML document
should have one <html> and each document should end with a closing </html> tag.
← <head>
← <body>
As such, start and end HTML tags enclose all the other HTML tags you use to describe the Web
page.
The <head> element is just a container for all other header elements. It should be the first thing to
appear after the opening <html> tag.
Each <head> element should contain a <title> element indicating the title of the document,
although it may also contain any combination of the following elements, in any order:
← The <base> tag is used to areate a "base" url for all links on the page. Check HTML Base
tag.
← The <object> tag is designed to include images, JavaScript objects, Flash animations, MP3
files, QuickTime movies and other components of a page. Check HTML Object tag.
← The <link> tag is used to link to an external file, such as a style sheet or JavaScript file.
Check HTML Link tag.
← The <style> tag is used to include CSS rules inside the document. Check HTML Style tag.
← The <script> tag is used to include JAVAScript or VBScript inside the document. Check
HTML Script tag.
← The <meta> tag includes information about the document such as keywords and a
description, which are particularly helpful for search applications. Check HTML Meta tag.
Example:
<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>
You should specify a title for every page that you write inside the <title> element. This element is a
child of the <head> element). It is used in several ways:
← Its is used by search engines that use its content to help index pages.
Therefore it is important to use a title that really describes the content of your site. The <title>
element should contain only the text for the title and it may not contain any other elements.
Example:
<head>
<title>HTML Basic tags</title>
</head>
The <body> element appears after the <head> element and contains the part of the Web page that
you actually see in the main browser window, which is sometimes referred to as body content.
A <body> element may contain anything from a couple of paragraphs under a heading to more
complicated layouts containing forms and tables.
Most of what you will be learning in this and the following five chapters will be written between the
opening <body> tag and closing </body> tag.
Example:
<body>
<p>This is a paragraph tag.</p>
</body>
Now if we will put all these tags together, it will constitute a complete
HTML document as follows:
<html>
<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>
<body>
<p>This is a paragraph tag.</p>
</body>
</html>
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.
You can add metadata to your web pages by placing <meta> tags
between the <head> and </head> tags. The can include the following
attributes:
Attribut
Description
e
Name for the property. Can be anything. Examples include, keywords, description,
Name
author, revised, generator etc.
Specifies a scheme to use to interpret the property's value (as declared in the content
scheme
attribute).
Used for http response message headers. For example http-equiv can be used to
http-
refresh the page or to set a cookie. Values include content-type, expires, refresh and
equiv
set-cookie.
NOTE: Core attributes for all the elements are discussed in next chapter.
Specifying Keywords:
<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 Revision date:
This information tells about last time the document was updated.
<head>
<meta name="revised" content="Tutorialspoint, 6/12/2006" />
</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:
<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.
<head>
<meta name="author" content="Mahnaz Mohtashim" />
</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.
HTML Attributes
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.
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 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:
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.
The title attribute gives a suggested title for the element. They syntax for the title attribute is
similar as explained for id attribute:
The behavior of this attribute will depend upon the element that carries it, although it is often
displayed as a tooltip or while the element is loading.
For example:
Now try to bring your cursor over "Titled Heading Tag Example" and see the result.
The class attribute is used to associate an element with a style sheet, and specifies the class of
element. You learn more about the use of the class attribute when you will learn Casecading Style
Sheet (CSS). So for now you can avoid it.
The style attribute allows you to specify CSS rules within the element.
For example:
<p style="font-family:arial; color:#FF0000;">Some text...</p>
Internationalization Attributes:
There are three internationalization attributes, which are available to most (although not all) XHTML
elements.
← dir
← lang
← xml:lang
Value Meaning
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.
The lang attribute allows you to indicate the main language used in a document, but this attribute
was kept in HTML only for backwards compatibility with earlier versions of HTML. This attribute has
been replaced by the xml:lang attribute in new XHTML documents.
When included within the <html> tag, the lang attribute specifies the language you've generally
used within the document. When used within other tags, the lang attribute specifies the language
you used within that tag's content. Ideally, the browser will use lang to better render the text for
the user.
The values of the lang attribute are ISO-639 standard two-character language codes.Check HTML
Language Codes: ISO 639 for a complete list of language codes.
Example:
<html lang=en>
<head>
<title>English Language Page</title>
</head>
<body>
This page is using English Language
</body>
</html>
The xml:lang attribute is the XHTML replacement for the lang attribute. The value of the xml:lang
attribute should be an ISO-639 country code as mentioned in previous section.
Generic Attributes:
Here's a table of some other attributes that are readily usable with
many of HTML's tags.
valign top, middle, bottom Vertically aligns tags within an HTML element.
backgroun
URL Places an background image behind an element
d
width Numeric Value Specifies the width of tables, images, or table cells.
height Numeric Value Specifies the height of tables, images, or table cells.
We will see related examples as we will proceed to study other HTML tags.
HTML Formatting 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.
You might think that if you put several consecutive spaces between two words, the spaces would
appear between those words onscreen, but this is not the case; by default, only one space will be
displayed. This is known as white space collapsing. So you need to use special HTML tags to create
multiple spaces.
Similarly, if you start a new line in your source document, or you have consecutive empty lines,
these will be ignored and simply treated as one space. So you need to use special HTML tags to
create more number of empty lines.
This is heading 1
This is heading 2
This is heading 3
This is heading 4
This is heading 5
This is heading 6
The <p> element offers a way to structure your text. Each paragraph
of text should go in between an opening <p> and closing </p> tag as
shown below in the example:
This is jutified. This works when you have multiple lines in your paragraph and you want to justfy
all the lines so that they can look more nice.
Note: The <br /> element 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 XHTML
Example:
Hello<br />
You come most carefully upon your hour.<br />
Thanks<br />
Mahnaz
Hello
Thanks
Mahnaz
Example:
<p>This is not in the center.</p>
<center>
<p>This is in the center.</p>
</center>
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:
Soft Hyphens:
<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>
<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>
Any text between the opening <pre> tag and the closing </pre> tag
will preserve the formatting of the source document.
<pre>
function testFunction( strText ){
alert (strText)
}
</pre>
For example you may want to give a line between two paragraphs as
follows:
Note: The <hr /> element 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 <hr> it is not valid XHTML
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.
The content of the <big> element is displayed one font size larger
than the rest of the text surrounding it.
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.
Content Articles
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.
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.
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.
You can indicate when you are using an abbreviated form by placing
the abbreviation between opening <abbr> and closing </abbr> tags.
When possible use a title attribute whose value is the full version of
the acronyms on the <acronym> element, and if the acronym is in a
different language, include an xml:lang attribute in XHTML documents.
At present, the major browsers do not change the appearance of the content of the <acronym>
element.
<p>This tutorial teaches you how mark up your documents for the web using
<dfn>XHTML</dfn>.</p>
This tutorial teaches you how mark up your documents for the web using XHTML.
<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>
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.
<p>The following description of XHTML is taken from the W3C Web site:</p>
The <q> element can also carry the cite attribute. The value should be a URL pointing to the source
of the quote.
<p>This HTML Tutorial is derived from <cite>World Wide Web Standard for HTML</cite>.</p>
This HTML Tutorial is derived from World Wide Web Standard for HTML.
<p><code>document.write("<var>user-name</var>")</code></p>
document.write("user-name")
← 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.
The elements which we have not discussed till now, will be discussed in subsequent chapters.
HTML Comments
Comments are piece of code which is ignored by any web browser. It is good practice to comment
your code, especially in complex documents, to indicate sections of a document, and any other
notes to anyone looking at the code. Comments help you and others understand your code.
HTML Comment lines are indicated by the special beginning tag <!-- and ending tag --> placed at
the beginning and end of EVERY line to be treated as a comment.
Comments do not nest, and the double-dash sequence "--" may not appear 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.
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.
<!--[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.
For example:
<script>
<!--
document.write("Hello World!")
//-->
</script>
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.
HTML Fonts
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 size="1"
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 size="-1">Font size="-1"</font>
<font size="+1">Font size="+1"</font>
<font size="+2">Font size="+2"</font>
<font size="+3">Font size="+3"</font>
<font size="+4">Font size="+4"</font>
Font size="-1"
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:
A visitor will only be able to see your font if they have that font installed on their computer. So, it is
possible to specify two or more font face alternatives by listing the font face names, separated by a
comma.
Example:
<font face="arial,helvetica">
<font face="Lucida Calligraphy,Comic Sans MS,Lucida Console>
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.
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:
The attributes that the <basefont> element takes are exactly the same as for the <font> element.
You can also set the size of fonts relative to the size of the <basefont> by giving them a value of
+1 for a size larger or -2 for two sizes smaller
NOTE: This element is deprecated in HTML 4 and will be removed from HTML, the preferred option
is to use CSS styles. Your browser may not have support for this tag.
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).
HTML Marquees
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:
</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
Images are very important to beautify as well as to depicts many concepts on your web page. Its is
true that one single image is worth than thuasands of words. So as a Web Developer you should
have clear understanding on how to use images in your web pages.
You will insert any image in your web page by using <img> tag.
Following is the simple syntax to use this 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.
← 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.
← 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" />
<img src="http://www.tutorialspoint.com/images/html.gif"
alt="HTML Tutorial" width="100" height="100"
border="2" align="right" title="HTML Tutorial" />
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;}.
Example 1:
<p>This is the first paragraph that appears above the paragraph with the image!</p>
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 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>
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>
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.
Ths images in Joint Photographic Experts Group - JPEG format have an unlimited color wheel, and
have a high compression rate downsizing your load times and saving hard drive space. JPEGs don't
allow for transparent backgrounds, but their size/quality ratio is outstanding. Its best to use JPEG
format for photo galleries, or artwork to allow the viewer to catch that extra bit of detail. Avoid
Jpegs for graphical design, stick to using them for thumbnails and backgrounds.
The images in Portable Network Graphics - PNG format is an extensible file format for the lossless,
portable, well-compressed storage of raster images. PNG provides a patent-free replacement for
GIF and can also replace many common uses of TIFF. Indexed-color, grayscale, and truecolor
images are supported, plus an optional alpha channel. Sample depths range from 1 to 16 bits. PNG
also compresses better than GIF in almost every case (5% to 25% in typical cases).
HTML Text Links
Web pages can contain links that take you directly to other pages and even specific parts of a given
page. These links are known as hyperlinks.
Hyperlinks allow visitors to navigate between Web sites by clicking on words, phrases, and images.
Thus you can create hyperlinks using text or images available on your any web page.
In this tutorial you will learn how to create text links between the different pages of your site, links
within pages of your sites, and how to link to other sites ( or external sites). If you want to know
more about URL then check Understanding URL Tutorial.
Anchor Attributes:
Following are most frequently used attributes for <a> tag.
← href: specifies the URL of the target of a hyperlink. Its value is any valid document URL,
absolute or relative, including a fragment identifier or a JavaScript code fragment.
← target: specify where to display the contents of a selected hyperlink. If set to "_blank"
then a new window will be opened to display the loaded page, if set to "_top" or "_parent"
then same window will be used to display the loaded document, if set to "_self" then loads
the new page in current window. By default its "_self".
← name & id: attributes places a label within a document. When that label is used in a link to
that document, it is the equivalent of telling the browser to goto that label.
← event: attributes like onClick, onMouseOver etc. are used to trigger any Javascript ot
VBscript code.
← title: attribute lets you specify a title for the document to which you are linking. The value
of the attribute is any string, enclosed in quotation marks. The browser might use it when
displaying the link, perhaps flashing the title when the mouse passes over the link.
← accesskey: attribute attribute provides a keyboard shortcut that can be used to activate a
link. For example, you could make the T key an access key so that when the user presses
either the Alt or Ctrl key on his keyboard (depending on his operating system) along with
the T key, the link gets activated.
A Simple Example:
<a href="http://www.tutorialspoint.com/" target="_blank" >TP Home</a> |
<a href="http://www.amrood.com/" target="_self" >AMROOD Home</a> |
<a href="http://www.change-images.com/" target="_top" >Change Images Home</a>
This will produce following result, Click and come back to proceed with
rest of the tutorial:
For example we have used following base tag in all the pages at
tutorialspoint.com:
<head>
<base href="http://www.tutorialspoint.com/">
</head>
So now if you will use <a href="/html/index.htm" then it will be considered as <a
href="http://www.tutorialspoint.com/html/index.htm".
Linking to a Page Section:
You can create a link to a particular section of a page by using name attribute. Here we will create
three links with-in this page itself.
First create a link to reach to the top of this page. Here is the code we have used for the title
heading HTML Text Links
Now you have a place where you can reach. To reach to this place use
the following code with-in this document anywhere:
This will produce following link and you try using this link to reach to
the top of this page:
Go to the Top
NOTE: Here we are using relative path. You can give complete URL and then # and then link name
eg. http://www.tutorialspoint.com/html/html_text_links.htm#top
You can use this type of URL in any other page to reach directly to a particular section.
You can refer to Style Sheet Tutorial for a complete understanding on CSS.
Otherwise you can use <body> tag to set link colors. Here is the
syntax.
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:
This will produce following link and will be used to download a file.
Download File
You can not make an image download able until you follow the following procedure.
Sometime it is desired that you want to give option where a use will click a link and it will pop up a
"File Download" box to the user in stead of displaying actual content. This is very easy and will be
achived through HTTP header.
This HTTP header will be different from the header mentioned in previous section.
#!/usr/bin/perl
# HTTP Header
print "Content-Type:application/octet-stream; name=\"FileName\"\r\n";
print "Content-Disposition: attachment; filename=\"FileName\"\r\n\n";
Previous chapters has tought you how to create hyper text link using
text and how to use images in your web page. Now we will learn how
to use images to create hyper links. See example below:
<a href="http://www.tutorialspoint.com/index.htm" target="_self" >
<img src="/images/home.gif" alt="Tutorials Point Home" border="0"/>
</a>
This was the simpletest way of creating hyperlinks using images. Next we will see how we can
create Mouse-Sensitive Image Links.
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.
← 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.
You add an image to an anchor simply by placing an <img> tag within the body of the <a> tag.
Make that embedded image into a mouse-sensitive one by adding the ismap attribute to the <img>
tag. This special <img> attribute tells the browser that the image is a special map containing more
than one link.
When the user clicks some place within the image, the browser passes the coordinates of the mouse
pointer along with the URL specified in the <a> tag to the document server. The server uses the
mouse-pointer coordinates to determine which document to deliver back to the browser.
When ismap is used, the href attribute of the containing <a> tag must contain the URL of a server
application like amap file or cgi script etc. to process the incoming request based on the passed
coordinates.
The coordinates of the mouse position are screen pixels counted from the upper-left corner of the
image, beginning with (0,0). The coordinates, preceded by a question mark, are added to the end of
the URL.
For example, if a user clicks 50 pixels over and 30 pixels down from
the upper-left corner of the image displayed from the following link:
/cgi-bin/logo.map?50,30
NOTE: Converting the coordinates into a specific document is handled by the server side
application, either cgi programme or special map files provided by seb server. For more detail Check
Using HTML ismap.
The image that is going to form the map is inserted into the page using the <img /> element as
normal, except it carries an extra attribute called usemap. The value of the usemap attribute is the
value of the name attribute on the <map> element, which you are about to meet, preceded by a
pound or hash sign.
The <map> element actually creates the map for the image and usually follows directly after the
<img /> element. It acts as a container for the <area /> elements that actually define the clickable
hotspots. The <map> element carries only one attribute, the name attribute, which is the name
that identifies the map. This is how the <img /> element knows which <map> element to use.
The <area> element specifies the shape and the coordinates that
define the boundaries of each clickable hotspot. Here's an example
from the image map:
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; x 2 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.
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 anti-spamming 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.
Send Email
Now if a user will click this link then it will lanuch one Email Client ( like Lotus Notes, Outlook
Express etc. ) installed on your user's computer.
This is another risk to use this procedure because if users do not have email client installed on their
computer then it would not be possible to send you email.
<a href="mailto:[email protected]?subject=Feedback&body=Message">
Send Feedback
</a>
Send Feedback
HTML Tables
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>
NOTE: In the above example border is an attribute of <table> and it will put border across all the
cells. If you do not need a border then you cal use border="0". The border attribute and other
attributes also mentione din this session are deprecated and they have been replaced by CSS. So it
is recommended to use CSS instead of using any attribute directly.
Table heading can be defined using <th> element. This tag will be put
to replace <td> tag which is used to represent actual data. Normally
you will put your top row as table heading as shown below, otherwise
you can use <th> element at any place:
<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>
This will produce following result. You can see its making heading as a
bold one:
Name Salary
Ramesh Raman 5000
Shabbir Hussein 7000
NOTE: Each cell must, however, have either a <td> or a <th> element in order for the table to
display correctly even if that element is empty.
Name Salary
<table border="1">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr><td rowspan="2">Row 1 Cell 1</td>
<td>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>
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.
<table border="1">
<caption>This is the caption</caption>
<tr>
<td>row 1, column 1</td><td>row 1, columnn 2</td>
</tr>
</table>
The three elements for separating the head, body, and foot of a table are:
or groups of data.
A table may contain several <tbody> elements to indicate different pages
But it is notable that <thead> and <tfoot> tags should appear before
<tbody>
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>
Salary
Name Ramesh Raman 5000
Shabbir Hussein 7000
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 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.
← Each frameset defines a set of rows or columns. If you define frames by using rows then
horizontal frames are created. If you define frames by using columns then vertical farmes
are 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:
<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.
← cols: specifies how many columns are contained in the frameset and the size of each
column. You can specify the width of each column in one of four ways:
← Absolute values in pixels. For example to create three vertical frames, use
cols="100, 500,100".
← A percentage of the browser window. For example to create three vertical frames,
use cols="10%, 80%,10%".
← Using a wildcard symbol. For example to create three vertical frames, use
cols="10%, *,10%". In this case wildcard takes remainder of the window.
← As relative widths of the browser window. For example to create three vertical
frames, use cols="3*,2*,1*". This is an alternative to percentages. You can use
relative widths of the browser window. Here the window is divided into sixths: the
first column takes up half of the window, the second takes one third, and the third
takes one sixth.
← 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.
← 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.
← src: indicates the file that should be used in the frame. Its value can be any URL. For
example, src="/html/top_frame.htm" will load an HTML file avaible in html directory.
← name: attribute allows you to give a name to a frame. It is used to indicate which frame a
document should be loaded into. This is especially important when you want to create links
in one frame that load pages into a second frame, in which case the second frame needs a
name to identify itself as the target of the link.
← frameborder: attribute specifies whether or not the borders of that frame are shown; it
overrides the value given in the frameborder attribute on the <frameset> element if one is
given, and the possible values are the same. This can take values either 1 (yes) or 0 (no).
← marginwidth: allows you to specify the width of the space between the left and right of
the frame's borders and the frame's content. The value is given in pixels. For example
marginwidth="10".
← marginheight: allows you to specify the height of the space between the top and bottom
of the frame's borders and its contents. The value is given in pixels. For example
marginheight="10".
← noresize: By default you can resize any frame by clicking and dragging on the borders of a
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"
In XHTML you must place a <body> element inside the <noframes> element because the
<frameset> element is supposed to replace the <body> element, but if a browser does not
understand the <frameset> element it should understand what is inside the <body> element
contained in the <noframes> element.
You can put some nice message for your user having old browsers. For example Sorry!! your
browser does not support frames.
attribute to give
As you have already seen, each <frame> element can carry the name
each frame a name.This name is used in the links to indicate which
frame the new page should load into. Consider this very simple
example, create following content in index.htm file:
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:
attribute can also take the attribute values listed in the table
The target
that follows.
Vlaue Description
_paren Loads the page into the parent window, which in the case of a single frameset is the
t main browser window.
_top Loads the page into the browser window, replacing any current frames..
Use the src attribute with <iframe> to specify the URL of the document that occupies the inline
frame.
All of the other, optional attributes for the <iframe> tag, including name, class, frameborder, id,
longdesc, marginheight, marginwidth, name, scrolling, style, and title behave exactly like the
corresponding attributes for the <frame> tag.
Following is the example to show how to use the <iframe>. This tag is
used along with <body> tag:
<body>
...other document content...
<iframe src="/html/menu.htm" width="75" height="200" align="right">
Your browser does not support inline frames. To view this
<a href="/html/menu.htm">document</a> correctly, you'll need
a copy of Internet Explorer or the latest Netscape Navigator.
</iframe>
...subsequent document content...
</body>
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.
← <dl> - A definition list. This is arrange your items in the same way as they are arranged in
a dictionary.
This list is created by using <ul> tag. Each item in the list is marked with a butllet. The bullet itself
comes in three flavors: squares, discs, and circles. The default bullet displayed by most web
browsers is the traditional full disc.
<center>
<h2>Movie List</h2>
</center>
<ul>
<li>Ram Teri Ganga Meli</li>
<li>Mera Naam Jocker</li>
<li>Titanic</li>
<li>Ghost in the ship</li>
</ul>
Movie List
<ul type="square">
<ul type="disc">
<ul type="circle">
This list is created by using <ol> tag. Each item in the list is marked with a number.
<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
<center>
<h2>Movie List</h2>
</center>
<ol start="5">
<li>Ram Teri Ganga Meli</li>
<li>Mera Naam Jocker</li>
<li>Titanic</li>
<li>Ghost in the ship</li>
</ol>
Movie List
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>
HTML
This stands for Hyper Text Markup Language
HTTP
This stands for Hyper Text Transfer Protocol
← Link collections
← Short, nonsequenced groups of text
← Tables of contents
← Sets of sequential sections of text
← Glossaries
← Custom bullets - make the item after the <dt> tag an icon-sized bullet image)
Web page layout is very important to give better look to your website. You should design your
webpage layout very carefully.
You may have noticed that there are many websites which have put their content in multiple
columns - they are formatted like a magazine or newspaper. This is easily achieved by using tables
or division or span tags. Sometime you use CSS as well to position various elements or to create
backgrounds or colorful look for the pages.
Although we can achieve pretty nice layouts with HTML tables, tables weren't really designed as a
layout tool. Tables are more suited to presenting tabular data.
You can achieve same result whatever you have achieved using
<table> tag in previous example.
<div style="width:100%">
<div style="background-color:#CC99FF;">
<b style="font-size:150%">This is Web Page Main title</b>
</div>
<div style="background-color:#FFCCFF;
height:200px;width:100px;float:left;">
<b>Main Menu</b><br />
HTML<br />
PHP<br />
PERL...
</div>
<div style="background-color:#eeeeee;
height:200px;width:300px;float:left;">
Technical and Managerial Tutorials
</div>
<div style="background-color:#CC99FF;clear:both">
<center>
Copyright © 2007 Tutorialspoint.com
</center>
</div>
</div>
Better layout can be created by using DIV, SPAN and CSS. For more information on CSS, please
refer CSS Tutorial.
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.
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 make up
the color.
← Color decimal or percentage values: : This value is specified using the rgb( ) property.
A hexadecimal value can be taken from any graphics software like Adobe Photoshop, Jasc Paintshop
Pro or even using Advanced Paint Brush.
#000000
#FF0000
#00FF00
#0000FF
#FFFF00
#00FFFF
#FF00FF
#C0C0C0
#FFFFFF
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)
Here is the list of 216 colors which are supposed to be most safe and
computer independent colors. These colors very from hexa code
000000 to FFFFFF. These color are safe to use because they ensure
that all computers would display the colors correctly when running a
256 color palette:
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.
← method: Here you will specify method to be used to upload data. It can take various
values but most frequently used are GET and POST.
← target: It specifies the target page where the result of the script will be displayed. It takes
values like _blank, _self, _parent etc.
← enctype: You can use the enctype attribute to specify how the browser encodes the data
before it sends it to the server. Possible values are like:
Please refer to PERL & CGI for a detail on data uploading using CGI.
There are different types of form controls that you can use to collect data from a visitor to your site.
← Hidden controls
← Single-line text input controls: Used for items that require only one line of user input,
such as search boxes or names. They are created using the <input> element.
← Password input controls: Single-line text input that mask the characters a user enters.
← Multi-line text input controls: Used when the user is required to give details that may be
longer than a single sentence. Multi-line input controls are created with the <textarea>
element.
First name:
Last name:
← type: Indicates the type of input control you want to create. This element is also used to
create other form controls such as radio buttons and checkboxes.
← name: Used to give the name part of the name/value pair that is sent to the server,
representing each form control and the value the user entered.
← value: Provides an initial value for the text input control that the user will see when the
form loads.
← size: Allows you to specify the width of the text-input control in terms of characters.
← maxlength: Allows you to specify the maximum number of characters a user can enter
into the text box.
Login :
Password :
Description :
← name: The name of the control. This is used in the name/value pair that is sent to the
server.
← rows: Indicates the number of rows of text area box.
When you use the <input> element to create a button, the type of button you create is specified
using the type attribute. The type attribute can take the following values:
← button: This creates a button that is used to trigger a client-side script when the user
clicks that button.
You can use <button> element to create various buttons. Here is the
syntax:
Submit
ResetButton
← value: The value that will be used if the checkbox is selected. More than one checkbox
should share the same name only if you want to allow users to select several items from
the same list.
← checked: Indicates that when the page loads, the checkbox should be selected.
Here is example HTML code for a form with two radio button:
Maths Physics
← value: Used to indicate the value that will be sent to the server if this option is selected.
← checked: Indicates that this option should be selected by default when the page loads.
← multiple: If set to "multiple" then allows a user to select multiple items from the menu.
← value: The value that is sent to the server if this option is selected.
← selected: Specifies that this option should be the initially selected value when the page
loads.
Here is example HTML code for a form with one file select box
<form action="/cgi-bin/hello_get.cgi"
method="get" name="pages">
<p>This is page 10</p>
<input type="hidden" name="pgaenumber" value="10" />
<input type="submit" value="Next Page" />
</form>
This is page 10
You already have seen submit button above, we will give one reset
example here:
First name:
Last name:
HTML Backgrounds
← Background Colors
← Background Images
Background Colors:
attribute is used to control the background of an HTML
The bgcolor
elmement, specifically page body and table backgrounds. Following is
the syntax to use bgcolor attribute with any HTML tag.
<tagname bgcolor="color_value"...>
Example:
Example:
Note that when your HTML element is larger than the dimensions of your picture, the image simply
begins to repeat itself.
It is suggested that when creating patterns or transparent gifs, use the smallest dimensions
possible even as small as 1x1 if you can. Larger files load slow and inhibit the load time of your
sites.
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.
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.
← 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.
This tag is having only two attributes loop and src. Both these attributes have same meaning as
explained above.
This will produce blank screen. This tag does not display any
component and remains hidden.
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 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 classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="penguin" codebase="someplace/swflash.cab"
width="200" height="300">
<param name="movie" value="flash/penguin.swf" />
<param name="quality" value="high" />
<img src="penguin.jpg" width="200"
height="300" alt="Penguin" />
</object>
<object
classid="clsid:8ad9c840-044e-11d1-b3e9-00805f499d93"
width="200" height="200">
<param name="code" value="applet.class">
</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.
HTML Styles
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 (;).
<head>
<link rel="stylesheet" type="text/css"
href="yourstyle.css">
</head>
If you want to apply Style Sheet rules to a single document only then
you can include those rules into that document only. Below is an
example:
<head>
<style type="text/css">
body{background-color: pink;}
p{color:blue; 20px;font-size:24px;}
</style>
</head>
You can apply style sheet rules directly to any HTML element. This
should be done only when you are interested to make a particular
change in any HTML element only. To use inline styles you use the
style attribute in the relevant tag. Below is an example:
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
Javascript or VBScript.
You can write your Event Handlers using any of the scripting language and then you can trigger
those functions using HTML attributes.
External Script:
<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>
Hello Javascript!
<head>
<title>Event Handler Example t</title>
<script type="text/javascript">
function myAlert()
{
alert("I am an event handler....");
return;
}
</script>
</head>
<body>
<span onmouseover="myAlert();">
Bring your mouse here to see an alert
</span>
</body>
Now this will produce following result. Bring your mouse over this line
and see the result:
Athough most (if not all) browsers these days support scripts, some
older browsers don't. If a browser doesn't support JavaScript, instead
of running your script, it would display the code to the user. To
prevent this from happening, you can simply place HTML comments
around the script. Older browsers will ignore the script, while newer
browsers will run it.
JavaScript Example:
<script type="text/javascript">
<!--
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>
<noscript>Your browser does not support Javascript!</noscript>
VBScript Example:
<script type="text/vbscript">
<!--
document.write("Hello VBScript!")
'-->
</script>
<noscript>Your browser does not support VBScript!</noscript>
Note that you can still override the default by specifying a language within the script tag.