Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

HTML Material

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

HTML material prepared by Ramesh Mudragada.

Contact: 9701797513 HTML is the abbreviation for Hyper Text Mark-up Language and is the language we use to create web pages. The HTML marks up a web page to indicate its format, telling the web browser where we want a new line, how we want a text or image to be aligned and so on. In other words, HTML is all about specifying the structure and format of your web page. HTML Tags and Elements: In HTML, all the terms will be enclosed in angular brackets <.> and such terms are called as tags. Most of the HTML tags come in pairs as opening tag and closing tag. The opening tag is the actual term enclosed in angular brackets and the closing tag is the /term enclosed in angular brackets. <HTML> </HTML> Collectively, a starting tag, an ending tag, and everything between them make up and HTML element. Tag Attributes: Tags can have attributes. Attributes can provide additional information about the HTML elements on your page. This tag defines the body element of your HTML page: <body>. With an added bgcolor attribute, you can tell the browser that the background color of your page should be red, like this: <body bgcolor="red">. This tag defines an HTML table: <table>. With an added border attribute, you can tell the browser that the table should have no borders: <table border="0"> Attributes always come in name/value pairs like this: name="value". Attributes are always added to the start tag of an HTML element <HTML>.</HTML>: Every HTML page should lie between theses tags. This contains two parts, as: 1. Head part 2. Body part The head part can be used to configure the title bar, tool bar and other base properties of the browser. Comments in HTML: The comment tag is used to insert a comment in the HTML source code. A comment will be ignored by the browser. You can use comments to explain your code, which can help you when you edit the source code at a later date. <!-- This is a comment --> Note that you need an exclamation point after the opening bracket, but not before the closing bracket. <HEAD>.</HEAD>: This is the first part of the HTML page. This contains the browser configuration settings.

-1-

HTML material prepared by Ramesh Mudragada. Contact: 9701797513

<TITLE>.</TITLE>: This comes inside the HEAD tags and can be used to configure the title on the title bar. <BODY>.</BODY>: This is the second part of a HTML page. These tags contains the contents along with the style of presentation on the HTML page. This BODY tag can take three attributes, namely: BGCOLOR, ONLOAD and ONUNLOAD. The attribute BGCOLOR changes the background color of the browser. The attribute ONLOAD displays the given message on the activation of the page. The attribute ONUNLOAD displays the goodbye message on unloading the page. <BODY BGCOLOR=red ONLOAD=alert (Welcome) ONUNLOAD=alert (Goodbye)> . . </BODY> Heading tags: HTML supports headings in six sizes as H1 to H6, H1 being the biggest and the H6 the smallest. These tags displays the enclosed text in the corresponding heading format. By default, the heading tags forces a paragraph break before and after the enclosed text and displays the text in bold. Emphasizing the Text: To emphasize some portions of the text, we can use the following tags: 1. <B> & </B> or <strong> & </strong> to display the enclosed text in bold. 2. <big> & </big> to display the enclosed text in bigger size. 3. <small> & </small> to display the enclosed text in smaller size. 4. <I> & </I> or <em> & </em> to display the enclosed text in italics. 5. <U> & </U> or <ins> & </ins> to display the enclosed text with underline. 6. <del> & </del> to display the text that was strike out. 7. <sup> & </sup> to display the enclosed text as superscript. 8. <sub> & </sub> to display the enclosed text as subscript.

These tags can be used in combination with one another. <html> <body> <b>This text is bold</b> <br> <strong>This text is strong</strong> <br> <big>This text is big</big> <br> <em>This text is emphasized</em> <br>

-2-

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 <i>This text is italic</i> <br> <small>This text is small</small> <br> This text contains<sub>subscript</sub> <br> This text contains<sup>superscript</sup> </body> </html> The Paragraph tags: The <P> and </P> tags are the paragraph tags and these tags forces a paragraph break before and after the enclosed paragraph. These tags takes two attributes, namely: id and align, the id being used to address it and the align takes three parameters as left, right and center. <p id=para1 align=center></p> Forcing a line break: To force a line break we can use the <br> tag. This has no closing tag and this forces a line break and continues the rest of the presentation on the next line. Quote and Blockquote tags: The <q> and </q> tags allow for short snippets of quoted text to be inserted into regular text content. Whereas the <blockquote> & </blockquote> can be used to insert longer quotation in to the body text. Generally the blockquote tag automatically forces a paragraph break and indents the text from the left margin. <html> <body> Here comes a long quotation: <blockquote> This is a long quotation. This is a long quotation. This is a long quotation. This is a long quotation. This is a long quotation. </blockquote> Here comes a short quotation: <q> This is a short quotation </q> <p> With the block quote element, the browser inserts line breaks and margins, but the q element does not render as anything special. </p> </body> </html>

