WT Unit - 2
WT Unit - 2
What is HTML:
HTML is an acronym which stands for Hyper Text Markup Language which is used
for creating web pages and web applications.
Static HTML, or HTML, is a collection of Tags. Let's see what is meant by Hypertext
Markup Language, and Web page.
HyperText: HyperText simply means "Text within Text." A text has a link within it,
is a hypertext. Whenever you click on a link which brings you to a new webpage,
you have clicked on a hypertext. HyperText is a way to link two or more web pages
(HTML documents) with each other.
Web Page: A web page is a document which is commonly written in HTML and
translated by a web browser. A web page can be identified by entering an URL. A
Web page can be of the static or dynamic type. With the help of HTML only, we
can create static web pages.
Hence, HTML is a markup language which is used for creating attractive web pages
with the help of styling, and which looks in a nice format on a web browser. An
HTML document is made of many HTML tags and each HTML tag contains different
content.
<!DOCTYPE>
<html>
<head>
</head>
<body>
https://cgccollegespace.live/
<h1>Write Your First Heading</h1>
</body>
</html>
<html > :This tag informs the browser that it is an HTML document. Text between
html tag describes the web document. It is a container for all other elements of
HTML except <!DOCTYPE>
<head>: It should be the first element inside the <html> element, which contains
the metadata(information about the document). It must be closed before the body
tag opens.
<title>: As its name suggested, it is used to add title of that HTML page which
appears at the top of the browser window. It must be placed inside the head tag and
should close immediately. (Optional)
<body> : Text between body tag describes the body content of the page that is
visible to the end user. This tag contains the main content of the HTML document.
<h1> : Text between <h1> tag describes the first level heading of the webpage.
<p> : Text between <p> tag describes the paragraph of the webpage.
Tim Berners-Lee is known as the father of HTML. The first available description of
HTML was a document called "HTML Tags" proposed by Tim in late 1991. The latest
version of HTML is HTML5, which we will learn later in this tutorial.
https://cgccollegespace.live/
HTML Versions
Since the time HTML was invented there are lots of HTML versions in market, the
brief introduction about the HTML version is given below:
HTML 1.0: The first version of HTML was 1.0, which was the barebones version of
HTML language, and it was released in1991.
HTML 2.0: This was the next version which was released in 1995, and it was
standard language version for website design. HTML 2.0 was able to support extra
features such as form-based file upload, form elements such as text box, option
button, etc.
HTML 3.2: HTML 3.2 version was published by W3C in early 1997. This version was
capable of creating tables and providing support for extra options for form elements.
It can also support a web page with complex mathematical equations. It became an
official standard for any browser till January 1997. Today it is practically supported
by most of the browsers.
HTML 4.01: HTML 4.01 version was released in December 1999, and it is a very
stable version of HTML language. This version is the current official standard, and it
provides added support for stylesheets (CSS) and scripting ability for various
multimedia elements.
HTML5 : HTML5 is the newest version of HyperText Markup language. The first draft
of this version was announced in January 2008. There are two major organizations
one is W3C (World Wide Web Consortium), and another one is WHATWG( Web
Hypertext Application Technology Working Group) which are involved in the
development of HTML 5 version, and still, it is under development.
Features of HTML
1) It is a very easy and simple language. It can be easily understood and
modified.
4) It facilitates programmers to add a link on the web pages (by html anchor tag),
so it enhances the interest of browsing of the user.
https://cgccollegespace.live/
6) It facilitates the programmer to add Graphics, Videos, and Sound to the web
pages which makes it more attractive and interactive.
DHTML Tutorial
DHTML stands for Dynamic Hypertext Markup language i.e., Dynamic HTML.
3. JS (JavaScript)
The DHTML application was introduced by Microsoft with the release of the 4th
version of IE (Internet Explorer) in 1997.
● HTML 4.0
● CSS
● JavaScript
● DOM.
HTML 4.0
https://cgccollegespace.live/
CSS
CSS stands for Cascading Style Sheet, which allows the web users or developers for
controlling the style and layout of the HTML elements on the web pages.
JavaScript
DOM
Uses of DHTML
Following are the uses of DHTML (Dynamic HTML):
● It is used for designing the animated and interactive web pages that are
developed in real-time.
● DHTML helps users by animating the text and images in their documents.
● It also allows the page authors for including the drop-down menus or rollover
buttons.
● It is also used to add the ticker on various websites, which needs to refresh
their content automatically.
Features of DHTML
Following are the various characteristics or features of DHTML (Dynamic HTML):
● Its simplest and main feature is that we can create the web page
dynamically.
https://cgccollegespace.live/
● Dynamic Style is a feature, that allows the users to alter the font, size,
color, and content of a web page.
● It provides the facility for using the events, methods, and properties. And,
also provides the feature of code reusability.
● Using DHTML, users can easily create dynamic fonts for their web sites or web
pages.
● With the help of DHTML, users can easily change the tags and their
properties.
2. It is used for developing and 2. It is used for creating and designing the
pages.
4. It does not contain any server-side 4. It may contain the code of server-side
5. The files of HTML are stored with 5. The files of DHTML are stored with the
system.
https://cgccollegespace.live/
6. A simple page which is created by 6. A page which is created by a user using
a user without using the scripts or the HTML, CSS, DOM, and JavaScript
https://cgccollegespace.live/
HTML <meta> tag
HTML <meta> tag is used to represent the metadata about the HTML document.
It specifies page description, keywords, copyright, language, author of the
documents, etc.
The metadata does not display on the webpage, but it is used by search engines,
browsers and other web services which scan the site or webpage to know about
the webpage.
With the help of meta tag, you can experiment and preview how your webpage
will render on the browser.
The <meta> tag is placed within the <head> tag, and it can be used more than
Syntax:
1. <meta charset="utf-8">
Display None
Following are some specific syntaxes of meta tag which shows the different
uses of meta Tag.
1. 1. <meta charset="utf-8">
It defines the character encoding. The value of charset is "utf-8" which means it
https://cgccollegespace.live/
It specifies the list of keywords which is used by search engines.
In the above example we have set a URL with content so it will automatically
It specifies the viewport to control the page dimension and scaling so that our
website looks good on all devices. If this tag is present, it indicates that this page
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta charset="utf-8">
5. <meta name="keywords" content="HTML, CSS, JavaScript, Tutorials">
6. <meta name="description" content="Free Online tutorials">
7. <meta name="author" content="thisauthor">
https://cgccollegespace.live/
8. <meta http-equiv="refresh" content="5;
url=https://www.javatpoint.com/html-tags-list">
9. <meta name="viewport" content="width=device-width,
initial-scale=1.0">
10.</head>
11.<body>
12.<h2>Example of Meta tag</h2>
13.<p>This example shows the use of meta tag within an HTML
document</p>
14.</body>
15.</html>
Attribute:
Tag-specific attributes:
= New in HTML5
HTML page.
● refresh
https://cgccollegespace.live/
name It specifies the name of document-level
● application-n
metadata.
ame
● author
● description
● generator
● keywords
Global attribute:
The <meta> tag supports the global attributes in HTML
Event attribute:
The <meta> tag supports the event attributes in HTML.
Supporting Browsers
Element Chrome IE Firefox Opera Safari
https://cgccollegespace.live/
has introduced application programming interfaces(API) and Document
Object Model(DOM).
Features:
Removed elements from HTML 5: There are many elements which are
depreciated from HTML 5 are listed below:
https://cgccollegespace.live/
New Added Elements in HTML 5:
https://cgccollegespace.live/
● <mark>: The <mark> tag in HTML is used to define the marked
text. It is used to highlight the part of the text in the paragraph.
● <nav>: The <nav> tag is used to declaring the navigational
section in HTML documents. Websites typically have sections
dedicated to navigational links, which enables user to navigate the
site. These links can be placed inside a nav tag.
● <section>: It demarcates a thematic grouping of content.
● <details>: The <details> tag is used for the content/information
which is initially hidden but could be displayed if the user wishes
to see it. This tag is used to create interactive widget which user
can open or close it. The content of details tag is visible when
open the set attributes.
● <summary>: The <summary> tag in HTML is used to define a
summary for the <details> element. The <summary> element is
used along with the <details> element and provides a summary
visible to the user. When the summary is clicked by the user, the
content placed inside the <details> element becomes visible
which was previously hidden. The <summary> tag was added in
HTMl 5. The <summary> tag requires both starting and ending
tag.
● <time>: The <time> tag is used to display the human-readable
data/time. It can also be used to encode dates and times in a
machine-readable form. The main advantage for users is that they
can offer to add birthday reminders or scheduled events in their
calender’s and search engines can produce smarter search
results.
● <bdi>: The <bdi> tag refers to the Bi-Directional Isolation. It
differentiate a text from other text that may be formatted in
https://cgccollegespace.live/
different direction. This tag is used when a user generated text
with an unknown directions.
● <wbr>: The <wbr> tag in HTML stands for word break opportunity
and is used to define the position within the text which is treated
as a line break by the browser. It is mostly used when the used
word is too long and there are chances that the browser may
break lines at the wrong place for fitting the text.
● <datalist>: The <datalist> tag is used to provide autocomplete
feature in the HTML files. It can be used with input tag, so that
users can easily fill the data in the forms using select the data.
● <keygen>: The <keygen> tag in HTML is used to specify a
key-pair generator field in a form. The purpose of <keygen>
element is to provide a secure way to authenticate users. When a
from is submitted then two keys are generated, private key and
public key. The private key stored locally, and the public key is
sent to the server. The public key is used to generate client
certificate to authenticate user for future.
● <output>: The <output> tag in HTML is used to represent the
result of a calculation performed by the client-side script such as
JavaScript.
● <progress>: It is used to represent the progress of a task. It is
also define that how much work is done and how much is left to
download a things. It is not used to represent the disk space or
relevant query.
● <svg>: It is the Scalable Vector Graphics.
● <canvas>: The <canvas> tag in HTML is used to draw graphics
on web page using JavaScript. It can be used to draw paths,
https://cgccollegespace.live/
boxes, texts, gradient and adding images. By default it does not
contains border and text.
● <audio>: It defines the music or audio content.
● <embed>: Defines containers for external applications (usually a
video player).
● <source>: It defines the sources for <video> and <audio>.
● <track>: It defines the tracks for <video> and <audio>.
● <video>: It defines the video content.
Advantages:
Disadvantages:
https://cgccollegespace.live/
HTML Images:
Images can improve the design and the appearance of a web page.
Example
Example
Example
https://cgccollegespace.live/
Images are not technically inserted into a web page; images are linked to
web pages. The <img> tag creates a holding space for the referenced image.
The <img> tag is empty, it contains attributes only, and does not have a
closing tag.
Syntax
alt="alternatetext"
<img src="url" >
The required src attribute specifies the path (URL) to the image.
Note: When a web page loads; it is the browser, at that moment, that gets
the image from a web server and inserts it into the page. Therefore, make
sure that the image actually stays in the same spot in relation to the web
page, otherwise your visitors will get a broken link icon. The broken link icon
and the alt text are shown if the browser cannot find the image.
Example
https://cgccollegespace.live/
<img src="img_chania.jpg" alt="Flowers in Chania">
The required alt attribute provides an alternate text for an image, if the
user for some reason cannot view it (because of slow connection, an error in
Example
If a browser cannot find an image, it will display the value of the alt
attribute:
Example
Tip: A screen reader is a software program that reads the HTML code, and allows the
user to "listen" to the content. Screen readers are useful for people who are visually
https://cgccollegespace.live/
Image Size - Width and Height
You can use the style attribute to specify the width and height of an image.
Example
Example
The width and height attributes always define the width and height of the
image in pixels.
Note: Always specify the width and height of an image. If width and height are not
specified, the web page might flicker while the image loads.
https://cgccollegespace.live/
The width, height, and style attributes are all valid in HTML.
Example
<!DOCTYPE html>
<html>
<head>
<style>
img {
width: 100%;
</style>
</head>
<body>
</body>
https://cgccollegespace.live/
</html>
The <link> tag is commonly used to link the external Stylesheet for the current
document, but it can also use with link site icons. It is placed on the head section of
the document.
Example
1. <link rel="stylesheet" type="text/css" href="">
Display None
Usage textual
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Link Tag</title>
5. <link rel="stylesheet" type="text/css" href="htmlpages/css/link.css">
6. </head>
https://cgccollegespace.live/
7. <body>
8. <h2>Example of Link Tag</h2>
9. <p>This is paragraph which is styled with external style sheet. </p>
10.</body>
11.</html>
CSS
1. body{
2. background-color: #7ac5cd;
3. text-align: center;}
4. h2{
5. color: #006400;}
6.
7. p{
8. color: #cd5c5c;
9. font-size: 25px;
10. font-style: italic;}
Output:
Attribute:
Tag-specific attributes:
https://cgccollegespace.live/
charset char_encoding It defines the character encoding of linked source. (Not
ss supported in HTML5)
media media_query It specifies the media, for which linked source is applied.
● dns-pr
efetch
● help
● icon
● license
● next
● pingba
ck
● precon
nect
● prefetc
h
https://cgccollegespace.live/
● preloa
d
● preren
der
● prev
● search
● stylesh
eet
rev reversed It describes the relationship between the linked document and
he current document. (Not supported in HTML5)
relationship
sizes Height* weight It specifies the size of the linked source. It should be only use
ith rel="icon."
_self
_top
_parent
frame_name
https://cgccollegespace.live/
Global attribute:
The <link> tag supports the global attributes in HTML
Event attribute:
The <link > tag supports the event attributes in HTML.
Supporting Browsers
https://cgccollegespace.live/
HTML Audio Tag
HTML audio tag is used to define sounds such as music and other audio clips.
Currently there are three supported file format for HTML 5 audio tag.
1. mp3
2. wav
3. ogg
HTML5 supports <video> and <audio> controls. The Flash, Silverlight and similar
This table defines that which web browser supports which audio file format.
https://cgccollegespace.live/
Apple Safari yes yes no
1. <audio controls>
2. <source src="koyal.mp3" type="audio/mpeg">
3. Your browser does not support the html audio tag.
4. </audio>
Output:
Let's see the example to play ogg file using HTML audio tag.
1. <audio controls>
2. <source src="koyal.ogg" type="audio/ogg">
3. Your browser does not support the html audio tag.
4. </audio>
Supporting Browsers
AttributeDescription
controls It defines the audio controls which is displayed with play/pause buttons.
autoplay It specifies that the audio will start playing as soon as it is ready.
loop It specifies that the audio file will start over again, every time when it is
ompleted.
preload It specifies the author view to upload audio file when the page loads.
https://cgccollegespace.live/
MIME Types for HTML Audio format
The available MIME type HTML audio tag is given below.
mp3 adio/mpeg
ogg audio/ogg
wav audio/wav
Currently, there are three video formats supported for HTML video tag:
1. mp4
2. webM
3. ogg
Let's see the table that defines which web browser supports video file format.
https://cgccollegespace.live/
Internet Explorer yes no no
1. <video controls>
2. <source src="movie.mp4" type="video/mp4">
3. Your browser does not support the html video tag.
4. </video>
Let's see the example to play ogg file using HTML video tag.
1. <video controls>
2. <source src="movie.ogg" type="video/ogg">
3. Your browser does not support the html video tag.
https://cgccollegespace.live/
4. </video>
Supporting Browsers
Attribute Description
controls It defines the video controls which is displayed with play/pause buttons.
https://cgccollegespace.live/
poster It specifies the image which is displayed on the screen when the video is
ot played.
autoplay It specifies that the video will start playing as soon as it is ready.
loop It specifies that the video file will start over again, every time when it is
ompleted.
preload It specifies the author view to upload video file when the page loads.
https://cgccollegespace.live/
MIME Types for HTML Video format
The available MIME type HTML video tag is given below.
mp4 video/mp4
ogg video/ogg
webM video/webM
HTML Table
HTML table tag is used to display data in tabular form (row * column). There can
We can create a table to display data in tabular form, using <table> element, with
the help of <tr> , <td>, and <th> elements.
In Each table, table row is defined by <tr> tag, table header is defined by <th>, and
HTML tables are used to manage the layout of the page e.g. header section,
navigation bar, body content, footer section etc. But it is recommended to use div
tag over table to manage the layout of the page .
https://cgccollegespace.live/
HTML Table Tags
Tag Description
<col> is used with <colgroup> element to specify column properties for each
olumn.
https://cgccollegespace.live/
<thead> is used to group the header content in a table.
1. <table>
2. <tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr
>
3. <tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>
4. <tr><td>James</td><td>William</td><td>80</td></tr>
5. <tr><td>Swati</td><td>Sironi</td><td>82</td></tr>
6. <tr><td>Chetna</td><td>Singh</td><td>72</td></tr>
7. </table>
Output:
Sonoo Jaiswal 60
James William 80
https://cgccollegespace.live/
Swati Sironi 82
Chetna Singh 72
In the above html table, there are 5 rows and 3 columns = 5 * 3 = 15 values.
recommended now.
1. <table border="1">
2. <tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr
>
3. <tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>
4. <tr><td>James</td><td>William</td><td>80</td></tr>
5. <tr><td>Swati</td><td>Sironi</td><td>82</td></tr>
6. <tr><td>Chetna</td><td>Singh</td><td>72</td></tr>
7. </table>
Output:
https://cgccollegespace.live/
First_Name Last_Name Marks
Sonoo Jaiswal 60
James William 80
Swati Sironi 82
Chetna Singh 72
1. <style>
2. table, th, td {
3. border: 1px solid black;
4. }
5. </style>
You can collapse all the borders in one border by border-collapse property. It will
1. <style>
2. table, th, td {
3. border: 2px solid black;
https://cgccollegespace.live/
4. border-collapse: collapse;
5. }
6. </style>
Output:
Sonoo Jaiswal 60
James William 80
Swati Sironi 82
Chetna Singh 72
https://cgccollegespace.live/
1. <style>
2. table, th, td {
3. border: 1px solid pink;
4. border-collapse: collapse;
5. }
6. th, td {
7. padding: 10px;
8. }
9. </style>
Output:
Sonoo Jaiswal 60
James William 80
Swati Sironi 82
Chetna Singh 72
https://cgccollegespace.live/
We can specify the HTML table width using the CSS width property. It can be
We can adjust our table width as per our requirement. Following is the example to
1. table{
2. width: 100%;
3. }
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>table</title>
5. <style>
6. table{
7. border-collapse: collapse;
8. width: 100%;
9. }
10. th,td{
11. border: 2px solid green;
12. padding: 15px;
13. }
14.
15. </style>
16. </head>
17.<body>
18. <table>
19. <tr>
20. <th>1 header</th>
21. <th>1 header</th>
22. <th>1 header</th>
23. </tr>
24. <tr>
https://cgccollegespace.live/
25. <td>1data</td>
26. <td>1data</td>
27. <td>1data</td>
28. </tr>
29. <tr>
30. <td>2 data</td>
31. <td>2 data</td>
32. <td>2 data</td>
33. </tr>
34. <tr>
35. <td>3 data</td>
36. <td>3 data</td>
37. <td>3 data</td>
38. </tr>
39.</table>
40.</body>
41.</html> Output:
attribute.
https://cgccollegespace.live/
It will divide one cell/row into multiple columns, and the number of columns depend
CSS code:
1. <style>
2. table, th, td {
3. border: 1px solid black;
4. border-collapse: collapse;
5. }
6. th, td {
7. padding: 5px;
8. }
9. </style>
HTML code:
1. <table style="width:100%">
2. <tr>
3. <th>Name</th>
4. <th colspan="2">Mobile No.</th>
5. </tr>
6. <tr>
7. <td>Ajeet Maurya</td>
8. <td>7503520801</td>
9. <td>9555879135</td>
10. </tr>
11.</table>
Output:
https://cgccollegespace.live/
Ajeet Maurya 7503520801 9555879135
attribute.
It will divide a cell into multiple rows. The number of divided rows will depend on
rowspan values.
CSS code:
1. <style>
2. table, th, td {
3. border: 1px solid black;
4. border-collapse: collapse;
5. }
6. th, td {
7. padding: 10px;
8. }
9. </style>
HTML code:
1. <table>
2. <tr><th>Name</th><td>Ajeet Maurya</td></tr>
3. <tr><th rowspan="2">Mobile No.</th><td>7503520801</td></tr>
4. <tr><td>9555879135</td></tr>
5. </table>
Output:
https://cgccollegespace.live/
Name Ajeet Maurya
9555879135
1. <table>
2. <caption>Student Records</caption>
3. <tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr
>
4. <tr><td>Vimal</td><td>Jaiswal</td><td>70</td></tr>
5. <tr><td>Mike</td><td>Warn</td><td>60</td></tr>
6. <tr><td>Shane</td><td>Warn</td><td>42</td></tr>
7. <tr><td>Jai</td><td>Malhotra</td><td>62</td></tr>
8. </table>
1. <style>
2. table, th, td {
3. border: 1px solid black;
https://cgccollegespace.live/
4. border-collapse: collapse;
5. }
6. th, td {
7. padding: 10px;
8. }
9. table#alter tr:nth-child(even) {
10. background-color: #eee;
11.}
12.table#alter tr:nth-child(odd) {
13. background-color: #fff;
14.}
15.table#alter th {
16. color: white;
17. background-color: gray;
18.}
19.</style>
Output:
NOTE: You can also create various types of tables using different CSS properties in your
table.
https://cgccollegespace.live/
Supporting Browsers
HTML Form
An HTML form is a section of a document which contains controls such as text
fields, password fields, checkboxes, radio buttons, submit button, menus etc.
An HTML form facilitates the user to enter data that is to be sent to the server for
processing such as name, email address, password, phone number, etc. .
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
https://cgccollegespace.live/
HTML Form Tags
Let's see the list of HTML 5 form tags.
Tag Description
https://cgccollegespace.live/
<optgroup> It defines a group of related options in a drop-down list.
Tag Description
https://cgccollegespace.live/
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
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:
1. <form>
2. //Form elements
3. </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:
1. <body>
2. <form>
3. Enter your name <br>
4. <input type="text" name="username">
5. </form>
6. </body>
Output:
https://cgccollegespace.live/
HTML TextField Control
The type="text" attribute of input tag creates textfield control also known as single
line textfield control. The name attribute is optional, but it is required for the server
1. <form>
2. First Name: <input type="text" name="firstname"/> <br/>
3. Last Name: <input type="text" name="lastname"/> <br/>
4. </form>
Output:
https://cgccollegespace.live/
Note: If you will omit 'name' attribute then the text filed input will not be submitted to server.
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:
https://cgccollegespace.live/
Label Tag in Form
It is considered better to have label in form. As it makes the code
parser/browser/user friendly.
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.
1. <form>
2. <label for="firstname">First Name: </label> <br/>
3. <input type="text" id="firstname" name="firstname"/> <br/>
4. <label for="lastname">Last Name: </label>
5. <input type="text" id="lastname" name="lastname"/> <br/>
6. </form>
Output:
https://cgccollegespace.live/
HTML Password Field Control
The password is not visible to the user in password field control.
1. <form>
2. <label for="password">Password: </label>
3. <input type="password" id="password" name="password"/>
<br/>
4. </form>
Output:
https://cgccollegespace.live/
The email field in new in HTML 5. It validates the text for correct email address. You
1. <form>
2. <label for="email">Email: </label>
3. <input type="email" id="email" name="email"/> <br/>
4. </form>
Note: If we will not enter the correct email, it will display error like:
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.
1. <form>
2. <label for="gender">Gender: </label>
3. <input type="radio" id="gender" name="gender"
value="male"/>Male
4. <input type="radio" id="gender" name="gender"
value="female"/>Female <br/>
5. </form>
Checkbox Control
The checkbox control is used to check multiple options from given checkboxes.
1. <form>
2. Hobby:<br>
3. <input type="checkbox" id="cricket" name="cricket"
value="cricket"/>
4. <label for="cricket">Cricket</label> <br>
https://cgccollegespace.live/
5. <input type="checkbox" id="football" name="football"
value="football"/>
6. <label for="football">Football</label> <br>
7. <input type="checkbox" id="hockey" name="hockey"
value="hockey"/>
8. <label for="hockey">Hockey</label>
9. </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:
Syntax:
https://cgccollegespace.live/
The type = submit , specifying that it is a submit button
The value attribute can be anything which we write on button on web page.
Example:
1. <form>
2. <label for="name">Enter name</label><br>
3. <input type="text" id="name" name="name"><br>
4. <label for="pass">Enter Password</label><br>
5. <input type="Password" id="pass" name="pass"><br>
6. <input type="submit" value="submit">
7. </form>
Output:
https://cgccollegespace.live/
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:
1. <form>
2. <fieldset>
3. <legend>User Information:</legend>
4. <label for="name">Enter name</label><br>
5. <input type="text" id="name" name="name"><br>
6. <label for="pass">Enter Password</label><br>
7. <input type="Password" id="pass" name="pass"><br>
8. <input type="submit" value="submit">
9. </fieldset>
10.lt;/form>
Output:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Form in HTML</title>
5. </head>
https://cgccollegespace.live/
6. <body>
7. <h2>Registration form</h2>
8. <form>
9. <fieldset>
10. <legend>User personal information</legend>
11. <label>Enter your full name</label><br>
12. <input type="text" name="name"><br>
13. <label>Enter your email</label><br>
14. <input type="email" name="email"><br>
15. <label>Enter your password</label><br>
16. <input type="password" name="pass"><br>
17. <label>confirm your password</label><br>
18. <input type="password" name="pass"><br>
19. <br><label>Enter your gender</label><br>
20. <input type="radio" id="gender" name="gender"
value="male"/>Male <br>
21. <input type="radio" id="gender" name="gender"
value="female"/>Female <br/>
22. <input type="radio" id="gender" name="gender"
value="others"/>others <br/>
23. <br>Enter your Address:<br>
24. <textarea></textarea><br>
25. <input type="submit" value="sign-up">
26. </fieldset>
27. </form>
28. </body>
29.</html>
Output:
https://cgccollegespace.live/
HTML Form Example
Let's see a simple example of creating HTML form.
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:160px"/></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="width:160px"/></td>
10.</tr>
11.<tr>
12. <td class="tdLabel"><label for="register_email" class="label">Enter
Email:</label></td>
13. <td
https://cgccollegespace.live/
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="register"/>
38.</div></td>
39.</tr>
40.</table>
41. </form>
https://cgccollegespace.live/
Supporting Browsers
UNIT -2 COMPLETED
https://cgccollegespace.live/