HTML Tutorial
HTML Tutorial
HTML or Hypertext Markup Language, is the most widely used language on Web. Technically, HTML is not a programming language, but rather a markup language. This tutorial gives a complete understanding on HTML. Send your feedback using Contact Us Form
HTML Introduction
Before your begin:
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. You should be familiar with:
Basic word processing using any text editor. How to create directories and files. How to navigate through different directories. 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.
1|Page
Open Notepad or another text editor. At the top of the page type <html>. 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>. Five spaces in from the margin on the next line, type<body>. Now drop down another line and type the closing tag right below its mate: </body>. Finally, go to the next line and type </html>. In the File menu, choose Save As. In the Save as Type option box, choose All Files. Name the file template.htm. 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.
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 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> - The main container for HTML pages <head> - The container for page header information <title> - The title of the page <body> - The main body of the page
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.
<head> <body>
As such, start and end HTML tags enclose all the other HTML tags you use to describe the Web page.
3|Page
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:
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>
It displays at the very top of a browser window. It is used as the default name for a bookmark in browsers such as IE and Netscape. 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:
Here is the example of using title tag.
4|Page
Example:
Here is the example of using body tag.
<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>
To Become more comfortable - Do Online Practice
5|Page
content scheme
httpequiv
NOTE: Core attributes for all the elements are discussed in next chapter.
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.
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.
6|Page
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.
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.
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.
HTML Attributes
7|Page
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:
Core Attributes:
The four core attributes that can be used on the majority of HTML elements (although not all) are:
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.
Above code will generate following result: Titled Heading Tag Example Now try to bring your cursor over "Titled Heading Tag Example" and see the result.
Internationalization Attributes:
There are three internationalization attributes, which are available to most (although not all) XHTML elements.
9|Page
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.
<html lang=en> <head> <title>English Language Page</title> </head> <body> This page is using English Language </body> </html>
Generic Attributes:
Here's a table of some other attributes that are readily usable with many of HTML's tags. Attribute Options Function
10 | P a g e
Places an background image behind an element Names an element for use with Cascading Style Sheets. Classifies an element for use with Cascading Style Sheets. Specifies the width of tables, images, or table cells. Specifies the height of tables, images, or table cells. "Pop-up" title for your elements.
class
User Defined
width
Numeric Value
height
Numeric Value
title
User Defined
We will see related examples as we will proceed to study other HTML tags. For a complete list of HTML Tags and related attributes please check reference to HTML Tags List.
11 | P a g e
is is is is is is
This is heading 1
This is heading 2
This is heading 3
This is heading 4
This is heading 5
This is heading 6
<p>Here is a paragraph of text.</p> <p>Here is a second paragraph of text.</p> <p>Here is a third paragraph of text.</p>
This will produce following result: Here is a paragraph of text. Here is a second paragraph of text. Here is a third paragraph of text. You can use align attribute to align your paragraphs. <p align="left">This is left aligned.</p> <p align="center">This is center aligned.</p>
12 | P a g e
This will produce following result: This is left aligned. This is center aligned. This is right aligned. 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. To Become more comfortable - Do Online Practice
Hello<br /> You come most carefully upon your hour.<br /> Thanks<br /> Mahnaz
This will produce following result:
Hello You come most carefully upon your hour. Thanks Mahnaz
To Become more comfortable - Do Online Practice
13 | P a g e
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.
14 | P a g e
<p>This is paragraph one and should be on top</p> <hr /> <p>This is paragraph two and should be at bottom</p>
This will produce following result: This is paragraph one and should be on top
This is paragraph two and should be at bottom Again <hr /> tag is an example of an empty element, where you do not need opening and closing tags, as there is nothing to go in between them. 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 To Become more comfortable - Do Online Practice
15 | P a g e
This will produce following result: The following word uses a bold typeface. To Become more comfortable - Do Online Practice
This will produce following result: The following word uses a italicized typeface. To Become more comfortable - Do Online Practice
This will produce following result: The following word uses a underlined typeface. To Become more comfortable - Do Online Practice
16 | P a g e
This will produce following result: The following word uses a strikethrough typeface. To Become more comfortable - Do Online Practice
This will produce following result: The following word uses a monospaced typeface. To Become more comfortable - Do Online Practice
typeface.
17 | P a g e
subscript
This will produce following result: The following word uses a big typeface. To Become more comfortable - Do Online Practice
This will produce following result: The following word uses a small typeface. To Become more comfortable - Do Online Practice
<div id="menu" align="middle" > <a href="/index.htm">HOME</a> | <a href="/about/contact_us.htm">CONTACT</a> | <a href="/about/index.htm">ABOUT</a> </div>
18 | P a g e
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.
19 | P a g e
This will produce following result: You must remember to close elements in XHTML. To Become more comfortable - Do Online Practice
This will produce following result: I have a friend called Abhy. To Become more comfortable - Do Online Practice
This will produce following result: This chapter covers marking up text in XHTML.
20 | P a g e
This will produce following result: This tutorial teaches you how mark up your documents for the web using XHTML. To Become more comfortable - Do Online Practice
This will produce following result: 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
21 | P a g e
This will produce following result: Amit is in Spain, He is their at my home. I think I am wrong. The <q> element can also carry the cite attribute. The value should be a URL pointing to the source of the quote. To Become more comfortable - Do Online Practice
This will produce following result: This HTML Tutorial is derived from World Wide Web Standard for HTML. To Become more comfortable - Do Online Practice
22 | P a g e
<p><code>document.write("<var>user-name</var>")</code></p>
This will produce following result: document.write("user-name")
23 | P a g e
Block-level elements - Block-level elements appear on the screen as if they have a carriage return or line break before and after them. For example the <p>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <ul>, <ol>, <dl>, <pre>, <hr />, <blockquote>, and <address> elements are all block level elements. They all start on their own new line, and anything that follows them appears on its own new line. Inline elements - Inline elements, on the other hand, can appear within sentences and do not have to appear on a new line of their own. The <b>, <i>, <u>, <em>, <strong>, <sup>, <sub>, <big>, <small>, <li>, <ins>, <del>, <code>, <cite>, <dfn>, <kbd>, and <var> elements are all inline elements.
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. For example: Given line is a valid comment in HTML
<!--
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.
24 | P a g e
<!-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:
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.
25 | P a g e
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="2"
26 | P a g e
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 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:
face="Times New Roman" size="5">Times New Roman</font> face="Verdana" size="5">Verdana</font> face="Comic sans MS" size="5">Comic Sans MS</font> face="WildWest" size="5">WildWest</font>
27 | P a g e
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:
28 | P a g e
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>
This will produce following result:
some
darkgray
a
text
courier
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 Images
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.
29 | P a g e
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" />
30 | P a g e
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
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.
31 | P a g e
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.
32 | P a g e
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: Tutorials Point | AMROOD | Change Images
33 | P a g e
Now you have a place where you can reach. To reach to this place use the following code within this document anywhere: <a href="/html/html_text_links.htm#top">Go to the Top</a>
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.
34 | P a g e
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.
#!/usr/bin/perl # HTTP Header print "Content-Type:application/octet-stream; name=\"FileName\"\r\n"; print "Content-Disposition: attachment; filename=\"FileName\"\r\n\n"; # Actual File Content will go hear. open( FILE, "<FileName" ); while(read(FILE, $buffer, 100) ) { print("$buffer"); }
For more detail on CGI go through our another tutorial PERL and CGI.
<a href="http://www.tutorialspoint.com/index.htm" target="_self" > <img src="/images/home.gif" alt="Tutorials Point Home" border="0"/> </a>
This will create following hyperlink at tutorialspoint.com home.
35 | P a g e
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.
<a href="/cgi-bin/logo.map" target="_self" > <img ismap src="/images/html.gif" alt="HTML" border="0"/> </a>
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
To Become more comfortable - Do Online Practice 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.
36 | P a g e
<img src=/https/www.scribd.com/images/html.gif alt="HTML Map" border="0" usemap="#html"/> <!-- Create Mappings --> <map name="html"> <area shape="circle" coords="154,150,59" href="link1.htm" alt="link 1" target="_self" /> <area shape="poly" coords="272,79,351,79,351,15,486,15,486,218,272,218, 292,166,292,136,270,76" alt="link 2" href="link2.htm" target="_self" /> <area shape="rect" coords="325,224,488,286" alt="link 3" href="link3.htm" target="_self" /> </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; 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
37 | P a g e
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>
This will produce following result: Row 1, Column 1 Row 1, Column 2 Row 2, Column 1 Row 2, Column 2
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. To Become more comfortable - Do Online Practice
38 | P a g e
To Become more comfortable - Do Online Practice 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.
<table border="1" cellpadding="5" cellspacing="5"> <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:
Salary 5000
39 | P a g e
<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>
This will produce following result: Column 1 Column 2 Column 3
Row 1 Cell 1 Row 1 Cell 2 Row 1 Cell 3 Row 2 Cell 2 Row 2 Cell 3 Row 3 Cell 1
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>
40 | P a g e
Row 1 Cell 1 Row 1 Cell 2 Row 1 Cell 3 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>
This will produce following result: Column 1 Column 2 Column 3
Row 1 Cell 1 Row 1 Cell 2 Row 1 Cell 3 Row 2 Cell 2 Row 2 Cell 3 Row 3 Cell 1
41 | P a g e
This will produce following result: Row 1, Column 1 Row 2, Column 1 Row 1, Column 2 Row 2, Column 2
<table border="1"> <caption>This is the caption</caption> <tr> <td>row 1, column 1</td><td>row 1, columnn 2</td> </tr> </table>
This will produce following result: This is the caption row 1, column 1 row 1, columnn 2
<thead> - to create a separate table header. <tbody> - to indicate the main body of the table. <tfoot> - to create a separate table footer.
A table may contain several <tbody> elements to indicate different pages or groups of data. But it is notable that <thead> and <tfoot> tags should appear before <tbody>
42 | P a g e
...more rows here containing four cells... Cell 1 Cell 2 Cell 3 Cell 4
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>.
43 | P a g e
<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>
This will produce following result:
Name
Salary
Ramesh Raman 5000 Shabbir Hussein 7000 Row 2, Column 1 Row 2, Column 2
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:
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.
44 | P a g e
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.
45 | P a g e
46 | P a g e
47 | P a g e
48 | P a g e
HTML Forms
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>
Most frequently used form attributes are:
name: This is the name of the form. action: Here you will specify any script URL which will receive uploaded data. 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: o application/x-www-form-urlencoded - This is the standard method most forms use. It converts spaces to the plus sign and non-alphanumeric characters into the hexadecimal code for that character in ASCII text. o mutlipart/form-data - This allows the data to be sent in parts, with each consecutive part corresponding the a form control, in the order they appear in the form. Each part can have an optional content-type header of its own indicating the type of data for that form control.
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.
Text input controls Buttons Checkboxes and radio buttons Select boxes File select boxes Hidden controls Submit and reset button
49 | P a g e
<form action="/cgi-bin/hello_get.cgi" method="get"> First name: <input type="text" name="first_name" /> <br> Last name: <input type="text" name="last_name" /> <input type="submit" value="submit" /> </form>
This will produce following result:
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.
50 | P a g e
Login : Password :
submit
<form action="/cgi-bin/hello_get.cgi" method="get"> Description : <br /> <textarea rows="5" cols="50" name="description"> Enter description here... </textarea> <input type="submit" value="submit" /> </form>
This will produce following result: Description :
Enter description here...
submit
51 | P a g e
submit: This creates a button that automatically submits a form. reset: This creates a button that automatically resets form controls to their initial values. button: This creates a button that is used to trigger a client-side script when the user clicks that button.
<form action="http://www.example.com/test.asp" method="get"> <input type="submit" name="Submit" value="Submit" /> <br /><br /> <input type="reset" value="Reset" /> <input type="button" value="Button" /> </form>
This will produce following result:
Submit
Reset
<form action="http://www.example.com/test.asp" method="get"> <button type="submit">Submit</button> <br /><br /> <button type="reset"> Reset </button>
52 | P a g e
<form action="/cgi-bin/checkbox.cgi" method="get"> <input type="checkbox" name="maths" value="on"> Maths <input type="checkbox" name="physics" value="on"> Physics <input type="submit" value="Select Subject" /> </form>
The result of this code is the following form
Maths
Physics
Select Subject
type: Indicates that you want to create a checkbox. name: Name of the control. 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.
<form action="/cgi-bin/radiobutton.cgi" method="post"> <input type="radio" name="subject" value="maths" /> Maths <input type="radio" name="subject" value="physics" /> Physics
53 | P a g e
Maths
Physics
Submit
type: Indicates that you want to create a radiobox. name: Name of the control. 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.
<form action="/cgi-bin/dropdown.cgi" method="post"> <select name="dropdown"> <option value="Maths" selected>Maths</option> <option value="Physics">Physics</option> </select> <input type="submit" value="Submit" /> </form>
The result of this code is the following form
Maths
Submit
name: This is the name for the control. size: This can be used to present a scrolling list box. 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.
54 | P a g e
<form action="/cgi-bin/hello_get.cgi" method="post" name="fileupload" enctype="multipart/form-data"> <input type="file" name="fileupload" accept="image/*" /> </form>
The result of this code is the following form
<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 will produce following result: This is page 10
Next Page
<form action="/cgi-bin/hello_get.cgi" method="get"> First name: <input type="text" name="first_name" /> <br> Last name: <input type="text" name="last_name" /> <input type="submit" value="Submit" /> <input type="reset" value="Reset" /> </form>
This will produce following result. Type something and click reset button.
Learn JSP Learn Servlets Learn log4j Learn iBATIS Learn Java Learn JDBC Java Examples Learn Best Practices Learn Python Learn Ruby Learn Ruby on Rails Learn SQL Learn MySQL Learn AJAX Learn C Programming Learn C++ Programming Learn CGI with PERL Learn DLL
Learn ASP.Net Learn HTML Learn HTML5 Learn XHTML Learn CSS Learn HTTP Learn JavaScript Learn jQuery Learn Prototype Learn script.aculo.us Web Developer's Guide Learn RADIUS Learn RSS Learn SEO Techniques Learn SOAP Learn UDDI Learn Unix Sockets Learn Web Services
56 | P a g e
Learn ebXML Learn Euphoria Learn GDB Debugger Learn Makefile Learn Parrot Learn Perl Script Learn PHP Script Learn Six Sigma Learn SEI CMMI Learn WiMAX Learn Telecom Billing
Learn XML-RPC Learn UML Learn UNIX Learn WSDL Learn i-Mode Learn GPRS Learn GSM Learn WAP Learn WML Learn Wi-Fi
57 | P a g e