-3-

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 Preformatted text: <pre> and </pre> takes the preformatted text and the enclosed text preserves both the spaces and linebreaks. <html> <body> <pre> This is preformatted text. It preserves both spaces and line breaks. </pre> <p>The pre tag is good for displaying computer code:</p> <pre> for i = 1 to 10 print i next i </pre> </body> </html> Using the Font tag: The <font> and </font> tags enables us to change the font and style of the enclosed text. It does the changes using three attributes, namely: face, size and color. The FACE attribute changes the font to your choicest font. The SIZE attribute changes the size of the text from +5 to -5, 0 being the default setting. The COLOR attribute changes the display color of the enclosed text. The Anchor Tag and the Href Attribute: HTML uses the <a> (anchor) tag to create a link to another document. An anchor can point to any resource on the Web: an HTML page, an image, a sound file, a movie, etc. The syntax of creating an anchor: <a href="url">Text to be displayed</a> The <a> tag is used to create an anchor to link from, the href attribute is used to address the document to link to, and the words between the open and close of the anchor tag will be displayed as a hyperlink. This anchor defines a link to Yahoo: <a href="http://www.yahoo.com>Visit Yahoo!</a> The Target Attribute With the target attribute, you can define where the linked document will be opened. The line below will open the document in a new browser window: <a href=http://www.yahoo.com/ target="_blank">Visit Yahoo!</a>

-4-

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 The following program connects an external page: <html> <body> <a href="page1.html" target="_blank"> Page1</a> <p> If you set the target attribute of a link to "_blank", the link will open in a new window. </p> </body> </html> The following program creats a link on the same page: <html> <body> <p> <a href="#C4">See also Chapter 4.</a> </p> <h2>Chapter 1</h2> <p>This chapter explains ba bla bla</p> <h2>Chapter 2</h2> <p>This chapter explains ba bla bla</p> <h2>Chapter 3</h2> <p>This chapter explains ba bla bla</p> <h2><a name="C4">Chapter 4</a></h2> <p>This chapter explains ba bla bla</p> <h2>Chapter 5</h2> <p>This chapter explains ba bla bla</p> <h2>Chapter 6</h2> <p>This chapter explains ba bla bla</p> <h2>Chapter 7</h2> <p>This chapter explains ba bla bla</p> <h2>Chapter 8</h2> <p>This chapter explains ba bla bla</p> <h2>Chapter 9</h2> <p>This chapter explains ba bla bla</p> <h2>Chapter 10</h2> <p>This chapter explains ba bla bla</p> <h2>Chapter 11</h2> <p>This chapter explains ba bla bla</p> <h2>Chapter 12</h2> <p>This chapter explains ba bla bla</p> <h2>Chapter 13</h2> <p>This chapter explains ba bla bla</p> <h2>Chapter 14</h2> </body> </html> Creating Lists:

-5-

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 Lists are of three types: Unordered lists, Ordered lists and Definition lists. Unordered lists: An unordered list is a list of items. The list items are marked with bullets (typically small black circles).An unordered list starts with the <ul> tag. Each list item starts with the <li> tag. <ul> <li>Coffee</li> <li>Milk</li> </ul> Here is how it looks in a browser: Coffee Milk Inside a list item you can put paragraphs, line breaks, images, links, other lists, etc. Ordered Lists: An ordered list is also a list of items. The list items are marked with numbers. An ordered list starts with the <ol> tag. Each list item starts with the <li> tag. <ol> <li>Coffee</li> <li>Milk</li> </ol> Here is how it looks in a browser: 1. Coffee 2. Milk Inside a list item you can put paragraphs, line breaks, images, links, other lists, etc. Definition Lists: A definition list is not a list of items. This is a list of terms and explanation of the terms. A definition list starts with the <dl> tag. Each definition-list term starts with the <dt> tag. Each definition-list definition starts with the <dd> tag. Inside a definition-list definition (the <dd> tag) you can put paragraphs, line breaks, images, links, other lists, etc. <html> <body> <h4>An Unordered List:</h4> <ul> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ul> <h4>An Ordered List:</h4> <ol> <li>Coffee</li>

