Unit 2
Unit 2
HTML: Elements, Tags and basic structure of HTML files, Basic and advanced text formatting,
multimedia Components in HTML documents, Designing of webpage: Document Layout, List,
Tables. Hyperlink, Working with Frames, Forms and Controls.
1. HTML
HTML, or Hypertext Markup Language, is a standard markup language used to create and structure content
on the web. It consists of a set of elements, each represented by tags, which define the different parts and
types of content within a web page. HTML provides a framework for organizing text, images, links, forms,
and multimedia elements, allowing browsers to interpret and display web content consistently.
Hypertext Markup Language (HTML) uses a markup system composed of elements which represent
specific content. Markup means that with HTML you declare what is presented to a viewer, not how
it is presented. HTML is sometimes called a programming language but it has no logic, so is a
markup language. HTML tags provide semantic meaning and machine-readability to the content in
the page.
HTML programs are generally written using any text editor e.g. Notepad, saved with .html extension
and viewed using any web browser like Google chrome. Unlike any programming language, HTML
has no compiler or interpreter so no syntax or semantic errors are generated. HTML programs when
viewed using any Web browser, browser display the content which is rightly written and ignore the
rest. It is the job of the programmer to interpret the output and identify and correct any mistakes.
HTML programs are not bound by any format structure and one can write the HTML program from
any line/column. It does not recognize any white space characters (blanks, tabs, new line
characters). Also, its not case sensitive too.
<element_name>...content...</element_name>
<!-- Complex element with opening and closing tags and nested content -->
<div>
<p>This is a paragraph inside a division.</p>
</div>
In the example above, <br> is a simple element represented by a single tag, while <div> is a more
complex element with an opening tag <div> and a closing tag </div> that encloses the paragraph
content.
A HTML page may consist of potentially hundreds of elements which are then read by a web
browser, interpreted and rendered into human readable or audible content on the screen.
All the web pages will have at least the following base elements: html, head, title and body.
<p>This is a paragraph.</p>
<a href="https://www.example.com">Visit Example</a>
<h1>Main Heading</h1>
A Container tag always wraps around text or contents and come with opening and a closing tag.
These tags are also called the paired tags, the first tag is referred to as Opening Tag and the
second tag is referred to as Closing Tag.
<BODY>
Content
</BODY>
<BODY> is the opening tag and </body> is the closing tag. The forward clash (‘/’) informs to the
browser that the tag has ended. The content between the opening and closing tag is the element or
the content of the web page that works according to the opening tag. Because of the element and
the resulting closing tag, this type of tag is called the container tag. For example:
<TITLE> contains the title of the web page </TITLE>
<BODY> contains the content of the web page </BODY>
The Empty tag does not have closing tag. For example:
<BR> Insert a line break
<HR> Insert a solid line
<BR>
<HR>
HTML links are defined with the <a> tag. The link address is specified in the href attribute:
The following HTML example creates a simple "Hello World" web page.
<html>
<head>
<title>Hello!</title>
</head>
<body>
<h1>Hello World!</h1>
<p>This is a simple paragraph.</p>
</body>
</html>
The head
The body
Tag Meaning
<html> Opens the page. No markup should come after the closing tag (</html>)
<head> Opens the head section, which does not appear in the main browser
window but mainly contains information about the HTML document,
called metadata. It can also contain imports from external stylesheets and
scripts. The closing tag is </head>.
<title> The title of the page. Text written between this opening and the closing
tag (</title>) will be displayed on the tab of the page or in the title bar of
the browser.
<body> Opens the part of the document displayed to users, i.e. all the visible or
audible content of a page. No content should be added after the closing
tag </body>.
<h1> A level 1 heading for the page.
<p> Represents a common paragraph of text.
Note: <html>, <head>, <title> and <body> tags are necessary tags for any HTML document and
are also known as Document Tags.
1.4 HTML Headings
HTML provides six separate header tags to indicate headings of various sizes and thickness.
Enumerated as heading 1 through heading 6, heading 1 has the largest and thickest text while
heading 6 is the smallest and thinnest. These are container tags.
Headings can be used to describe the topic they precede and they are defined with the <h1> to <h6>
tags. So, <h1> is used for most important heading and <h6> is used for least important.
Defining a heading:
<html>
<head>
<title>Heading Tags</title>
</head>
<body>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
</body>
</html>
Output:
Importance of Heading:
• Search Engines use headings for indexing the structure and organizing the content of the
webpage.
• Headings are used for highlighting important topics.
• They provide valuable information and tell us about the structure of the document.
<html>
<head></head>
<body>
<h2>Welcome To HTML Programming</h2>
<!-- Use of <p> tag -->
<p>Learn HTML Programming to create web pages.</p>
<p>It contains well written, well thought articles.</p>
<p>
This paragraph has multiple lines.
But HTML reduces them to a single line,
omitting the carriage return we have used.
</p>
<p>
This paragraph has multiple spaces.
But HTML reduces them to a single line,
omitting the extra spaces and line have used.
</p>
</body>
</html>
Output:
Note: <!-- --> is a comment tag used by programmer for documentation purpose. It will not be
displayed in the output.
Attributes: align
align attribute is used to specify the alignment of paragraph text content. The align attribute in <p>
aligns text horizontally.
Syntax: <p align=” left | right | center | justify”>
Attributes Values Description
left It sets the text left-align. It is default value.
right It sets the text right-align.
center It sets the text center-align.
justify It stretch the text of paragraph to set the width of all lines
equal.
Sample Program:
<html>
<head>
<title> HTML p align Attribute </title>
</head>
<body>
<h1>
<p> <!—Without Justify attribute-->
HTML (HyperText Markup Language) is the code that is used to structure a web page
and its content. For example, content could be structured within a set of paragraphs, a list
of bulleted points, or using images and data tables.
</p>
<p align="justify"> > <!—With Justify attribute-->
HTML (HyperText Markup Language) is the code that is used to structure a web page
and its content. For example, content could be structured within a set of paragraphs, a list
of bulleted points, or using images and data tables.
</p>
</h1>
<h2>
HTML p align Attribute
</h2>
<p align="left">
Left align content
</p>
<p align="center">
center align content
</p>
<p align="right">
Right align content
</p>
</body>
</html>
Note: Notice the difference in layout of text with and without justify attribute with <p> tag.
Output:
Sample Program:
<html>
<body>
<p>
There is a horizontal rule below this paragraph.
</p>
<!--HTML hr tag is used here-->
<hr>
<p>
This is a horizontal rule above this paragraph.
</p>
</body>
</html>
Output:
Sample Program:
<html>
<body>
<p>
Normal horizontal line.
</p>
<!--HTML hr tag is used here-->
<hr>
<p>
Horizontal line with height of 30 pixels
</p>
<hr size="30">
<p>
Horizontal line with height of 30 pixels, red color and
noshade.
</p>
<hr size="30" noshade color="red">
</body>
</html>
Output:
Sample Program:
<html>
<body>
<p>
Horizontal line with width of 100 pixels and size of 5 pixels.
</p>
<hr width="100" size="5">
<p>
Horizontal line with width 50% and size of 5 pixels.
</p>
<hr width="50%" size="5">
</body>
</html>
Output:
Note: width of line will be fixed when specified with pixels whereas it will be relative to browser
window size when specified in percentage.
type Any font available in the system To set the font style
color color name To set the text color
Sample Program:
<html>
<body>
<!--HTML font size tag starts here-->
<font size="1">HTML Programming!</font><br>
<font size="2">HTML Programming!</font><br>
<font size="3">HTML Programming!</font><br>
<font size="4">HTML Programming!</font><br>
<font size="5">HTML Programming!</font><br>
<font size="6">HTML Programming!</font><br>
<font size="7">HTML Programming!</font>
<!--HTML font size tag ends here-->
</body>
</html>
Output
Sample Program:
<html>
<body>
<font face="Times New Roman" size="6" color="red">
HTML Programming!!!
</font> <br>
<font face="Verdana" size="5" color="blue">
HTML Programming!!!
</font><br>
<font face="Comic sans MS" size=" 6" color="green">
HTML Programming!!!
</font><br>
</body>
</html>
Output:
1.9 Formatting Tags
There are two types of Tags:
• Physical Tags
• Logical Tags
Sample Program:
<html>
<head>
<title>Physical Tags</title>
</head>
<body>
<h1> Physical Tags </h1>
Text without any formatting <br>
<b> HTML- This is Bold text </b> <br>
<big> HTML- This is BIG text </big> <br>
<i> HTML- This is Italic text </i> <br>
<small> HTML- This is Small text </small> <br>
1<sup>st </sup> <br>
H<sub>2</sub>O <br>
<tt> HTML- This is teletype text </tt> <br>
<u> HTML- This is underlined text</u> <br>
<strike> HTML- This is striked text</strike> <br>
</body>
</html>
Output:
Sample Program:
<html>
<head>
<title>Logical Tags</title>
<body>
<h1>Logical Tags</h1>
<!-- abbr tag -->
Welcome to <abbr title="Hyper Text Markup Language"> HTML </abbr> Programming
<br>
Output:
2. Lists
HTML offers three ways for specifying lists: ordered lists, unordered lists, and description lists. Ordered lists
use ordinal sequences to indicate the order of list elements, unordered lists use a defined symbol such as a
bullet to list elements in no designated order, and description lists use indents to list elements with their
children.
Note: A list item (<li>) can contain a new list, and other HTML elements, like images and links etc.
Attributes
Sample Program
<html>
<head>
<title> Ordered List</title>
</head>
<body>
<ol>
<li>Item
<li>Another Item
<li>Yet Another Item
</ol>
</body>
</html>
Output
Sample Program
<html>
<head>
<title> Ordered List</title>
</head>
<body>
<ol start="5">
<li>Item
<li>Some Other Item
<li value="4">A Reset Item
<li>Another Item
<li>Yet Another Item
</ol>
</body>
</html>
Output
Sample Program
<html>
<head>
<title> Ordered List</title>
</head>
<body>
<ol reversed type="I">
<li>Item
<li>Some Other Item
<li>A Reset Item
<li>Another Item
</ol>
</body>
</html>
Output
Types of Bullets:
Value Description
Sample Program
<html>
<head></head>
<body>
<ul>
<li>Item</li>
<li>Another Item</li>
<li>Yet Another Item</li>
</ul>
</body>
</html>
Output
Sample Program
<html>
<head></head>
<body>
<ul type="square">
<li>Item</li>
<li>Another Item</li>
<li>Yet Another Item</li>
</ul>
</body>
</html>
Output
2.3 Nested List
Lists can be nested to represent sub-items of a list item. Unordered lists can be nested under ordered lists
and vice versa. Lists can be nested up to any level. Nested lists are displayed indented to the parent lists.
Sample Program
<html>
<head></head>
<body>
<ul>
<li>item 1
<li>item 2
<ul>
<li>sub-item 2.1
<li>sub-item 2.2
</ul>
<li>item 3</li>
</ul>
</body>
</html>
Output
Sample Program
<html>
<head></head>
<body>
<ol>
<li>Hello, list!
<ul>
<li>Hello, nested list!
</ul>
</ol>
</body>
</html>
Output
2.4 Description List
A description list or definition list can be created with the dl element. It consists of name-value groups,
where the name is given in the dt element and the value is given in the dd element. This list is used to
prepare glossary like list generally given at the end of the text books.
Sample Program
<html>
<head></head>
<body>
<dl>
<dt>W3C</dt>
<dd>The World Wide Web Consortium was created in 1994 to develop standards and
protocols for the World Wide Web.</dd>
<dt>HTML</dt>
<dd>Hypertext Markup Language is the authoring language used to create documents
for the eorld wide web.</dd>
</dl>
</body>
</html>
Output
3. Images
Images can improve the design and the appearance of a web page. In earlier times, the web pages only
contain textual contents, which made them appear quite boring and uninteresting. Fortunately, it wasn’t
long enough that the ability to embed images on web pages was added for users.
<img> tag is used to display image on the web page. It is an empty tag that contains attributes only.
Attributes
There are two ways to specify the value in src attribute of img tag:
Sample Program
<html>
<head></head>
<body>
<img src="b2b.jpg"
alt="typeofecommerce" height="200"
width="200" border=”5”>
</body>
</html>
Output
Output
Effective use of alt attribute, when image cannot be displayed on browser.
To insert an image in the web, that image must be present in the same
folder (relative addressing) where the HTML file is stored. But if in some cases image is available in some
other directory then one can access the image like this:
Sample Program
<html>
<head></head>
<body>
<img src="b2b.jpg"
alt="typeofecommerce" height="200"
width="200" border="5"
align="middle">Business to Business
type of commerce
</body>
</html>
Output
if you want to open the link to another page/tab, target attribute can be used:
<a href = ”next.html” target = ”_blank”> Click for Next Page </a>
Try the above code yourself. You can use any webpage stored in the same folder as your current webpage.
Above examples are for linking two webpages. To create links within a webpage use name attribute. You
need to give name to anchor element where ever you want your cursor/web page to scroll after clicking on
the link. E.g. to insert link in a webpage so that whenever you click on it, web page scrolls to the top of the
page. At the top of the page, after the <body> tag, type the following code:
Now, anywhere in the webpage or at the bottom of the webpage, type the following code:
3.2 Imagemaps
An image maps is an image with clickable areas that usually act as hyperlinks.
The image is defined by the <img> tag, and the map is defined by a <map> tag with <area> tags to denote
each clickable area. Use the usemap and name attributes to bind the image and the map.
Tag/Attribute Description
<img> Below are the image map-specific attributes to use with <img>. Regular <img>
attributes apply.
usemap The name of the map with a hash symbol prepended to it. E.g., for a map with
name=”map”, the image should have usemap=”#map”
<map>
Name The name of the map to identify it. To be used with the image’s usemap attribute.
<area> Below are the area specific attributes. When href is specified, making the <area>
a link, <area> also supports all of the attributes of the anchor tag <a>.
coords The coordinates outlining the selectable area. When shape = “polygon”, this
should be set to a list of “x,y” pairs separated by commas (i.e., shape=”polygon”
coords=”x1, y1, x2, y2, x3, y3, ….”). when shape =”rectangle”, this should be set
to left top and right bottom. When shape=”circle”, this should be set to center X,
Y and radius.
href The URL of the hyperlink, if specified. If it is omitted, then the <area> will not
represent a hyperlink.
shape The shape of the <area>. Can be set to default to select the entire image (no
coords attribute necessary), circle or circ for a circle, rectangle or rect for a
rectangle and a polygon or poly for a polygonal area specified by corner points.
Note: Microsoft paint can be used to find out the coordinates of the clickable shape used in the image.
Consider the above image, we will create the imagemaps for computer, phone and cup of coffee. Here is
the code:
Sample Program
<html>
<head></head>
<body>
<img src=”workplace.jpg” alt=”Workplace” usemap=”#workmap”>
<map name=”workmap”>
<area shape=”rect” cooords=”34,44,270,350” href=”computer.html”>
<area shape=”rect” coords=”290,172,333,250” href=”phone.html”>
<area shape=”circle” coords=”337,3000,44” href=”coffee.html”>
</map>
</body>
<html>
Before trying the code make sure to create files with the name computer.html, phone.html and coffee.html.
4. Table Tag
<table> tag is used to display data in tabular form (row * column). There can be many columns in a row.
In each table, table row is defined by <tr> tag, table header is defined by <th>, and table data is defined by
<td> tags.
Tag/Attribute Description
<table> It defines a table.
<tr> It defines a row in a table.
<th> It defines a header cell in a table, bold and centre aligned
<td> It defines a cell in a table.
<caption> It defines the table caption.
border It is used with <table> tag to specify border width.
height To increase the height of the table. By default table height is as per total
number of rows in the table.
width To increase the height of the table. By default table width is as per the
content in the cell in the table.
align “left|right|center”
Can be used with <table> or <tr> or <th> or <td> for alignment of table
and text in row or any cell.
valign “top|middle|bottom”
Can be used with <tr>, <th>, <td>
Can be used with <tr> or <th> or <td> for alignment of text in row or any
cell.
frame • void: It is used to hide the outside border.
• above: It is used to display the top outside border.
• below: It is used to display the bottom outside border.
• hsides: It is used to display the top and bottom outside border.
• vsides: It is used to display the left and right outside border.
• lhs: It is used to display the left outside border.
• rhs: It is used to display the right outside border.
• box: It is used to display all sides outside border.
rules • none: It does not create any lines.
• rows: It creates line between the rows.
• cols: It creates line between the columns.
• all: It creates line between the rows and columns.
cellpadding It is used to specify the space between the cell content and cell wall. The
cellpadding attribute is set in terms of pixels. By default, the padding is
set to 0.
cellspacing It is used to specify the space between the cells. The cellspacing attribute
is set in terms of pixels. By default, the spacing is set to 1 pixel.
rowspan It allows you to merge or combine adjacent table cells vertically, creating
a single, longer cell that spans across multiple rows.
colspan It allows you to merge or combine adjacent table cells horizontally,
creating a single, wider cell that spans across multiple columns.
background To set any image as the background for the table, row or cell when used
with <table>, <tr> or <th> | <td> respectively.
bgcolor To change the background colour for the table, row or cell when used
with <table>, <tr> or <th> | <td> respectively.
Sample Program
<html>
<head></head>
<body>
<table border="5">
<tr>
<td></td>
<th>Column Heading 1</th>
<th>Column Heading 2</th>
</tr>
<tr>
<th>Row Heading 1</th>
<td>content11</td>
<td>content12</td>
</tr>
<tr>
<th>Row Heading 2</th>
<td>content21</td>
<td>content22</td>
</tr>
</table>
</body>
</html>
Output
Sample Program
Output
Sample Program
Output
Sample Program
<html> Output
<head></head>
<body>
<table border="5" cellpadding="9"
cellspacing="7">
<tr>
<td colspan="3" align="center">TOP</td>
</tr>
<tr align="center">
<td rowspan="2">WAY LEFT</td>
<td>MIDDLE UP</td>
<td rowspan="2">WAY RIGHT</td>
</tr>
<tr align="center">
<td>MIDDLE DOWN</td>
</tr>
<tr>
<td colspan="3"
align="center">BOTTOM</td>
</tr>
</table>
</body>
</html>
Sample Program
<html> Output
<head></head>
<body>
<table border="5" cellpadding="9"
cellspacing="7">
<tr>
<td>
<table border="3">
<tr><td>Rubber</td><td>Baby</td></tr>
<tr><td>Buggy</td><td>Bumbers</td></tr>
</table>
</td>
<td>
<table border="3">
<tr><td>She</td><td>Sells</td></tr>
<tr><td>Sea</td><td>Shells</td></tr>
</table>
</td>
</tr>
</table>
</body>
</html>
5. Frameset Tag
This tag is used to define how to divide the browser. It specifies the number of rows and columns in the
frameset and how much space they will occupy. Each part is known as a frame. Each frame is indicated by
the frame tag and it basically defines which HTML document shall open into the frame. <body> tag is not
used with the <frameset> tag. It is a container tag.
Tag/Attribute Description
cols Used to create vertical frames in a web browser. Basically, used to define the
no. of columns and their size inside the tag.
rows Used to create horizontal frames in the web browser. Basically, used to
define the no. of rows and their size inside the tag.
border Defines the width of the border of each frame in pixels.
frameborder Specifies whether a 3-D border should be displayed between frames. This
attribute takes value either 1 (yes) or 0 (no). e.g., frameborder=”0” specifies
no border.
<frame> Defines which HTML document shall open into the frame. Below mentioned
attributes are used with the <frame> tag.
src It is used to give file name that should be loaded in the frame.
name It allows one to give a name to a frame. It is used to indicate which frame a
document should be loaded into. This is especially important when one
want to create links in one frame that load pages into an another frame, in
which case the second frame needs a name to identify itself as the target of
the link.
noresize By default one can resize any frame by clicking and dragging on the borders
of a frame. The noresize attribute prevents a user from being able to resize
the frame.
scrolling This attribute controls the appearance of the scrollbars that appear on the
frame. This takes values either “yes”, “no”. e.g., scrolling = “no” means it
should not have scroll bars.
For rows and cols attributes, values can be specified in the following ways:
• Absolute values in pixels. E.g., to create three vertical frames, use cols = “200, 400, 100”.
• A percentage of the browser window. E.g., to create three vertical frames, use cols = “20%, 60%,
20%”.
• Using wild card symbol. E.g. to create three vertical frame, use cols = “20%, 50%, *”. In this case
wildcard ‘*’ takes remainder of the window. It can be used with the pixels too.
For equal number of rows and columns in the browser, use both the rows and cols attribute in the tag.
E.g., <frameset cols=”50%, 50%” rows=”50%, 50%”> will divide the browser window into four equal parts.
Sample Program
<html>
<head>
<title> Learning Frameset tag</title>
</head>
<frameset cols="33%, 33%, *">
<frame src="prg8 list1.html">
<frame src="prg12 images 1.html">
<frame src="prg8 list2.html">
</frameset>
</html>
Output
Note: Web Browser window is divided into three vertical parts with three different web pages displayed in
each part.
Sample Program
Main Program
<html>
<head>
<title></title>
</head>
<body>
<h1> Links displayed on the left pane will be displayed in this pane
when clicked because of name attribute in frame tag and tartget
attribute in a tag.</h2>
</body>
</html>
Output
6. Form Tag
An HTML Form is a section of a document which contains controls such as text fields, password fields,
checkboxes, submit buttons etc. it 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. Integrating forms in the content
enhances user engagement, boosts interactivity, and the site more attractive.
Syntax:
</form>
Tag/Attribute Description
<input> It defines an input control.
<textarea> It defines a multi-line input control.
<label> It defines a label for an input element.
<fieldset> It groups the related element in a form.
<legend> It defines a caption for a <fieldset> element.
<select> It defines a drop-down list.
<option> It defines an option in a drop-down list.
<button> It defines a clickable button.
action The action attribute (used with <form>) defines the action to be performed when
the form is submitted, which usually leads to a script that collects the
information submitted and works with it. If left blank, it will send it to the same
file.
method The method attribute (used with <form>) is used to define the HTTP method of
the form which is either GET or POST.
The GET method is mostly used to get data, for example to receive a post by its
ID or name, or to submit a search query. The GET method will append the form
data to the URL specified in the action attribute.
The POST method is used when submitting data to a script. The POST method
does not append the form data to the action URL but sends using the request
body.
name Specifies the name of the form element. When submitting the form and sending
it to the server, the server needs to distinguish and differentiate between the
different kinds of submitted data it gathers. So, to submit the data from the form
correctly, a name attribute name must be specified. All the form elements must
have unique names.
e.g.: <input type “text” name=”fname”>
type Used to set the type of the input field or form element. Possible values are:
text|password|radio|checkbox|submit|reset
value It specifies the value of an form element or <input> element. It is used differently
for different input types:
• For “reset” and “submit” – it defines the text on the button.
• For “text” and “password” – it defines the initial (default) value of the input
field.
• For “checkbox” and “radio” – it defines the value associated with the input
(this is also the value that is sent on submit).
Attribute Description
size This attribute specifies the visible width, in characters. Can be used with
password also. Default value is 20.
maxlength This attribute specify the maximum number of characters allowed in the text or
password. Default value is 524288. With maxlength=0, element will not accept
any input.
Sample Program
Output
<html>
<head>
<title>Form TextBox</title>
</head>
<body bgcolor = "#ffa8d3">
<form method="post" action="">
<font color="blue" size=5>
<b><label>Name : <input type="text" name="nm1" value="sarita"></label> No restriction
on size and maxlength<br><br>
<label>Age : <input type="text" name="ag" size=2 maxlength=2></label> size=2 and
maxlength=2<br><br>
<label>City : <input type="text" name="city" size=15 maxlength=6></label> size=15 and
maxlength=6<br><br>
<label>Mail : <input type="text" name="e-m" size=20 maxlength=25></label> size=20 and
maxlength=25<br><br>
<label>Mob : <input type="text" name="mob" size=15 maxlength=20 value="+91"></label>
size=15 and maxlength=20<br><br>
<label>Text : <input type="text" name="nochar" size="5" maxlength=0></label> size=5 and
maxlength=0<br><br>
</b></font>
</form>
</body>
</html>
6.1.2 Password
The <input type = ”password”> is used to specify the password field of the input tag. Here password iput
field where characters are masked, enhances security by hiding sensitive information like passwords from
plain view.
All the attributes used with textbox are also supported by password input element.
6.1.3 Radio Buttons
Radio buttons are a type of input element used in HTML forms. They allow users to select one option from
a group of choices. This is particularly useful in situations where one need the user to make a single
selection, such as choosing a shipping method, selecting a payment option, or picking a preferred language.
Radio button is shown as the round box.
To create a radio button in HTML, one need to use the <input> tag with the type attribute set to “radio”.
The name attribute is used to group radio buttons together, ensuring that only one option can be selected
at a time. The value attribute represents the value that will be submitted if the radio button is selected.
Sample Program
Output
<html>
<head>
<title>Form Radio Button</title>
</head>
<body>
<form method="post" action="">
<fieldset>
<legend>Gender</legend>
<b>
<label><input type="radio" name="gender"
value="male"> Male </label><br>
<label><input type="radio" name="gender"
value="female" checked> Female
</label><br> Note: Because of <fieldset> tag, box is appearing
<label><input type="radio" name="gender" around the options and Gender over the box is
value="other"> Other </label><br> displayed because of <legend> tag. By default, female is
</b> choosen because of checked attribute in <input> tag.
</fieldset>
</form> 6.1.4 Checkbox
</body> The checkbox is used to select one or more options from
</html> a variety of options. It is a multi-control unit that will be
presented as a small square box on the screen. Checkbox is similar to radio buttons except for the name
attribute. Here, one need to give different name for each choice/option.
<html>
<head>
<title>Form Check box</title>
</head>
<body>
<form method="post" action="">
<fieldset>
<legend>Choose your favourite dishes:</legend>
<b>
<label><input type="checkbox" name="dish1"
value="Rajma Chawal" checked> Rajma Chawal
</label><br>
<label><input type="checkbox" name="dish2"
value="Shahi Paneer" > Shahi Paneer </label><br>
6.1.5 List
The <select> element is used to create a drop-down list. It is most often used in a form, to collect user input.
The name attribute is needed to reference the form data after the form is submitted (if the name attribute,
no data from the drop-down list will be submitted).
The <option> tags inside the <select> element define the available options in the drop-down list.
Attribute Description
Required Specifies that the user is required to select a value before submitting
the form.
Size Defines the number of visible options in a drop-down list.
Sample Program
<form> Output
<font color="brown" size=4>Choose one
model:
</font>
<select name="car">
<option value="honda">Honda</option>
<option value="hyundai">Hyundai</option>
<option value="maruti">Maruti</option>
<option value="Kia">Kia</option>
<option value="tata">Tata</option>
<option
value="mahindra">Mahindra</option>
<option value="toyota">Toyota</option>
</select>
<br><br>
<font color="brown" size=4>Choose one
colour:
</font>
<select name="color" size="3">
<option>White</option>
<option>SilverGreen</option>
<option>Black</option>
<option>Red</option>
<option>Blue</option>
<option>Yellow</option>
</select>
</form>
Sample Program
<html> Output
<head>
<title>Form Text Area</title>
</head>
<body bgcolor = "#4ae371">
<center><font color="red" size=7
face="monotype corsiva"><u><b>
Text Area
</font></u></b>
<form>
<textarea name="tab" rows=8 cols=40>
Text written between the start and end of text
area tag.</textarea>
</form>
</center>
</body>
</html>
Output
7. Audio Tag
The <audio> tag is an inline element that is used to embed sound files into a web page. The <audio> tag
contains one or more <source> tags with different audio sources. The browser will choose the first source
it supports. There are three supported audio formats in HTML: MP3, WAV and OGG.
Attribute Description
autoplay Specifies that the audio will start playing as soon as it is ready.
controls Specifies that audio controls should be displayed (such as play/pause button
etc)
loop Specifies that the audio will start over again, every time it is finished
muted Specifies that the audio output should be muted
src Specifies the URL of the audio file
Sample Program Output
8. Video Tag
The <video> tag is used to embed video content in a
document, such as movie clip or other video
streams. It contains one or more <source> tags with
different video sources. The browser will choose the
first source it supports. Supported video formats in HTML are MP4, WebM and OGG.
Attribute Description
autoplay Specifies that the video will start playing as soon as it is ready.
controls Specifies that video controls should be displayed (such as a play/pause button
etc.)
height Sets the height of the video player.
width Sets the width of the video player.
loop Specifies that the video will start over again, every time it is finished.
muted Specifies that the audio output of the video should be muted.
src Specifies the URL of the video file.
Sample Program Output
9. Iframe tag
Adding a video to a webpage was a real challenge since one had to convert the videos to different formats
to make them play in all browsers. Converting videos to different formats can be difficult and time-
consuming.
Adding a video to a webpage has become as easy as copying and pasting and a very apt solution to add
videos to a website is using Youtube. Youtube helps to host a video for a user so that they can be further
embedded on web pages.
youTube displays an id like “BGAk3_2zi8k”, whenever a video is saved orplayed. This id is further used as a
referral for the You Tube video to be embedded in the webpage.
1. What is HTML?
HTML stands for Hypertext Markup Language. It is used to design web pages using a markup
language. HTML is a combination of Hypertext and Markup language. Hypertext defines the link
between the web pages. The markup language is used to define the text document within the tag
which defines the structure of web pages. HTML is used to structure the website and is therefore
used for Web Development.
2. Difference between HTML and XHTML.
HTML stands for Hypertext Markup XHTML stands for Extensible Hypertext
1.
Language. Markup Language.
All tags and attributes are not In this, every tag and attribute should be in
6.
necessarily to be in lower or upper case. lower case.
Doctype is not necessary to write at the Doctype is very necessary to write at the top
7.
top. of the file.
It is not necessary to close the tags in the It is necessary to close the tags in the order
8.
order they are opened. they are opened.
The used filename extensions are .html, The used Filename extensions are .xhtml, .xht,
10.
.htm. .xml.
HTML HTML5
It didn’t support audio and video without the use It supports audio and video controls with
of Flash player support. the use of <audio> and <video> tags.
Not possible to draw shapes like circles, HTML5 allows drawing shapes like circles,
rectangles, triangles, etc. rectangles, triangles, etc.
Older versions of HTML are less mobile-friendly. HTML5 language is more mobile-friendly.
HTML HTML5
The doctype declaration is too long and The doctype declaration is quite simple and
complicated. easy.
Character encoding is long and complicated. Character encoding is simple and easy.
It is almost impossible to get the true Geolocation One can track the Geo Location of a user
of users with the help of the browser. easily by using JS Geolocation API.
Attributes like charset, async, and ping are absent Attributes of the charset, async, and ping
in HTML. are a part of HTML 5.
Either opening or closing is used to mark the start Collection of a start tag, end tag, and its
or end of an element. attributes.
<section id="home_section">
Information About Page
</section>
Example: When the user clicks on the “Contact Us” link, he will be redirected to the “Contact Us
section” on the same page.
HTML
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100%;
height: 400px;
border: 1px solid black;
}
</style>
</head>
<body>
<h2>Welcome to GeeksforGeeks</h2>
<p>
This is the example of
<i>
Redirect to a particular section
using HTML on same page
</i>
</p>
</html>
Output:
16. What is the use of the target attribute in the <link> tag?
The HTML <link> target Attribute is used to specify the window or a frame where the linked
document is loaded. It is not supported by HTML 5.
Syntax:
<link target="_blank|_self|_parent|_top|framename">
Attribute Values:
_blank: It opens the link in a new window.
_self: It opens the linked document in the same frame.
_parent: It opens the linked document in the parent frameset.
_top: It opens the linked document in the full body of the window.
framename: It opens the linked document in the named frame.