Class: XII Subject: Computer: Features of HTML
Class: XII Subject: Computer: Features of HTML
Subject: Computer
Chapter 1: HTML
The Hypertext Mark-up Language (or HTML) is the language used to create
documents for the World Wide Web.
Tim Berners lee a researcher of particle physics of Cern lab, Geneva gave the
concept of html in 1989.
Features of html
HTML is the most common used language to write web pages. It has recently
gained popularity due to its advantages such as: -
1- It is the language which can be easily understand and can be modified.
2- Effective presentations can be made with the HTML with the help of its all
formatting tags.
3- It provides the more flexible way to design web pages along with the text.
4- Links can also be added to the web pages so it helps the readers to browse
the information of their interest.
5- You can display HTML documents on any platforms such as Windows and
Linux etc.
6-Graphics, videos and sounds can also be added to the web pages which give
an extra attractive look to your web pages .
HTML stands for HyperText Markup Language, and it is the most widely
used language to write Web Pages.
Hypertext refers to the way in which Web pages (HTML documents) are
linked together. Thus, the link available on a webpage is called Hypertext.
As its name suggests, HTML is a Markup Language which means you use
HTML to simply "mark-up" a text document with tags that tell a Web browser
how to structure it to display.
HTML Tags
As told earlier, HTML is a markup language and makes use of various tags to format
the content. These tags are enclosed within angle braces <Tag Name>. Except few
tags, most of the tags have their corresponding closing tags. For
example, <html> has its closing tag </html> and <body> tag has its closing
tag </body> tag etc.
An HTML tag is commonly defined as a set of characters constituting a formatted
command for a Web page. At the core of HTML, tags provide the directions or recipes for
the visual content that one sees on the Webpage. Or we can say, HTML tags are the
hidden keywords within a web page that define how your web browser must format
and display the content.
The forward slash (/) on the closing tag tells the browser that the tag has ended.
On the other hand, the empty tags are stand alone. For ex. The tag <br> is
one that adds a line break. Empty tags do not have to be wrapped around text
and do not require a closing
HTML structure.
All HTML documents are divided into two main parts: the head and the body.
When you begin any new page, it must have a declaration: <!DOCTYPE
html>. It’s telling or declaring to the browser that the following file is an HTML
file.
To build any webpage you will need four primary tags: <html>, <head>, <title>
and <body>. These are all container tags and must appear as pairs with a
beginning and an ending.
1 <!DOCTYPE...>
2 <html>
This tag encloses the complete HTML document and mainly comprises of document header which
is represented by <head>...</head> and document body which is represented by
<body>...</body> tags.
3 <head>
This tag represents the document's header which can keep other HTML tags like <title>, <link> etc.
4 <title>
The <title> tag is used inside the <head> tag to mention the document title.
5 <body>
This tag represents the document's body which keeps other HTML tags like <h1>, <div>, <p> etc.
Heading Tags
Any document starts with a heading. We can use different sizes for your headings.
HTML also has six levels of headings, which use the elements <h1>, <h2>, <h3>,
<h4>, <h5>, and <h6>. While displaying any heading, browser adds one line before
and one line after that heading.
Example:
<html>
<head>
<title>Heading Example</title>
</head>
<body>
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
</body>
</html>
This is heading 1
This is heading 2
This is heading 3
This is heading 4
This is heading 5
This is heading 6
Paragraph Tag
The <p> tag offers a way to structure your text into different paragraphs. Each
paragraph of text should go in between an opening <p> and a closing </p> tag as
shown below in the example −
<html>
<head>
<title>Paragraph Example</title>
</head>
<body>
<p>Here is a first paragraph of text.</p>
<p>Here is a second paragraph of text.</p>
</body>
</html>
<head>
<title>Line Break Example</title>
</head>
<body>
<p>Hello<br>
You delivered your assignment ontime.<br>
Thanks<br>
</body>
</html>
Horizontal Lines
Horizontal lines are used to visually break-up sections of a document. The <hr> tag
creates a line from the current position in the document to the right margin and breaks
the line accordingly.
<hr> tag is an example of the empty element, where we do not need opening and
closing tags, as there is nothing to go in between them.
For example, you may want to give a line between two paragraphs as in the given
example below −
Example
<html>
<head>
<title>Horizontal Line Example</title>
</head>
<body>
<p>This is paragraph one and should be on top</p>
<hr />
<p>This is paragraph two and should be at bottom</p>
</body>
</html>
This will produce the following result −
Preserve Formatting
Sometimes, we want our text to follow the exact format of how it is written in the HTML
document. In these cases, we can use the preformatted tag <pre>.
Any text between the opening <pre> tag and the closing </pre> tag will preserve the
formatting of the source document.
Example
<html>
<head>
<title>Preserve Formatting Example</title>
</head>
<body>
<pre>
function testFunction( strText ){
alert (strText)
}
</pre>
</body>
</html>
<head>
<title>Align Attribute Example</title>
</head>
<body>
<p align = "left">This is left aligned</p>
<p align = "center">This is center aligned</p>
<p align = "right">This is right aligned</p>
</body>
</html>
This will display the following result –
Formatting tags
Bold Text
Anything that appears within <b>...</b> element, is displayed in bold as shown below
-
Example
<html>
<head>
<title>Bold Text Example</title>
</head>
<body>
<p>The following word uses a <b>bold</b> typeface.</p>
</body>
</html>
Italic Text
Anything that appears within <i>...</i> element is displayed in italicized as shown
below −
Example
<html>
<head>
<title>Italic Text Example</title>
</head>
<body>
<p>The following word uses an <i>italicized</i>
typeface.</p>
</body>
</html>
Underlined Text
Anything that appears within <u>...</u> element, is displayed with underline as
shown below −
Example
<html>
<head>
<title>Underlined Text Example</title>
</head>
<body>
<p>The following word uses an <u>underlined</u>
typeface.</p>
</body>
</html>
Strike Text
Anything that appears within <strike>...</strike> element is displayed with
strikethrough, which is a thin line through the text as shown below −
Example
<html>
<head>
<title>Strike Text Example</title>
</head>
<body>
<p>The following word uses a <strike>strikethrough</strike>
typeface.</p>
</body>
</html>
<html>
<head>
<title>Monospaced Font Example</title>
</head>
<body>
<p>The following word uses a <tt>monospaced</tt>
typeface.</p>
</body>
</html>
Superscript Text
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
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>Superscript Text Example</title>
</head>
<body>
<p>The following word uses a <sup>superscript</sup>
typeface.</p>
</body>
</html>
Subscript Text
The content of a <sub>...</sub> element is written in subscript; the font size used is
the same as the characters surrounding it, but is displayed half a character's height
beneath the other characters.
Example
<html>
<head>
<title>Subscript Text Example</title>
</head>
<body>
<p>The following word uses a <sub>subscript</sub>
typeface.</p>
</body>
</html>
Larger Text
The content of the <big>...</big> element is displayed one font size larger than the
rest of the text surrounding it as shown below −
Example
<html>
<head>
<title>Larger Text Example</title>
</head>
<body>
<p>The following word uses a <big>big</big> typeface.</p>
</body>
</html>
Smaller Text
The content of the <small>...</small> element is displayed one font size smaller
than the rest of the text surrounding it as shown below −
Example
<html>
<head>
<title>Smaller Text Example</title>
</head>
<body>
<p>The following word uses a <small>small</small>
typeface.</p>
</body>
</html>
This will produce the following result –
Grouping Content
The <div> tag allows us to group together several elements to create sections or
subsections of a page.
For example, we might want to put all of the footnotes on a page within a <div>
element to indicate that all of the elements within that <div> element relate to the
footnotes. You might then attach a style to this <div> element so that they appear
using a special set of style rules.
Example
<html>
<head>
<title>Div Tag Example</title>
</head>
<body>
<div align = "middle" >
<a href = "/index.htm">HOME</a> |
<a href = "/about/contact_us.htm">CONTACT</a> |
<a href = "/about/index.htm">ABOUT</a>
</div>
</html>
This will produce the following result –
Meta Tags
The <meta> tag is used to provide such additional information. This tag is an empty
element and so does not have a closing tag but it carries information within its
attributes.
We can include one or more meta tags in our document based on what information
we want to keep in our document but in general, meta tags do not impact physical
appearance of the document so from appearance point of view, it does not matter if
we include them or not.
We can add metadata to our web pages by placing <meta> tags inside the header of
the document which is represented by <head> and </head> tags. A meta tag can
have following attributes in addition to core attributes −
1
Name
Name for the property. Can be anything. Examples include, keywords, description, author, revised,
generator etc.
2
content
Specifies the property's value.
Specifying Keywords
You can use <meta> tag to specify important keywords related to the document and
later these keywords are used by the search engines while indexing your webpage
for searching purpose.
Example:
<meta name = "keywords" content = "HTML, Meta Tags, Metadata" />
Document Description
You can use <meta> tag to give a short description about the document. This again
can be used by various search engines while indexing your webpage for searching
purpose.
HTML - Comments
Comment is a piece of code which is ignored by any web browser. It is a good practice
to add comments into HTML code, especially in complex documents, to indicate
sections of a document, and any other notes to anyone looking at the code.
Comments help others to understand our code and increases code readability.
HTML comments are placed in between <!-- ... --> tags. So, any content placed with-
in <!-- ... --> tags will be treated as comment and will be completely ignored by the
browser.
Example
<!DOCTYPE html>
<html>
<body>
<p>Document content goes here.....</p>
</body>
</html>
This will produce the following result without displaying the content given as a part of
comments −
Document content goes here.....
HTML - Images
Images are very important to beautify as well as to depict many complex concepts in
simple way on your web page.
Insert Image
We can insert any image in our web page by using <img> tag. Following is the simple
syntax to use this tag.
<img src = "Image URL" ... attributes-list/>
The <img> tag is an empty tag, which means that, it can contain only list of attributes
and it has no closing tag.
Example
To try following example, let's keep our HTML file test.html and image file
htmlImage.png in the same directory −
<html>
<head>
<title>Using Image in Webpage</title>
</head>
<body>
<p>Simple Image Insert</p>
<img src = "/html/htmlImage.png" alt = "Test Image" />
</body>
</html>
We can use PNG, JPEG or GIF image file based on our comfort but make sure to
specify correct image file name in src attribute. Image name is always case sensitive.
The alt attribute is a mandatory attribute which specifies an alternate text for an
image, if the image cannot be displayed.
<html>
<head>
<title>Set Image Width and Height</title>
</head>
<body>
<p>Setting image width and height</p>
<img src = "/html/htmlImage.png" alt = "Test Image" width =
"150" height = "100"/>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Set Image Border</title>
</head>
<body>
<p>Setting image Border</p>
<img src = "/html/images/test.png" alt = "Test Image"
border = "3"/>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Set Image Alignment</title>
</head>
<body>
<p>Setting image Alignment</p>
<img src = "/html/images/test.png" alt = "Test Image"
border = "3" align = "right"/>
</body>
</html>
HTML - Lists
HTML offers web authors three ways for specifying lists of information. All lists must
contain one or more list elements. Lists may contain −
• <ul> − An unordered list. This will list items using plain bullets.
• <ol> − An ordered list. This will use different schemes of numbers to list items.
• <dl> − A definition list. This arranges items in the same way as they are arranged in a
dictionary.
<head>
<title>HTML Unordered List</title>
</head>
<body>
<ul>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ul>
</body>
</html>
• Beetroot
• Ginger
• Potato
• Radish
<html>
<head>
<title>HTML Unordered List</title>
</head>
<body>
<ul type = "square">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ul>
</body>
</html>
▪ Beetroot
▪ Ginger
▪ Potato
▪ Radish
Example
Following is an example where we used <ul type = "disc"> −
<html>
<head>
<title>HTML Unordered List</title>
</head>
<body>
<ul type = "disc">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ul>
</body>
</html>
• Beetroot
• Ginger
• Potato
• Radish
Example
Following is an example where we used <ul type = "circle"> −
<html>
<head>
<title>HTML Unordered List</title>
</head>
<body>
<ul type = "circle">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ul>
</body>
</html>
o Beetroot
o Ginger
o Potato
o Radish
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
1. Beetroot
2. Ginger
3. Potato
4. Radish
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type = "1">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
1. Beetroot
2. Ginger
3. Potato
4. Radish
Example
Following is an example where we used <ol type = "I">
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type = "I">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
I. Beetroot
II. Ginger
III. Potato
IV. Radish
Example
Following is an example where we used <ol type = "i">
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type = "i">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
i. Beetroot
ii. Ginger
iii. Potato
iv. Radish
Example
Following is an example where we used <ol type = "A" >
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type = "A">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
A. Beetroot
B. Ginger
C. Potato
D. Radish
Example
Following is an example where we used <ol type = "a">
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type = "a">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
a. Beetroot
b. Ginger
c. Potato
d. Radish
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type = "i" start = "4">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
iv. Beetroot
v. Ginger
vi. Potato
vii. Radish
<html>
<head>
<title>HTML Definition List</title>
</head>
<body>
<dl>
<dt><b>HTML</b></dt>
<dd>This stands for Hyper Text Markup Language</dd>
<dt><b>HTTP</b></dt>
<dd>This stands for Hyper Text Transfer Protocol</dd>
</dl>
</body>
</html>
Text Links
A webpage can contain various links that take us directly to other pages and even
specific parts of a given page. These links are known as hyperlinks.
Hyperlinks allow visitors to navigate between Web sites by clicking on words,
phrases, and images. Thus we can create hyperlinks using text or images available
on a webpage.
Linking Documents
A link is specified using HTML tag <a>. This tag is called anchor tag and anything
between the opening <a> tag and the closing </a> tag becomes part of the link and
a user can click that part to reach to the linked document. Following is the simple
syntax to use <a> tag.
<a href = "Document URL" ... attributes-list>Link Text</a>
Example
Let's try following example which links http://www.tutorialspoint.com at our page −
<html>
<head>
<title>Hyperlink Example</title>
</head>
<body>
<p>Click following link</p>
<a href = "https://www.tutorialspoint.com" target =
"_self">Tutorials Point</a>
</body>
</html>
This will produce the following result, where you can click on the link generated to
reach to the home page of Tutorials Point (in this example).
Tutorials Point
1
_blank
Opens the linked document in a new window or tab.
2
_self
Opens the linked document in the same frame.
3
_top
Opens the linked document in the full body of the window.
Linking to a Page Section
You can create a link to a particular section of a given webpage by
using name attribute. This is a two-step process.
First create a link to the place where you want to reach with-in a webpage and name
it using <a...> tag as follows −
<h1>HTML Text Links <a name = "top"></a></h1>
Second step is to create a hyperlink to link the document and place where you want
to reach −
<a href = "/html/html_text_links.htm#top">Go to the Top</a>
This will produce following link, where you can click on the link generated Go to the
Top to reach to the top of the HTML Text Link tutorial.
Go to the Top
<head>
<title>Hyperlink Example</title>
<base href = "https://www.tutorialspoint.com/">
</head>
</html>
This will produce the following result. Just check color of the link before clicking on it,
next check its color when you activate it and when the link has been visited.
Image Links
We have seen how to create hypertext link using text and we also learnt how to use
images in our webpages. Now, we will learn how to use images to create hyperlinks.
Example
It's simple to use an image as hyperlink. We just need to use an image inside
hyperlink at the place of text as shown below −
<!DOCTYPE html>
<html>
<head>
<title>Image Hyperlink Example</title>
</head>
<body>
<p>Click following link</p>
<a href = "https://www.tutorialspoint.com" target =
"_self">
<img src = "/images/logo.png" alt = "Tutorials Point"
border = "0"/>
</a>
</body>
</html>
HTML - Backgrounds
By default, your webpage background is white in color. You may not like it, but no
worries. HTML provides you following two good ways to decorate your webpage
background.
<html>
<head>
<title>HTML Background Colors</title>
</head>
</body>
</html>
<head>
<title>HTML Background Images</title>
</head>
</body>
</html>
HTML - Colors
Colors are very important to give a good look and feel to your website. You can
specify colors on page level using <body> tag or you can set colors for individual tags
using bgcolor attribute.
The <body> tag has following attributes which can be used to set different colors −
• bgcolor − sets a color for the background of the page.
• text − sets a color for the body text.
• alink − sets a color for active links or selected links.
• link − sets a color for linked text.
• vlink − sets a color for visited links − that is, for linked text that you have already clicked
on.
#000000
#FF0000
#00FF00
#0000FF
#FFFF00
#00FFFF
#FF00FF
#C0C0C0
#FFFFFF
rgb(0,0,0)
rgb(255,0,0)
rgb(0,255,0)
rgb(0,0,255)
rgb(255,255,0)
rgb(0,255,255)
rgb(255,0,255)
rgb(192,192,192)
rgb(255,255,255)
HTML - Fonts
Fonts play a very important role in making a website more user friendly and increasing
content readability. Font face and color depends entirely on the computer and
browser that is being used to view your page but you can use HTML <font> tag to
add style, size, and color to the text on your website. You can use a <basefont> tag
to set all of your text to the same size, face, and color.
The font tag is having three attributes called size, color, and face to customize your
fonts. To change any of the font attributes at any time within your webpage, simply
use the <font> tag. The text that follows will remain changed until you close with the
</font> tag. You can change one or all of the font attributes within one <font> tag.
Note −The font and basefont tags are deprecated and it is supposed to be removed in a future
version of HTML. So they should not be used rather, it's suggested to use CSS styles to
manipulate your fonts. But still for learning purpose, this chapter will explain font and basefont
tags in detail.
<html>
<head>
<title>Setting Font Size</title>
</head>
<body>
<font size = "1">Font size = "1"</font><br />
<font size = "2">Font size = "2"</font><br />
<font size = "3">Font size = "3"</font><br />
<font size = "4">Font size = "4"</font><br />
<font size = "5">Font size = "5"</font><br />
<font size = "6">Font size = "6"</font><br />
<font size = "7">Font size = "7"</font>
</body>
</html>
<html>
<head>
<title>Font Face</title>
</head>
<body>
<font face = "Times New Roman" size = "5">Times New
Roman</font><br />
<font face = "Verdana" size = "5">Verdana</font><br />
<font face = "Comic sans MS" size =" 5">Comic Sans
MS</font><br />
<font face = "WildWest" size = "5">WildWest</font><br />
<font face = "Bedrock" size = "5">Bedrock</font><br />
</body>
</html>
Example
<html>
<head>
<title>Setting Font Color</title>
</head>
<body>
<font color = "#FF00FF">This text is in pink</font><br />
<font color = "red">This text is red</font>
</body>
</html>
<html>
<head>
<title>Setting Basefont Color</title>
</head>
<body>
<basefont face = "arial, verdana, sans-serif" size = "2"
color = "#ff0000">
<p>This is the page's default font.</p>
<h2>Example of the <basefont> Element</h2>
</html>
INTERNET
9.XML