-6-

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 <li>Tea</li> <li>Milk</li> </ol> <h4>Numbered list:</h4> <ol> <li>Apples</li> <li>Bananas</li> <li>Lemons</li> <li>Oranges</li> </ol> <h4>Letters list:</h4> <ol type="A"> <li>Apples</li> <li>Bananas</li> <li>Lemons</li> <li>Oranges</li> </ol> <h4>Lowercase letters list:</h4> <ol type="a"> <li>Apples</li> <li>Bananas</li> <li>Lemons</li> <li>Oranges</li> </ol> <h4>Roman numbers list:</h4> <ol type="I"> <li>Apples</li> <li>Bananas</li> <li>Lemons</li> <li>Oranges</li> </ol> <h4>Lowercase Roman numbers list:</h4> <ol type="i"> <li>Apples</li> <li>Bananas</li> <li>Lemons</li> <li>Oranges</li> </ol> <h4>Disc bullets list:</h4> <ul type="disc"> <li>Apples</li> <li>Bananas</li> <li>Lemons</li> <li>Oranges</li>

-7-

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 </ul> <h4>Circle bullets list:</h4> <ul type="circle"> <li>Apples</li> <li>Bananas</li> <li>Lemons</li> <li>Oranges</li> </ul> <h4>Square bullets list:</h4> <ul type="square"> <li>Apples</li> <li>Bananas</li> <li>Lemons</li> <li>Oranges</li> </ul> <h4>A Definition List:</h4> <dl> <dt>Coffee</dt> <dd>Black hot drink</dd> <dt>Milk</dt> <dd>White cold drink</dd> </dl> <h4>A nested List:</h4> <ul> <li>Coffee</li> <li>Tea <ul> <li>Black tea</li> <li>Green tea</li> </ul> </li> <li>Milk</li> </ul> </body> </html>

-8-

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 The Image Tag and the Src Attribute: In HTML, images are defined with the <img> tag. The <img> tag is empty, which means that it contains attributes only and it has no closing tag. To display an image on a page, you need to use the src attribute. Src stands for "source". The value of the src attribute is the URL of the image you want to display on your page. The syntax of defining an image: <img src="url"> The URL points to the location where the image is stored. An image named "boat.gif" located in the directory "images" on "www.flexisoft.net" has the URL: http://www. flexisoft.net /images/boat.gif. The browser puts the image where the image tag occurs in the document. If you put an image tag between two paragraphs, the browser shows the first paragraph, then the image, and then the second paragraph. The Alt Attribute The alt attribute is used to define an "alternate text" for an image. The value of the alt attribute is an author-defined text: <img src="boat.gif" alt="Big Boat"> The "alt" attribute tells the reader what he or she is missing on a page if the browser can't load images. The browser will then display the alternate text instead of the image. It is a good practice to include the "alt" attribute for each image on a page, to improve the display and usefulness of your document for people who have text-only browsers. <html> <body> <p> An image: <img src="constr4.gif" width="144" height="50"> </p> <p> An animated image: <img src="hackanm.gif" width="48" height="48"> </p> <p> Note that the syntax of inserting an animated image is no different from that of a nonmoving image. </p> </body> </html> Plading an image from external source: <html> <body>

-9-

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 <p> An image from another folder: <img src="/images/netscape.gif" width="33" height="32"> </p> <p> An image from website: <img src="http://www.flexisoft.net/images/ie.gif" width="73" height="68"> </p> </body> </html> Using image as background: <html> <body background="background.jpg"> <h3>Look: A background image!</h3> <p>Both gif and jpg files can be used as HTML backgrounds.</p> <p>If the image is smaller than the page, the image will repeat itself.</p> </body> </html> Aligining the images: <html> <body> <p> An image <img src="hackanm.gif" align="bottom" width="48" height="48"> in the text </p> <p> An image <img src ="hackanm.gif" align="middle" width="48" height="48"> in the text </p> <p> An image <img src ="hackanm.gif" align="top" width="48" height="48"> in the text </p> <p>Note that bottom alignment is the default alignment</p> <p> An image <img src ="hackanm.gif" width="48" height="48"> in the text </p> <p> <img src ="hackanm.gif" width="48" height="48"> An image before the text </p> <p> An image after the text <img src ="hackanm.gif" width="48" height="48"> </p> </body> </html>

