Professional Documents
Culture Documents
Elements of HTML: HTML Tags, Working with Text, Working with Lists, Tables and
Frames, Working with Hyperlinks, Images and Multimedia, Working with Forms and
controls
HTML tags are like keywords which defines that how web browser will format and display the
content. With the help of tags, a web browser can distinguish between an HTML content and a
simple content. HTML tags contain three main parts: opening tag, content and closing tag. But
some HTML tags are unclosed tags.
When a web browser reads an HTML document, browser reads it from top to bottom and left to
right. HTML tags are used to create HTML documents and render their properties. Each HTML
tags have different properties.
An HTML file must have some essential tags so that web browser can differentiate between a
simple text and HTML text. You can use as many tags you want as per your code requirement.
o All HTML tags must enclosed within < > these brackets.
o If you have used an open tag <tag>, then you must use a close tag </tag> (except some
tags)
Syntax
HTML contains several elements for defining text with a special meaning.
Example
Example
The HTML <strong> element defines text with strong importance. The content inside is typically
displayed in bold.
Example
The HTML <i> element defines a part of text in an alternate voice or mood. The content inside is
typically displayed in italic.
Tip: The <i> tag is often used to indicate a technical term, a phrase from another language, a
thought, a ship name, etc.
The HTML <em> element defines emphasized text. The content inside is typically displayed in
italic.
Tip: A screen reader will pronounce the words in <em> with an emphasis, using verbal stress.
Example
Example
Example
The HTML <del> element defines text that has been deleted from a document. Browsers will
usually strike a line through deleted text:
Example
The HTML <ins> element defines a text that has been inserted into a document. Browsers will
usually underline inserted text:
Example
Example
<p>This is <sub>subscripted</sub> text.</p>
The HTML <sup> element defines superscript text. Superscript text appears half a character
above the normal line, and is sometimes rendered in a smaller font. Superscript text can be used
for footnotes, like WWW[1]:
Example
<p>This is <sup>superscripted</sup> text.</p>
HTML Exercises
Tag Description
Lists are a part of everyday life. To-do lists determine what to get done. Navigational routes
provide turn-by-turn lists of directions. Recipes provide lists of ingredients and lists of
instructions. With a list for nearly everything, it’s easy to understand why they are also popular
online.
When we want to use a list on a website, HTML provides three different types to choose from:
unordered, ordered, and description lists. Choosing which type of list to use—or whether to use a
list at all—comes down to the content and the most semantically appropriate option for
displaying that content.
In addition to the three different types of lists available within HTML, there are multiple ways to
style these lists with CSS. For example, we can choose what type of marker to use on a list. The
marker could be square, round, numeric, alphabetical, or perhaps nonexistent. Also, we can
decide if a list should be displayed vertically or horizontally. All of these choices play significant
roles in the styling of our web pages.
Unordered Lists
An unordered list is simply a list of related items whose order does not matter. Creating an
unordered list in HTML is accomplished using the unordered list block-level element, <ul>.
Each item within an unordered list is individually marked up using the list item element, <li>.
E.g
<ul>
<li>Orange</li>
<li>Green</li>
<li>Blue</li>
</ul>
Orange
Green
Blue
Ordered Lists
The ordered list element, <ol>, works very much like the unordered list element; individual list
items are created in the same manner. The main difference between an ordered list and an
unordered list is that with an ordered list, the order in which items are presented is important.
Because the order matters, instead of using a dot as the default list item marker, an ordered list
uses numbers.
<ol>
<li>Orange</li>
<li>Green</li>
<li>Blue</li>
</ol>
1. Blue
2. Green
3. Orange
Start Attribute
The start attribute defines the number from which an ordered list should start. By default,
ordered lists start at 1. However, there may be cases where a list should start at 30 or another
number. When we use the start attribute on the <ol> element, we can identify exactly which
number an ordered list should begin counting from.
The start attribute accepts only integer values, even though ordered lists may use different
numbering systems, such as roman numerals.
<ol start="30">
<li>Orange</li>
<li>Green</li>
<li>Blue</li>
</ol>
30. Blue
31. Green
32. Orange
Reversed Attribute
The reversed attribute is a Boolean attribute, and as such it doesn’t accept any value. It is either
true or false. False is the default value; the value becomes true when the attribute
name reversed appears on the <ol> element.
<ol reversed>
<li>Orange</li>
<li>Green</li>
<li>Blue</li>
</ol>
3. Blue
2. Green
1. Orange
Value Attribute
As an example, if the second list item has a value attribute value of 9, the number on that list
item marker will appear as if it is the ninth item. All subsequent list items will be numbered
upwards from 9.
<ol>
<li>Orange</li>
<li>value="9"Green</li>
<li>Blue</li>
</ol>
1. Blue
9. Green
10. Orange
Description Lists
Another type of list seen online (but not as often as unordered or ordered lists) is the description
list. Description lists are used to outline multiple terms and their descriptions, as in a glossary,
for example.
Creating a description list in HTML is accomplished using the description list block-level
element, <dl>. Instead of using a <li> element to mark up list items, the description list requires
two block-level elements: the description term element, <dt>, and the description element, <dd>.
A description list may contain numerous terms and descriptions, one after the other.
Additionally, a description list may have multiple terms per description, as well as multiple
descriptions per term. A single term may have multiple meanings and warrant multiple
descriptions. Conversely, a single description may be suitable for multiple terms.
When adding a description list, the <dt> element must come before the <dd> element. The
definition term and the description that directly follows it correspond to one another; thus, the
order of these elements is important.
<dl>
<dt>study</dt>
<dd>The devotion of time and attention to acquiring knowledge on an academic subject,
especially by means of books</dd>
<dt>design</dt>
<dd>A plan or drawing produced to show the look and function or workings of a building,
garment, or other object before it is built or made</dd>
<dd>Purpose, planning, or intention that exists or is thought to exist behind an action, fact, or
material object</dd>
<dt>business</dt>
<dt>work</dt>
<dd>A person's regular occupation, profession, or trade</dd>
</dl>
Study
The devotion of time and attention to acquiring knowledge on an academic subject, especially by
means of books
Design
A plan or drawing produced to show the look and function or workings of a building, garment, or
other object before it is built or made
Purpose, planning, or intention that exists or is thought to exist behind an action, fact, or material
object
Business
Work
Nesting Lists
One feature that makes lists extremely powerful is their ability to be nested. Every list may be
placed within another list; they can be nested continually. But the potential to nest lists
indefinitely doesn’t provide free rein to do so. Lists should still be reserved specifically for
where they hold the most semantic value.
One trick with nesting lists is to know where to begin and end each list and list item. Speaking
specifically about unordered and ordered lists, as that is where most nesting will occur, the only
element that may reside directly within the <ul> and <ol> elements is the <li> element. To
repeat, the only element we can place as a direct child of the <ul> and <ol> elements is
the <li> element.
That said, once inside the <li> element, the standard set of elements may be added, including
any <ul> or <ol> elements.
To nest a list rather than closing a list item, begin a new list. Once the nested list is complete and
closed, close the wrapping list item and continue on with the original list.
<ol>
<li>Fold laundry</li>
<li>
<ul>
<li>Milk</li>
<li>Bread</li>
<li>Cheese</li>
</ul>
</li>
<li>Make dinner</li>
</ol>
Fold laundry
Bread
Cheese
Make dinner
Because nesting lists can be a little tricky—and unwanted styles will appear if it’s done
incorrectly—let’s quickly review. The <ul> and <ol> elements may contain only <li> elements.
The <li> element may contain any normal element as desired; however, the <li> element has to
be a direct child of either a <ul> or <ol> element.
It’s also worth noting that as lists are nested inside of other lists, their list item markers will
change according to how deeply the list is nested. In the previous example, the unordered list
nested within the ordered list uses hollow circles instead of solid discs as the list item marker.
This change happens because the unordered list is nested one level into the ordered list.
Frames and tables are extremely important in web design. It is impossible to create a navigation
bar on a website without using frames or tables in one form or another.
An example of this is that this page is completely enclosed in a giant invisible table. It has a
column down the side to put the navigation in and a giant cell for all the page text. I could also
have got the same effect using frames.
Frames divide up your browser window into separate areas. In each of these a page is loaded.
Links in different pages can be made to change the pages in other frames and frames can stay the
same when another page changes. This means that you can have one page which has the
navigation bar for a whole site on it and it never changes.
Tables divide up a web page into separate cells (like in a spreadsheet). This means that you have
a lot more control over where text and pictures can be placed. By using the method I described
earlier (having a column for a navigation bar and a cell for the page text) you can create complex
page structures. A page looking the same could be created with frames and tables.
The best feature of using frames is, of course, the ability to update every page on your site using
one file. For example: if I used frames on Free Webmaster Help I could add another link to the
navigation bar on one page. When the frames loaded on the web you would see this change,
whatever page you are on.
Frames also make very consistent pages. As you are only changing the text for each page of the
site, the actual look of the page will not change much in the user's browser.
When used properly frames can make a very good design feature and, once each frame has
loaded, the loading times of a site are a lot less (as, usually, only one frame is ever changed
throughout the whole site).
Frames do have their bad points, though. One of the major ones is that, even though frames have
been around for a long time, they are still not fully supported. Some people who are still using
older browsers cannot view frames sites. Even worse, some search engines will not index pages
using frames! This could mean a great loss of traffic for your website
Another problem with frames is that if someone arrives at an internal page on your site the
frames will not appear. This could mean that someone might read a page and not actually know
they are on your site.
The final problem is that it is very difficult to bookmark an internal page in your site and if
someone bookmarks a page on your site (using most browsers) and return later, they will see
your first page, not the one they bookmarked.
The HTML tables allow web authors to arrange data like text, images, links, other
tables, etc. into rows and columns of cells.
The HTML tables are created using the <table> tag in which the <tr> tag is used to
create table rows and <td> tag is used to create data cells. The elements under <td>
are regular and left aligned by default
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Tables</title>
</head>
<body>
<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>
</body>
</html>
Here, the border is an attribute of <table> tag and it is used to put a border across all
the cells. If you do not need a border, then you can use border = "0".
Table Heading
Table heading can be defined using <th> tag. This tag will be put to replace <td> tag,
which is used to represent actual data cell. Normally you will put your top row as table
heading as shown below, otherwise you can use <th> element in any row. Headings,
which are defined in <th> tag are centered and bold by default.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Header</title>
</head>
<body>
<table border = "1">
<tr>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>Ramesh Raman</td>
<td>5000</td>
</tr>
<tr>
<td>Shabbir Hussein</td>
<td>7000</td>
</tr>
</table>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Cellpadding</title>
</head>
<body>
<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>
</body>
</html>
You will use colspan attribute if you want to merge two or more columns into a single
column. Similar way you will use rowspan if you want to merge two or more rows.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Colspan/Rowspan</title>
</head>
<body>
<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>
</body>
</html>
Tables Backgrounds
You can set table background using one of the following two ways −
bgcolor attribute − You can set background color for whole table or just for one
cell.
background attribute − You can set background image for whole table or just for
one cell.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Background</title>
</head>
<body>
<table border = "1" bordercolor = "green" bgcolor = "yellow">
<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>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Background</title>
</head>
<body>
<table border = "1" bordercolor = "green" background = "/images/test.png">
<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>
</body>
</html>
This will produce the following result. Here background image did not apply to table's
header.
You can set a table width and height using width and height attributes. You can specify
table width or height in terms of pixels or in terms of percentage of available screen
area.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Width/Height</title>
</head>
<body>
<table border = "1" width = "400" height = "150">
<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>
</body>
</html>
Table Caption
The caption tag will serve as a title or explanation for the table and it shows up at the
top of the table. This tag is deprecated in newer version of HTML/XHTML.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Caption</title>
</head>
<body>
<table border = "1" width = "100%">
<caption>This is the caption</caption>
<tr>
<td>row 1, column 1</td><td>row 1, columnn 2</td>
</tr>
<tr>
<td>row 2, column 1</td><td>row 2, columnn 2</td>
</tr>
</table>
</body>
</html>
Tables can be divided into three portions − a header, a body, and a foot. The head and
foot are rather similar to headers and footers in a word-processed document that remain
the same for every page, while the body is the main content holder of the table.
The three elements for separating the head, body, and foot of a table are −
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table</title>
</head>
<body>
<table border = "1" width = "100%">
<thead>
<tr>
<td colspan = "4">This is the head of the table</td>
</tr>
</thead>
<tfoot>
<tr>
<td colspan = "4">This is the foot of the table</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</tbody>
</table>
</body>
</html>
Nested Tables
You can use one table inside another table. Not only tables you can use almost all the
tags inside table data tag <td>.
Example
Following is the example of using another table and other tags inside a table cell.
<!DOCTYPE html>
<html>
<head>
<title>HTML Table</title>
</head>
<body>
<table border = "1" width = "100%">
<tr>
<td>
<table border = "1" width = "100%">
<tr>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>Ramesh Raman</td>
<td>5000</td>
</tr>
<tr>
<td>Shabbir Hussein</td>
<td>7000</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Frames In HTML
<html>
<head>
<title>My Frames Page</title>
</head>
<frameset border="0" cols="150,*" frameborder="0">
<frame name="contents" target="main" src="contents.htm" scrolling="auto" noresize>
<frame name="main" src="main.htm" scrolling="auto" noresize>
<noframes>
<body>
<p>This page uses frames, but your browser doesn't support them.</p>
</body>
</noframes>
</frameset>
</html>
Description of code:
<html>
<head>
<title>My Frames Page</title>
</head>
This is the standard start for an HTML document. The title will appear in the browser's title bar
for every page on the site as it is contained in frames.
This declares a frames page. It sets the border as none and the frames borders as none. The part:
cols="150,*"
Says that the frames should be columns. One should be 150 pixels wide and the other should fill
up the rest of the screen. This is a very versatile tag. You can use percentages instead of the
values and any number of frames can be added by just adding another comma.
You can also change this to rows= to make the frames rows instead.
This is the tag for the first frame. It tells you the frame should be referred to as contents, links in
it will open in the frame called main, the page to be loaded in the frame is contents.htm and that
scrollbars should be used if needed. It also tells the browser not to allow the user to resize the
frame. Other values which could have been used for scrolling could be yes and no. These would
set the browser to always display scollbars or never display them respectively.
<noframes>
<body>
<p>This page uses frames, but your browser doesn't support them.</p>
</body>
</noframes>
This is the area where you can put the information to be displayed by browsers which don't
support frames. It is a normal HTML page between the <body></body> tags.
</frameset>
</html>
The final thing you need to know to use the a tag to make hyperlinks refer to another frame. To
do this you add target="framename" to the hyperlink tag. For example to make a page load in the
main frame you would use:
Links are found in nearly all web pages. Links allow users to click their way
from page to page.
When you move the mouse over a link, the mouse arrow will turn into a little
hand.
Note: A link does not have to be text. A link can be an image or any other
HTML element!
<a href="url">link text</a>
Clicking on the link text, will send the reader to the specified URL address.
Example
<a href="https://www.Google.com/">Visit Google.com!</a>
By default, the linked page will be displayed in the current browser window.
To change this, you must specify another target for the link.
Example
<a href="https://www.Google.com/" target="_blank">Visit Google!</a>
Both examples above are using an absolute URL (a full web address) in
the href attribute.
A local link (a link to a page within the same website) is specified with
a relative URL (without the "https://www" part):
Example
<h2>Absolute URLs</h2>
<p><a href="https://www.google.com/">Google</a></p>
<h2>Relative URLs</h2>
<p><a href="html_images.asp">HTML Images</a></p>
<p><a href="/css/default.asp">CSS Tutorial</a></p>
Example
<a href="default.asp">
<img src="smiley.gif" alt="HTML
tutorial" style="width:42px;height:42px;">
</a>
Example
<a href="mailto:someone@example.com">Send email</a>
Button as a Link
To use an HTML button as a link, you have to add some JavaScript code.
Example
<button onclick="document.location='default.asp'">HTML
Tutorial</button>
Link Titles
Example
<a href="https://www.google.com/html/" title="Go to google HTML
section">Visit our HTML Tutorial</a>
Link to a page located in the html folder on the current web site:
<a href="/html/default.asp">HTML tutorial</a>
Example
<a href="default.asp">HTML tutorial</a>
Summary
Tag Description
Images
HTML img tag is used to display image on the web page. HTML img tag is an empty
tag that contains attributes only, closing tags are not used in HTML image element.
<h2>HTML Image Example</h2>
<img src="good_morning.jpg" alt="Good Morning Friends"/>
Output:
The src and alt are important attributes of HTML img tag. All attributes of HTML image
tag are given belowC++ vs Java
1) src
It is a necessary attribute that describes the source or path of the image. It instructs the
browser where to look for the image on the server.
The alt attribute defines an alternate text for the image, if it can't be displayed. The value
of the alt attribute describe the image in words. The alt attribute is considered good for
SEO prospective.
3) width
It is an optional attribute which is used to specify the width to display the image. It is
not recommended now. You should apply CSS in place of width attribute.
4) height
It h3 the height of the image. The HTML height attribute also supports iframe, image
and object elements. It is not recommended now. You should apply CSS in place of
height attribute.
You have learnt about how to insert an image in your web page, now if we want to give
some height and width to display image according to our requirement, then we can set
it with height and width attributes of image.
Example:
1. <img src="animal.jpg" height="180" width="300" alt="animal image">
Output:
Note: Always try to insert the image with height and width, else it may flicker while
displaying on webpage.
We can use alt attribute with tag. It will display an alternative text in case if image
cannot be displayed on browser. Following is the example for alt attribute:
1. <img src="animal.png" height="180" width="300" alt="animal image">
Output:
To insert an image in your web, that image must be present in your same folder where
you have put the HTML file. But if in some case image is available in some other
directory then you can access the image like this:
1. <img src="E:/images/animal.png" height="180" width="300" alt="animal image">
We can also link an image with other page or we can use an image as a link. To do this,
put <img> tag inside the <a> tag.
Example
1. <a href="https://www.javatpoint.com/what-is-robotics"><img src="robot.jpg" heigh
t="100" width="100"></a>
Output:
Supporting Browsers
Multimedia
What is Multimedia?
Browser Support
The first web browsers had support for text only, limited to a single font in a
single color.
Later came browsers with support for colors, fonts, images, and multimedia!
Multimedia Formats
The most common way to discover the type of a file, is to look at the file
extension.
MPEG .mpg MPEG. Developed by the Moving Pictures Expert Group. The first p
.mpeg format on the web. Not supported anymore in HTML.
AVI .avi AVI (Audio Video Interleave). Developed by Microsoft. Commonly u
cameras and TV hardware. Plays well on Windows computers, but
browsers.
RealVideo .rm RealVideo. Developed by Real Media to allow video streaming with
.ram Does not play in web browsers.
WebM .webm WebM. Developed by Mozilla, Opera, Adobe, and Google. Supporte
MPEG-4 .mp4 MP4. Developed by the Moving Pictures Expert Group. Commonly u
or MP4 cameras and TV hardware. Supported by all browsers and recomm
YouTube.
Note: Only MP4, WebM, and Ogg video are supported by the HTML
standard.
MP3 is the best format for compressed recorded music. The term MP3 has
become synonymous with digital music.
MIDI .mid MIDI (Musical Instrument Digital Interface). Main format for all elect
.midi devices like synthesizers and PC sound cards. MIDI files do not conta
digital notes that can be played by electronics. Plays well on all comp
hardware, but not in web browsers.
RealAudi .rm RealAudio. Developed by Real Media to allow streaming of audio with
o .ram Does not play in web browsers.
WMA .wma WMA (Windows Media Audio). Developed by Microsoft. Plays well on
computers, but not in web browsers.
AAC .aac AAC (Advanced Audio Coding). Developed by Apple as the default fo
Plays well on Apple computers, but not in web browsers.
WAV .wav WAV. Developed by IBM and Microsoft. Plays well on Windows, Macin
operating systems. Supported by HTML.
MP3 .mp3 MP3 files are actually the sound part of MPEG files. MP3 is the most
for music players. Combines good compression (small files) with hig
Supported by all browsers.
MP4 .mp4 MP4 is a video format, but can also be used for audio. Supported by
Note: Only MP3, WAV, and Ogg audio are supported by the HTML standard.
Example
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video
How it Works
Example
<video width="320" height="240" autoplay>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
Example
<video width="320" height="240" autoplay muted>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
Browser Support
The numbers in the table specify the first browser version that fully supports
the <video> element.
Element
There are three supported video formats: MP4, WebM, and Ogg. The
browser support for the different formats is:
MP4 video/mp4
WebM video/webm
Ogg video/ogg
There are also DOM events that can notify you when a video begins to play,
is paused, etc.
Play/Pause Big Small Normal
Tag Description
<source> Defines multiple media resources for media elements, such as <vid
<audio>
<track> Defines text tracks in media players
HTML Audio
Example
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio
Example
<audio controls autoplay>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Example
The numbers in the table specify the first browser version that fully supports
the <audio> element.
Element
There are three supported audio formats: MP3, WAV, and OGG. The browser
support for the different formats is:
*From Edge 79
MP3 audio/mpeg
OGG audio/ogg
WAV audio/wav
This allows you to load, play, and pause audios, as well as set duration and
volume.
There are also DOM events that can notify you when an audio begins to play,
is paused, etc.
Tag Description
<source> Defines multiple media resources for media elements, such as <video>
HTML Form
HTML forms are required if you want to collect some data from of the site visitor.
For example: If a user want to purchase some items on internet, he/she must fill the
form such as shipping address and credit/debit card details so that item can be sent to
the given address.
7.3M
234
<form action="server url" method="get|post">
//input controls e.g. textfield, textarea, radiobutton, button
</form>
Tag Description
Tag Description
The HTML <form> element provide a document section to take input from user. It
provides various interactive controls for submitting information to web server such as
text field, text area, password field, etc.
Note: The <form> element does not itself create a form but it is container to contain all
required form elements, such as <input>, <label>, etc.
Syntax:
<form>
//Form elements </form>
The HTML <input> element is fundamental form element. It is used to create form
fields, to take input from user. We can apply different input filed to gather different
information form user. Following is the example to show the simple text input.
Example:
<body>
<form>
Enter your name <br>
<input type="text" name="username">
</form>
</body>
Output:
<form>
First Name: <input type="text" name="firstname"/> <br/>
Last Name: <input type="text" name="lastname"/> <br/>
</form>
Output:
Note: If you will omit 'name' attribute then the text filed input will not be submitted to
server.
The <textarea> tag in HTML is used to insert multiple-line text in a form. The size of
<textarea> can be specify either using "rows" or "cols" attribute or by CSS.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Form in HTML</title>
5. </head>
6. <body>
7. <form>
8. Enter your address:<br>
9. <textarea rows="2" cols="20"></textarea>
10. </form>
11. </body>
12. </html>
Output:
If you click on the label tag, it will focus on the text control. To do so, you need to have
for attribute in label tag that must be same as id attribute of input tag.
NOTE: It is good to use <label> tag with form, although it is optional but if you will use it,
then it will provide a focus when you tap or click on label tag. It is more worthy with
touchscreens.
<form>
<label for="firstname">First Name: </label> <br/>
<input type="text" id="firstname" name="firstname"/> <br/>
<label for="lastname">Last Name: </label>
<input type="text" id="lastname" name="lastname"/> <br/>
</form>
Output:
1. <form>
2. <label for="password">Password: </label>
3. <input type="password" id="password" name="password"/> <br/>
4. </form>
Output:
HTML 5 Email Field Control
The email field in new in HTML 5. It validates the text for correct email address. You
must use @ and . in this field.
<form>
<label for="email">Email: </label>
<input type="email" id="email" name="email"/> <br/>
</form>
The radio button is used to select one option from multiple options. It is used for
selection of gender, quiz questions etc.
If you use one name for all the radio buttons, only one radio button can be selected at a
time.
Using radio buttons for multiple options, you can only choose a single option at a time.
<form>
<label for="gender">Gender: </label>
<input type="radio" id="gender" name="gender" value="male"/>Male
<input type="radio" id="gender" name="gender" value="female"/>Female
<br/>
</form>
Checkbox Control
The checkbox control is used to check multiple options from given checkboxes.
<form>
Hobby:<br>
<input type="checkbox" id="cricket" name="cricket" value="cricket"/>
<label for="cricket">Cricket</label> <br>
<input type="checkbox" id="football" name="football" value="football"/>
<label for="football">Football</label> <br>
<input type="checkbox" id="hockey" name="hockey" value="hockey"/>
<label for="hockey">Hockey</label>
</form>
Note: These are similar to radio button except it can choose multiple options at a time
and radio button can select one button at a time, and its display.
Output:
Submit button control
Syntax:
<input type="submit" value="submit">
The value attribute can be anything which we write on button on web page.
Example:
<form>
<label for="name">Enter name</label><br>
<input type="text" id="name" name="name"><br>
<label for="pass">Enter Password</label><br>
<input type="Password" id="pass" name="pass"><br>
<input type="submit" value="submit">
</form>
Output:
The <fieldset> element in HTML is used to group the related information of a form. This
element is used with <legend> element which provide caption for the grouped
elements.
Example:
<form>
<fieldset>
<legend>User Information:</legend>
<label for="name">Enter name</label><br>
<input type="text" id="name" name="name"><br>
<label for="pass">Enter Password</label><br>
<input type="Password" id="pass" name="pass"><br>
<input type="submit" value="submit">
</fieldset>
lt;/form>
Output:
<!DOCTYPE html>
<html>
<head>
<title>Form in HTML</title>
</head>
<body>
<h2>Registration form</h2>
<form>
<fieldset>
<legend>User personal information</legend>
<label>Enter your full name</label><br>
<input type="text" name="name"><br>
<label>Enter your email</label><br>
<input type="email" name="email"><br>
<label>Enter your password</label><br>
<input type="password" name="pass"><br>
<label>confirm your password</label><br>
<input type="password" name="pass"><br>
<br><label>Enter your gender</label><br>
<input type="radio" id="gender" name="gender" value="male"/>Male <br>
<input type="radio" id="gender" name="gender" value="female"/>Female
<br/>
<input type="radio" id="gender" name="gender" value="others"/>others <br/>
<br>Enter your Address:<br>
<textarea></textarea><br>
<input type="submit" value="sign-up">
</fieldset>
</form>
</body>
</html>
Output:
1. <form action="#">
2. <table>
3. <tr>
4. <td class="tdLabel"><label for="register_name" class="label">Enter name:</
label></td>
5. <td><input type="text" name="name" value="" id="register_name" style="width:16
0px"/></td>
6. </tr>
7. <tr>
8. <td class="tdLabel"><label for="register_password" class="label">Enter password:<
/label></td>
9. <td><input type="password" name="password" id="register_password" style="widt
h:160px"/></td>
10. </tr>
11. <tr>
12. <td class="tdLabel"><label for="register_email" class="label">Enter Email:</
label></td>
13. <td
14. ><input type="email" name="email" value="" id="register_email" style="width:160px"/
></td>
15. </tr>
16. <tr>
17. <td class="tdLabel"><label for="register_gender" class="label">Enter Gender:</
label></td>
18. <td>
19. <input type="radio" name="gender" id="register_gendermale" value="male"/>
20. <label for="register_gendermale">male</label>
21. <input type="radio" name="gender" id="register_genderfemale" value="female"/>
22. <label for="register_genderfemale">female</label>
23. </td>
24. </tr>
25. <tr>
26. <td class="tdLabel"><label for="register_country" class="label">Select Country:</
label></td>
27. <td><select name="country" id="register_country" style="width:160px">
28. <option value="india">india</option>
29. <option value="pakistan">pakistan</option>
30. <option value="africa">africa</option>
31. <option value="china">china</option>
32. <option value="other">other</option>
33. </select>
34. </td>
35. </tr>
36. <tr>
37. <td colspan="2"><div align="right"><input type="submit" id="register_0" value="r
egister"/>
38. </div></td>
39. </tr>
40. </table>
41. </form>
Test it Now
Supporting Browsers