HTML PRACTICAL New
HTML PRACTICAL New
HTML Headings
These tags help us to give headings to the content of a webpage. These tags are mainly written inside
the body tag. HTML provides us with six heading tags from <h1> to <h6>. Every tag displays the heading
in a different style and font size.
Source Code
<html>
<head>
</head>
<body>
</body>
</html>
Output
Program 2
HTML Paragraph
These tags help us to write paragraph statements in a webpage. They start with the <p> tag and ends
with <p>. Here the <br> tag is used to break line and acts as a carriage return. <br> is an empty tag.
Source Code
<html>
<head>
<title>Line Break Example</title>
</head>
<body>
<p>Hello<br />
Thanks<br />
Mahnaz</p>
</body>
</html>
Output
Hello
You delivered your assignment on time.
Thanks
Mahnaz
Program 3
HTML Horizontal Lines
The <hr> tag is used to break the page into various parts, creating horizontal margins with help of a
horizontal line running from left to right hand side of the page.
This is also an empty tag and doesn’t take any additional statements.
Source Code
<html>
<head>
</head>
<body>
<hr/>
</body>
</html>
Output
Source Code
Bold Text
Anything that appears within <b>...</b> element, is displayed in bold as shown below .
<html>
<head>
</head>
<body>
</body>
</html>
Anything that appears within <i>...</i> element is displayed in italicized as shown below −
Example
<html>
<head>
</head>
<body>
</body>
</html>
(iii)
Underlined Text
Anything that appears within <u>...</u> element, is displayed with underline as shown below
<html>
<head>
</head>
<body>
</body>
</html>
(iv)
Strike Text
Anything that appears within <strike>...</strike> element is displayed with strikethrough, which is a thin
line through the text as shown below −
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
(v)
Monospaced Font
The content of a <tt>...</tt> element is written in monospaced font. Most of the fonts are known as
variable-width fonts because different letters are of different widths (for example, the letter 'm' is wider
than the letter 'i'). In a monospaced font, however, each letter has the same width.
Example
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
This will produce the following result –
The content of a <sup>...</sup> element is written in superscript; the font size used is the same size as
the characters surrounding it but is displayed half a character's height above the other characters.
Example
<html>
<head>
</head>
<body>
</body>
</html>
<html>
<head>
</head>
<body>
</body>
</html>
Indicates that the text should be used with a font such as Courier that
<TT> </TT>
allots the same width to each character.
Logical Tags
Logical tags are used to indicate to the visually impaired that there is some emphasizes on the text. Each
browser has its own technique as to how to indicate to its viewer that the text between the tags are
different.
The syntax or format for using a LOGICAL TAG is as follows:
<Tag Name> Character/s to be formatted. </Tag Name>
Used to offset text that the user should enter. Often displayed in a
<KBD> Courier font or a similar font that allots the same width to each </KBD>
character.
Program 5
An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.
The list items will be marked with bullets (small black circles) by default:
You can use type attribute for <ul> tag to specify the type of bullet you like. By default, it is a disc.
Following are the possible options −
<html>
<head>
</head>
<body>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ul>
</body>
</html>
Output
Beetroot
Ginger
Potato
Radish
Program 6
Ordered List
<html>
<head>
</head>
<body>
<ol>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
Output
Beetroot
Ginger
Potato
Radish
You can use type attribute for <ol> tag to specify the type of numbering you like. By default, it is a
number. Following are the possible options −
You can use start attribute for <ol> tag to specify the starting point of numbering you need. Following
are the possible options −
<html>
<head>
</head>
<body>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
Output
Beetroot
Ginger
Potato
Radish
Program 7
HTML and XHTML supports a list style which is called definition lists where entries are listed like in a
dictionary or encyclopaedia. The definition list is the ideal way to present a glossary, list of terms, or
other name/value list.
<dt> − A term
<head>
</head>
<body>
<dl>
<dt><b>HTML</b></dt>
<dt><b>HTTP</b></dt>
</dl>
</body>
</html>
Output
HTML
HTTP
A list within another list is termed as nested list. If you want a bullet list inside a numbered list then such
type of list will called as nested list.
<html>
<head>
<title>Nested list</title>
</head>
<body>
<ol>
<li>Delhi
<ul>
<li>NewDelhi</li>
</ul>
</li>
<li>Haryana
<ul>
<li>Chandigarh</li>
</ul>
</li>
<li>Gujarat
<ul>
<li>Gandhinagar</li>
</ul>
</li>
<li>Rajasthan
<ul>
<li>Jaipur</li>
</ul>
</li>
<li>Maharashtra
<ul>
<li>Mumbai</li>
</ul>
</li>
<li>Uttarpradesh
<ul>
<li>Lucknow</li></ul>
</li>
</ol>
</body>
</html>
Output
Program 9
HTML – Tables
Simple Table
<html>
<head>
<title>HTML Tables</title>
</head>
<body>
<tr>
</tr>
<tr>
</tr>
</table>
</body>
</html>
Output
Table Heading
<html>
<head>
</head>
<body>
<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>
<html>
<head>
</head>
<body>
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>
<html>
<head>
</head>
<body>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
</table>
</body>
</html>
(v)
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.
You can also set border color also using bordercolor attribute.
Note −The bgcolor, background, and bordercolor attributes deprecated in HTML5. Do not use these
attributes.
<html>
<head>
</head>
<body>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
</table>
</body>
</html>
(vi)
<html>
<head>
</head>
<body>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
</table>
</body>
</html>
<html>
<head>
</head>
<body>
<tr>
</tr>
<tr>
</tr>
</table>
</body>
</html>
<html>
<head>
</head>
<body>
<tr>
</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 −
A table may contain several <tbody> elements to indicate different pages or groups of data.
But it is notable that <thead> and <tfoot> tags should appear before <tbody>
<html>
<head>
<title>HTML Table</title>
</head>
<body>
<tr>
</tr>
</thead>
<tfoot>
<tr>
</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>
Program 10
HTML Image
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.
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.
2) alt
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.
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
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.
Example 1
Example 2
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:
<head>
</head>
<body>
<img src = "myimage.jpeg" alt = "Test Image" border = "3" align = "right"/>
</body>
</html>
<html>
<head>
</head>
<body>
<img src = " F:\Data 6\myimage2.jpg " alt = "Test Image" border = "3" align = "right"/>
</body>
</html>
Program 11
Anything between the opening <a> tag and the closing </a> tag becomes the part of the link that the
user sees and clicks in a browser.
Syntax Explanation:
Examples
<a href="https://www.google.com/">
Google Search
</a>
<a href="https://www.apsvaranasi.org/">
APS Varanasi
</a>
<a href="images/kites.jpg">
</a>
An absolute URL is the URL that includes every part of the URL format, such as protocol, host name, and
path of the document, e.g., https://www.google.com/, https://www.example.com/form.php, etc.
While, relative URLs are page-relative paths, e.g., contact.html, images/smiley.png, and so on. A relative
URL never includes the http:// or https:// prefix.
The target attribute tells the browser where to open the linked document. There are four defined
targets, and each target name starts with an underscore(_) character:
_self — Opens the linked document in the same window or tab as the source document. This is the
default, hence it is not necessary to explicitly specify this value.
About Us
</a>
</a>
</a>
Program
<html>
<head>
<body>
<p>
<a href="myimage2.jpg">
</a>
</p>
</body>
</html>
Program 12
Description
The HTML <basefont> tag defines the default font-family, font-size and color for the text in the HTML
document.
Since this tag was removed in HTML5, it is recommended that you use CSS properties such as font, font-
family, font-size and color to format the text in the document
WARNING: The <basefont> tag has been removed in HTML5. Use CSS instead.
Syntax
In HTML, the syntax for the <basefont> tag is: (example that defines the base font as red, uses to the
font-family Verdana, Geneva, sans-serif and has a size of 12)
<head>
</head>
Attributes
Attribute Description
Color of text in either hexadecimal (ie: #RRGGBB format) or named color (ie: black, red,
color
white)
face Font to use for text. Listed as one or more font names (comma separated)
size Numeric values range from 1 to 7 (1 is the smallest, 7 is the largest, 3 is the default).
Relative values can be values such as +1 or -2, increasing by one font size or decreasing
by 2 font sizes, respectively.
Note
The <basefont> tag is obsolete in HTML5. Use CSS instead to format the text. The CSS equivalents would
be color, font, font-family, font-size, etc
Browser Compatibility
The <basefont> tag has basic support with the following browsers:
Edge
Edge Mobile
(i)
<!DOCTYPE html>
<html>
<head>
<title>Basefont tag</title>
</head>
<body>
<p>The basefornt tag is not supported in HTML5 use CSS to style the document</p>
</body>
</html>
(ii)
<html>
<head>
<style>
p{
font-size: 20px;
color: #67dfee;
font-family: Helvetica;
</style>
</head>
<body>
<p>This is Paragraph</p>
</body>
</html>
Program 13
The HTML <font> tag defines the font size, color and face of text in the HTML document.
Since this tag was removed in HTML5, it is recommended that you use CSS properties such as font, font-
family, font-size and color to format the text in the document.
Syntax
Display Inline
Note
The <font> tag is obsolete in HTML5. Use CSS instead to format the text. The CSS equivalents would
be color, font, font-family, font-size, etc.
Browser Compatibility
The <font> tag has basic support with the following browsers:
Chrome
Android
Firefox (Gecko)
Edge Mobile
Opera
Opera Mobile
Safari (WebKit)
Safari Mobile
Example
<html>
<head>
<title>Font Tag</title>
</head>
<body>
<p>
</p>
<p>
</p>
<p>
</p>
</body>
</html>
Using CSS
The same effect can be achieved using CSS properties as in below example:
<!DOCTYPE html>
<html>
<head>
<title>Font Tag</title>
</head>
<body>
<p style="font-size: 25px; color: green;">Text with Increased size and default face </p>
</body>
</html>