- 10 -

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 Placing a text around the image: <html> <body> <p> <img src ="hackanm.gif" align ="left" width="48" height="48"> A paragraph with an image. The align attribute of the image is set to "left". The image will float to the left of this text. </p> <p> <img src ="hackanm.gif" align ="right" width="48" height="48"> A paragraph with an image. The align attribute of the image is set to "right". The image will float to the right of this text. </p> </body> </html> Using an image as hyperlink: <html> <body> <p> You can also use an image as a link: <a href="lastpage.htm"> <img border="0" src="buttonnext.gif" width="65" height="38"> </a> </p> </body> </html> Tables: Tables are defined with the <table> tag. A table is divided into rows (with the <tr> tag), and each row is divided into data cells (with the <td> tag). The letters td stands for "table data," which is the content of a data cell. A data cell can contain text, images, lists, paragraphs, forms, horizontal rules, tables, etc. <table border="1"> <tr> <td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr> <tr> <td>row 2, cell 1</td> <td>row 2, cell 2</td> </tr> </table> Tables and the Border Attribute If you do not specify a border attribute the table will be displayed without any borders. Sometimes this can be useful, but most of the time, you want the borders to show. To display a table with borders, you will have to use the border attribute <table border="1"> <tr> <td>Row 1, cell 1</td>

- 11 -

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 <td>Row 1, cell 2</td> </tr> </table> Headings in a Table Headings in a table are defined with the <th> tag. <table border="1"> <tr> <th>Heading</th> <th>Another Heading</th> </tr> <tr> <td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr> <tr> <td>row 2, cell 1</td> <td>row 2, cell 2</td> </tr> </table> Example: <html> <body> <p> Each table starts with a table tag. Each table row starts with a tr tag. Each table data starts with a td tag. </p> <h4>One column:</h4> <table border="1"> <tr> <td>100</td> </tr> </table> <h4>One row and three columns:</h4> <table border="1"> <tr> <td>100</td> <td>200</td> <td>300</td> </tr> </table> <h4>Two rows and three columns:</h4> <table border="1"> <tr> <td>100</td> <td>200</td> <td>300</td> </tr>

- 12 -

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 <tr> <td>400</td> <td>500</td> <td>600</td> </tr> </table> </body> </html> Table with Borders: <html> <body> <h4>With a normal border:</h4> <table border="1"> <tr> <td>First</td> <td>Row</td> </tr> <tr> <td>Second</td> <td>Row</td> </tr> </table> <h4>With a thick border:</h4> <table border="8"> <tr> <td>First</td> <td>Row</td> </tr> <tr> <td>Second</td> <td>Row</td> </tr> </table> <h4>With a very thick border:</h4> <table border="15"> <tr> <td>First</td> <td>Row</td> </tr> <tr> <td>Second</td> <td>Row</td> </tr> </table> </body> </html> Table with no borders:

- 13 -

HTML material prepared by Ramesh Mudragada. Contact: 9701797513

<html> <body> <h4>This table has no borders:</h4> <table> <tr> <td>100</td> <td>200</td> <td>300</td> </tr> <tr> <td>400</td> <td>500</td> <td>600</td> </tr> </table> <h4>And this table has no borders:</h4> <table border="0"> <tr> <td>100</td> <td>200</td> <td>300</td> </tr> <tr> <td>400</td> <td>500</td> <td>600</td> </tr> </table> </body> </html> Tables with headings: <html> <body> <h4>Table headers:</h4> <table border="1"> <tr> <th>Name</th> <th>Telephone</th> <th>Telephone</th> </tr> <tr> <td>Bill Gates</td> <td>555 77 854</td> <td>555 77 855</td> </tr> </table> <h4>Vertical headers:</h4> <table border="1">

- 14 -

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 <tr> <th>First Name:</th> <td>Bill Gates</td> </tr> <tr> <th>Telephone:</th> <td>555 77 854</td> </tr> <tr> <th>Telephone:</th> <td>555 77 855</td> </tr> </table> </body> </html> Tables with Caption: <html> <body> <h4> This table has a caption, and a thick border: </h4> <table border="6"> <caption>My Caption</caption> <tr> <td>100</td> <td>200</td> <td>300</td> </tr> <tr> <td>400</td> <td>500</td> <td>600</td> </tr> </table> </body> </html> Table with row and column spanning: <html> <body> <h4>Cell that spans two columns:</h4> <table border="1"> <tr> <th>Name</th> <th colspan="2">Telephone</th> </tr> <tr> <td>Bill Gates</td>

- 15 -

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 <td>555 77 854</td> <td>555 77 855</td> </tr> </table> <h4>Cell that spans two rows:</h4> <table border="1"> <tr> <th>First Name:</th> <td>Bill Gates</td> </tr> <tr> <th rowspan="2">Telephone:</th> <td>555 77 854</td> </tr> <tr> <td>555 77 855</td> </tr> </table> </body> </html> Cell padding: <html> <body> <h4>Without cellpadding:</h4> <table border="1"> <tr> <td>First</td> <td>Row</td> </tr> <tr> <td>Second</td> <td>Row</td> </tr> </table> <h4>With cellpadding:</h4> <table border="1" cellpadding="10"> <tr> <td>First</td> <td>Row</td> </tr> <tr> <td>Second</td> <td>Row</td> </tr> </table> </body> </html>

- 16 -

HTML material prepared by Ramesh Mudragada. Contact: 9701797513

Cell spacing: <html> <body> <h4>Without cellspacing:</h4> <table border="1"> <tr> <td>First</td> <td>Row</td> </tr> <tr> <td>Second</td> <td>Row</td> </tr> </table> <h4>With cellspacing:</h4> <table border="1" cellspacing="10"> <tr> <td>First</td> <td>Row</td> </tr> <tr> <td>Second</td> <td>Row</td> </tr> </table> </body> </html>

Adding an image to table: <html> <body> <h4>A background color:</h4> <table border="1" bgcolor="red"> <tr> <td>First</td> <td>Row</td> </tr> <tr> <td>Second</td> <td>Row</td> </tr> </table> <h4>A background image:</h4> <table border="1" background="bgdesert.jpg">

- 17 -

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 <tr> <td>First</td> <td>Row</td> </tr> <tr> <td>Second</td> <td>Row</td> </tr> </table> </body> </html> Adding an image to a cell: <html> <body> <h4>Cell backgrounds:</h4> <table border="1"> <tr> <td bgcolor="red">First</td> <td>Row</td> </tr> <tr> <td background="bgdesert.jpg"> Second</td> <td>Row</td> </tr> </table> </body> </html>

- 18 -

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 Frames With frames, you can display more than one HTML document in the same browser window. Each HTML document is called a frame, and each frame is independent of the others. The disadvantages of using frames are: The web developer must keep track of more HTML documents It is difficult to print the entire page The Frameset Tag The <frameset> tag defines how to divide the window into frames. Each frameset defines a set of rows or columns. The values of the rows/columns indicate the amount of screen area each row/column will occupy. The Frame Tag The <frame> tag defines what HTML document to put into each frame. In the example below we have a frameset with two columns. The first column is set to 25% of the width of the browser window. The second column is set to 75% of the width of the browser window. The HTML document "frame_a.htm" is put into the first column, and the HTML document "frame_b.htm" is put into the second column: <frameset cols="25%,75%"> <frame src="frame_a.htm"> <frame src="frame_b.htm"> </frameset> If a frame has visible borders, the user can resize it by dragging the border. To prevent a user from doing this, you can add noresize="noresize" to the <frame> tag. Add the <noframes> tag for browsers that do not support frames. Vertical frameset This example demonstrates how to make a vertical frameset with three different documents. <html> <frameset cols="25%,50%,25%"> <frame src="frame_a.htm"> <frame src="frame_b.htm"> <frame src="frame_c.htm"> </frameset> </html> Horizontal frameset This example demonstrates how to make a horizontal frameset with three different documents. <html> <frameset rows="25%,50%,25%"> <frame src="frame_a.htm"> <frame src="frame_b.htm"> <frame src="frame_c.htm"> </frameset> </html>

- 19 -

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 How to use the <noframes> tag This example demonstrates how to use the <noframes> tag. <html> <frameset cols="25%,50%,25%"> <frame src="frame_a.htm"> <frame src="frame_b.htm"> <frame src="frame_c.htm"> <noframes> <body>Your browser does not handle frames!</body> </noframes> </frameset> </html> Mixed frameset This example demonstrates how to make a frameset with three documents, and how to mix them in rows and columns. <html> <frameset rows="50%,50%"> <frame src="frame_a.htm"> <frameset cols="25%,75%"> <frame src="frame_b.htm"> <frame src="frame_c.htm"> </frameset> </frameset> </html> Frameset with noresize="noresize" This example demonstrates the noresize attribute. The frames are not resizable. Move the mouse over the borders between the frames and notice that you can not move the borders. <html> <frameset rows="50%,50%"> <frame noresize="noresize" src="frame_a.htm"> <frameset cols="25%,75%"> <frame noresize="noresize" src="frame_b.htm"> <frame noresize="noresize" src="frame_c.htm"> </frameset> </frameset> </html> Navigation frame This example demonstrates how to make a navigation frame. The navigation frame contains a list of links with the second frame as the target. The file called "tryhtml_contents.htm" contains three links. The source code of the links: <a href ="frame_a.htm" target ="showframe">Frame a</a><br> <a href ="frame_b.htm" target ="showframe">Frame b</a><br>

- 20 -

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 <a href ="frame_c.htm" target ="showframe">Frame c</a> The second frame will show the linked document. <html> <frameset cols="120,*"> <frame src="tryhtml_contents.htm"> <frame src="frame_a.htm" name="showframe"> </frameset> </html> Inline frame This example demonstrates how to create an inline frame (a frame inside an HTML page). <html> <body> <iframe src="default.asp"></iframe> <p>Some older browsers don't support iframes.</p> <p>If they don't, the iframe will not be visible.</p> </body> </html> Jump to a specified section within a frame This example demonstrates two frames. One of the frames has a source to a specified section in a file. The specified section is made with <a name="C10"> in the "link.htm" file. <html> <frameset cols="20%,80%"> <frame src="frame_a.htm"> <frame src="link.htm#C10"> </frameset> </html> Jump to a specified section with frame navigation This example demonstrates two frames. The navigation frame (content.htm) to the left contains a list of links with the second frame (link.htm) as a target. The second frame shows the linked document. One of the links in the navigation frame is linked to a specified section in the target file. The HTML code in the file "content.htm" looks like this: <a href ="link.htm" target ="showframe">Link without Anchor</a><br><a href ="link.htm#C10" target ="showframe">Link with Anchor</a>. <html> <frameset cols="180,*"> <frame src="content.htm"> <frame src="link.htm" name="showframe"> </frameset> </html>

- 21 -

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 Forms A form is an area that can contain form elements. Form elements are elements that allow the user to enter information (like text fields, textarea fields, drop-down menus, radio buttons, checkboxes, etc.) in a form. A form is defined with the <form> tag. <form> <input> <input> </form> Input The most used form tag is the <input> tag. The type of input is specified with the type attribute. The most commonly used input types are explained below. Text Fields Text fields are used when you want the user to type letters, numbers, etc. in a form. <form> First name: <input type="text" name="firstname"> <br> Last name: <input type="text" name="lastname"> </form> Radio Buttons Radio Buttons are used when you want the user to select one of a limited number of choices. <form> <input type="radio" name="sex" value="male"> Male <br> <input type="radio" name="sex" value="female"> Female </form> Checkboxes Checkboxes are used when you want the user to select one or more options of a limited number of choices. <form> <input type="checkbox" name="bike"> I have a bike <br> <input type="checkbox" name="car"> I have a car </form> The Form's Action Attribute and the Submit Button When the user clicks on the "Submit" button, the content of the form is sent to another file. The form's action attribute defines the name of the file to send the content to. The file defined in the action attribute usually does something with the received input. <form name="input" action="html_form_action.asp" method="get"> Username: <input type="text" name="user"> <input type="submit" value="Submit"> </form>

- 22 -

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 Text fields: This example demonstrates how to create text fields on an HTML page. A user can write text in a text field. <html> <body> <form> First name: <input type="text" name="firstname"> <br> Last name: <input type="text" name="lastname"> </form> </body> </html> Password fields: This example demonstrates how to create a password field on an HTML page. <html> <body> <form> Username: <input type="text" name="user"> <br> Password: <input type="password" name="password"> </form> <p> Note that when you type characters in a password field, the browser displays asterisks or bullets instead of the characters. </p> </body> </html> Checkboxes: This example demonstrates how to create check-boxes on an HTML page. A user can select or unselect a checkbox. <html> <body> <form> I have a bike: <input type="checkbox" name="Bike"> <br> I have a car: <input type="checkbox" name="Car"> </form> </body> </html>

- 23 -

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 Radio buttons: This example demonstrates how to create radio-buttons on an HTML page. <html> <body> <form> Male: <input type="radio" checked="checked" name="Sex" value="male"> <br> Female: <input type="radio" name="Sex" value="female"> </form> <p> When a user clicks on a radio-button, the button becomes checked, and all other buttons with the same name become unchecked </p> </body> </html> Simple drop down box: This example demonstrates how to create a simple dropdown box on an HTML page. A drop-down box is a selectable list. <html> <body> <form> <select name="cars"> <option value="volvo">Volvo <option value="saab">Saab <option value="fiat">Fiat <option value="audi">Audi </select> </form> </body> </html> Another drop down box: This example demonstrates how to create a simple dropdown box with a pre-selected value. <html> <body> <form> <select name="cars"> <option value="volvo">Volvo <option value="saab">Saab <option value="fiat" selected="selected">Fiat

- 24 -

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 <option value="audi">Audi </select> </form> </body> </html> Text area: This example demonstrates how to create a text-area (a multi-line text input control). A user can write text in the text-area. In a text-area you can write an unlimited number of characters. <html> <body> <p> This example cannot be edited because our editor uses a textarea for input, and your browser does not allow a textarea inside a textarea. </p> <textarea rows="10" cols="30"> The cat was playing in the garden. </textarea> </body> </html> Create a button: This example demonstrates how to create a button. On the button you can define your own text. <html> <body> <form> <input type="button" value="Hello world!"> </form> </body> </html> Fieldset around data: This example demonstrates how to draw a border with a caption around your data. <html> <body> <fieldset> <legend> Health information: </legend> <form> Height <input type="text" size="3">

- 25 -

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 Weight <input type="text" size="3"> </form> </fieldset> <p> If there is no border around the input form, your browser is too old. </p> </body> </html> Form with input fields and a submit button: This example demonstrates how to add a form to a page. The form contains two input fields and a submit button. <html> <body> <form name="input" action="html_form_action.asp" method="get"> Type your first name: <input type="text" name="FirstName" value="Mickey" size="20"> <br>Type your last name: <input type="text" name="LastName" value="Mouse" size="20"> <br> <input type="submit" value="Submit"> </form> <p> If you click the "Submit" button, you will send your input to a new page called html_form_action.asp. </p> </body> </html> Form with checkboxes: This form contains two checkboxes, and a submit button. <html> <body> <form name="input" action="html_form_action.asp" method="get"> I have a bike: <input type="checkbox" name="Bike" checked="checked"><br> I have a car: <input type="checkbox" name="Car"> <br> <input type="submit" value="Submit"> </form> <p>

- 26 -

HTML material prepared by Ramesh Mudragada. Contact: 9701797513 If you click the "Submit" button, you send your input to a new page called html_form_action.asp. </p> </body> </html> Form with radiobuttons: This form contains two radio buttons, and a submit button. <html> <body> <form name="input" action="html_form_action.asp" method="get"> Male: <input type="radio" name="Sex" value="Male" checked="checked"> <br> Female: <input type="radio" name="Sex" value="Female"> <br> <input type ="submit" value ="Submit"> </form> <p> If you click the "Submit" button, you will send your input to a new page called html_form_action.asp. </p> </body> </html> Send e-mail from a form: This example demonstrates how to send e-mail from a form. <html> <body> <form action="MAILTO:someone@yahoo.com" method="post" enctype="text/plain"> <h3>This form sends an e-mail to yahoo.com.</h3> Name:<br> <input type="text" name="name" value="yourname" size="20"> <br> Mail:<br> <input type="text" name="mail" value="yourmail" size="20"> <br> Comment:<br> <input type="text" name="comment" value="yourcomment" size="40"> <br><br> <input type="submit" value="Send"> <input type="reset" value="Reset"> </form> </body> </html>

- 27 -

You might also like