Introduction to HTML Basics and Usage
Introduction to HTML Basics and Usage
What is website?
A website is a collection of many web pages, and web pages are digital files that
are written using HTML (HyperText Markup Language).
i) Static Website
ii) Dynamic Website
HTML stands for Hypertext Markup Language, and it is the most widely used
language to write Web Pages.
1
Introduction to HTML
HTML stands for Hyper Text Markup Language, which is the most widely used
language on Web to develop web pages. HTML was created by Tim Berners-Lee
in late 1991 but "HTML 2.0" was the first standard HTML specification which was
published in 1995. HTML 4.01 was a major version of HTML and it was published
in late 1999. Though HTML 4.01 version is widely used but currently we are having
HTML-5 version which is an extension to HTML 4.01, and this version was
published in 2012.
Originally, HTML was developed with the intent of defining the structure of
documents like headings, paragraphs, lists, and so forth to facilitate the sharing of
scientific information between researchers. Now, HTML is being widely used to
format web pages with the help of different tags available in HTML language.
2
Hello World using HTML.
<!DOCTYPE html>
<html>
<head>
<title>This is document title</title>
</head>
<body>
<h1>This is a heading</h1>
<p>Hello World!</p>
</body>
</html>
Applications of HTML
As mentioned before, HTML is one of the most widely used language over the web.
I'm going to list few of them here:
This HTML tutorial is designed for the aspiring Web Designers and Developers
with a need to understand the HTML in enough detail along with its simple
overview, and practical examples. This tutorial will give you enough ingredients to
start with HTML from where you can take yourself at higher level of expertise.
Prerequisites
Before proceeding with this tutorial you should have a basic working knowledge
with Windows or Linux operating system, additionally you must be familiar with −
● Experience with any text editor like notepad, notepad++, or Edit plus
etc.
● How to create directories and files on your computer.
● How to navigate through different directories.
● How to type content in a file and save them on a computer.
● Understanding about images in different formats like JPEG, PNG
format.
<!DOCTYPE html>
<html>
<head>
<title>This is document title</title>
</head>
4
<body>
<h1>This is a heading</h1>
<p>Document content goes here.....</p>
</body>
</html>
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.
1 <!DOCTYPE...>
2 <html>
5
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.
6 <h1>
7 <p>
To learn HTML, you will need to study various tags and understand how they
behave, while formatting a textual document. Learning HTML is simple as users
have to learn the usage of different tags in order to format the text or images to make
a beautiful webpage.
6
HTML Document Structure
<html>
<head>
Document header related tags
</head>
<body>
Document body related tags
</body>
</html>
We will study all the header and body tags in subsequent chapters, but for now let's
see what is document declaration tag.
The <!DOCTYPE> declaration tag is used by the web browser to understand the
version of the HTML used in the document. Current version of HTML is 5 and it
makes use of the following declaration −
<!DOCTYPE html>
There are many other declaration types which can be used in HTML document
depending on what version of HTML is being used. We will see more details on this
while discussing <!DOCTYPE...> tag along with other HTML tags.
7
HTML BASIC Tags
Heading Tags
Any document starts with a heading. You 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
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 −
Example
<!DOCTYPE html>
<html>
8
<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>
<p>Here is a third paragraph of text.</p>
</body>
</html>
Whenever you use the <br /> element, anything following it starts from the next
line. This tag is an example of an empty element, where you do not need opening
and closing tags, as there is nothing to go in between them.
The <br /> tag has a space between the characters br and the forward slash. If you
omit this space, older browsers will have trouble rendering the line break, while if
you miss the forward slash character and just use <br> it is not valid in XHTML.
Example
<!DOCTYPE html>
<html>
<head>
9
<title>Line Break Example</title>
</head>
<body>
<p>Hello<br />
You delivered your assignment ontime.<br />
Thanks<br />
Mahnaz</p>
</body>
</html>
Centering Content
You can use <center> tag to put any content in the center of the page or any table
cell.
Example
<!DOCTYPE html>
<html>
<head>
<title>Centring Content Example</title>
</head>
<body>
<p>This text is not in the center.</p>
10
<center>
<p>This text is in the center.</p>
</center>
</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.
For example, you may want to give a line between two paragraphs as in the given
example below −
Example
<!DOCTYPE html>
<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>
11
This will produce the following result –
Again <hr /> tag is an example of the empty element, where you do not need
opening and closing tags, as there is nothing to go in between them.
The <hr /> element has a space between the characters hr and the forward slash. If
you omit this space, older browsers will have trouble rendering the horizontal line,
while if you miss the forward slash character and just use <hr> it is not valid in
XHTML.
Preserve Formatting
Sometimes, you want your text to follow the exact format of how it is written in the
HTML document. In these cases, you 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
<!DOCTYPE html>
<html>
<head>
<title>Preserve Formatting Example</title>
</head>
<body>
<pre>
function testFunction( strText ){
alert (strText)
}
12
</pre>
</body>
</html>
Nonbreaking Spaces
Suppose you want to use the phrase "12 Angry Men." Here, you would not want a
browser to split the "12, Angry" and "Men" across two lines −
In cases, where you do not want the client browser to break text, you should use a
nonbreaking space entity instead of a normal space. For example, when
coding the "12 Angry Men" in a paragraph, you should use something similar to the
following code −
Example
<!DOCTYPE html>
<html>
<head>
<title>Nonbreaking Spaces Example</title>
</head>
<body>
<p>An example of this technique appears in the movie
"12 Angry Men."</p>
</body>
</html>
13
This will produce the following result −
HTML Elements
<br />
HTML documents consists of a tree of these elements and they specify how HTML
documents should be built, and what kind of content should be placed in what part
of an HTML document.
14
An HTML element is defined by a starting tag. If the element contains other content,
it ends with a closing tag.
For example, <p> is starting tag of a paragraph and </p> is closing tag of the same
paragraph but <p>This is paragraph</p> is a paragraph element.
It is very much allowed to keep one HTML element inside another HTML element
−
Example
<!DOCTYPE html>
<html>
<head>
<title>Nested Elements Example</title>
</head>
<body>
<h1>This is <i>italic</i> heading</h1>
<p>This is <u>underlined</u> paragraph</p>
</body>
</html>
HTML-Attributes
We have seen few HTML tags and their usage like heading tags <h1>,
<h2>, paragraph tag <p> and other tags. We used them so far in their simplest form,
15
but most of the HTML tags can also have attributes, which are extra bits of
information.
● The name is the property you want to set. For example, the
paragraph <p> element in the example carries an attribute whose name
is align, which you can use to indicate the alignment of paragraph on
the page.
● The value is what you want the value of the property to be set and
always put within quotations. The below example shows three possible
values of align attribute: left, center and right.
Attribute names and attribute values are case-insensitive. However, the World Wide
Web Consortium (W3C) recommends lowercase attributes/attribute values in their
HTML 4 recommendation.
Example
<!DOCTYPE html>
<html>
<head>
<title>Align Attribute Example</title>
</head>
<body>
<p align = "left">This is left aligned</p>
16
<p align = "center">This is center aligned</p>
<p align = "right">This is right aligned</p>
</body>
</html>
Core Attributes
The four core attributes that can be used on the majority of HTML elements
(although not all) are −
● Id
● Title
● Class
● Style
The Id Attribute
The id attribute of an HTML tag can be used to uniquely identify any element within
an HTML page. There are two primary reasons that you might want to use an id
attribute on an element −
We will discuss style sheet in separate tutorial. For now, let's use the id attribute to
distinguish between two paragraph elements as shown below.
Example
17
<p id = "html">This para explains what is HTML</p>
<p id = "css">This para explains what is Cascading Style Sheet</p>
The title attribute gives a suggested title for the element. They syntax for
the title attribute is similar as explained for id attribute −
The behavior of this attribute will depend upon the element that carries it, although
it is often displayed as a tooltip when cursor comes over the element or while the
element is loading.
Example
<!DOCTYPE html>
<html>
<head>
<title>The title Attribute Example</title>
</head>
<body>
<h3 title = "Hello HTML!">Titled Heading Tag Example</h3>
</body>
</html>
Now try to bring your cursor over "Titled Heading Tag Example" and you will see
that whatever title you used in your code is coming out as a tooltip of the cursor.
18
The class Attribute
The class attribute is used to associate an element with a style sheet, and specifies
the class of element. You will learn more about the use of the class attribute when
you will learn Cascading Style Sheet (CSS). So for now you can avoid it.
The value of the attribute may also be a space-separated list of class names. For
example −
The style attribute allows you to specify Cascading Style Sheet (CSS) rules within
the element.
<!DOCTYPE html>
<html>
<head>
<title>The style Attribute</title>
</head>
<body>
<p style = "font-family:arial; color:#FF0000;">Some text...</p>
</body>
</html>
19
Horizontal Line <hr>
20
The <del> and <s> Tags
The <del> tag specifies a part of the text that was deleted from the document.
[Link]
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<p>My favorite color is <del style="color:#8ebf42;">green</del> <ins
style="color:#1c87c9;"> blue</ins>!</p>
<p><s>I am studying in high school.</s></p>
<p>I am studying in an university.</p>
</body>
</html>
Output:
Superscript Text
The baseline passes through upper or lower edge of the symbols. (eg. x2, cm3)
21
Subscript Text
Subscript text is under the baseline of other symbols of the line and has smaller
font. (eg. H2O, CO2)
The <u> tag specifies text that is stylistically different from normal text, i.e. words
or fragments of text that need to be presented differently.
22
HTML-Images
Images are very important to beautify as well as to depict many complex concepts
in simple way on your web page. This tutorial will take you through simple steps to
use images in your web pages.
Insert Image
You can insert any image in your 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 [Link] and image file [Link]
in the same directory −
<!DOCTYPE html>
<html>
<head>
<title>Using Image in Webpage</title>
</head>
<body>
<p>Simple Image Insert</p>
<img src = "/html/images/[Link]" alt = "Test Image" />
</body>
</html>
This will produce the following result −
You can use PNG, JPEG or GIF image file based on your comfort but make sure
you specify correct image file name in src attribute. Image name is always case
sensitive.
23
The alt attribute is a mandatory attribute which specifies an alternate text for an
image, if the image cannot be displayed.
Usually we keep all the images in a separate directory. So let's keep HTML file
[Link] in our home directory and create a subdirectory images inside the home
directory where we will keep our image [Link].
Example
Assuming our image location is "image/[Link]", try the following example −
<!DOCTYPE html>
<html>
<head>
<title>Using Image in Webpage</title>
</head>
<body>
<p>Simple Image Insert</p>
<img src = "/html/images/[Link]" alt = "Test Image" />
</body>
</html>
This will produce the following result −
You can set image width and height based on your requirement
using width and height attributes. You can specify width and height of the image in
terms of either pixels or percentage of its actual size.
Example
<!DOCTYPE html>
<html>
<head>
24
<title>Set Image Width and Height</title>
</head>
<body>
<p>Setting image width and height</p>
<img src = "/html/images/[Link]" alt = "Test Image" width = "150" height =
"100"/>
</body>
</html>
This will produce the following result −
By default, image will have a border around it, you can specify border thickness in
terms of pixels using border attribute. A thickness of 0 means, no border around the
picture.
Example
<!DOCTYPE html>
<html>
<head>
<title>Set Image Border</title>
</head>
<body>
<p>Setting image Border</p>
<img src = "/html/images/[Link]" alt = "Test Image" border = "3"/>
</body>
</html>
This will produce the following result −
25
Set Image Alignment
By default, image will align at the left side of the page, but you can
use align attribute to set it in the center or right.
Example
<!DOCTYPE html>
<html>
<head>
<title>Set Image Alignment</title>
</head>
<body>
<p>Setting image Alignment</p>
<img src = "/html/images/[Link]" alt = "Test Image" border = "3" align =
"right"/>
</body>
</html>
This will produce the following result −
26
HTML-Tables
The HTML tables allow web authors to arrange data like text, images, links, other
tables, etc. into rows and columns of cells.
The HTML tables are created using the <table> tag in which the <tr> tag is used to
create table rows and <td> tag is used to create data cells. The elements under <td>
are regular and left aligned by default
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Tables</title>
</head>
<body>
<table border = "1">
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
</tr>
</table>
</body>
</html>
This will produce the following result −
Here, the border is an attribute of <table> tag and it is used to put a border across
all the cells. If you do not need a border, then you can use border = "0".
27
Table Heading
Table heading can be defined using <th> tag. This tag will be put to replace <td>
tag, which is used to represent actual data cell. Normally you will put your top row
as table heading as shown below, otherwise you can use <th> element in any row.
Headings, which are defined in <th> tag are centered and bold by default.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Header</title>
</head>
<body>
<table border = "1">
<tr>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>Ramesh Raman</td>
<td>5000</td>
</tr>
<tr>
<td>Shabbir Hussein</td>
<td>7000</td>
</tr>
</table>
</body>
</html>
This will produce the following result −
28
Cellpadding and Cellspacing Attributes
There are two attributes called cellpadding and cellspacing which you will use to
adjust the white space in your table cells. The cellspacing attribute defines space
between table cells, while cellpadding represents the distance between cell borders
and the content within a cell.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Cellpadding</title>
</head>
<body>
<table border = "1" cellpadding = "5" cellspacing = "5">
<tr>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>Ramesh Raman</td>
<td>5000</td>
</tr>
<tr>
<td>Shabbir Hussein</td>
<td>7000</td>
</tr>
</table>
</body>
</html>
This will produce the following result −
29
Colspan and Rowspan Attributes
You will use colspan attribute if you want to merge two or more columns into a
single column. Similar way you will use rowspan if you want to merge two or more
rows.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Colspan/Rowspan</title>
</head>
<body>
<table border = "1">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr>
<td rowspan = "2">Row 1 Cell 1</td>
<td>Row 1 Cell 2</td>
<td>Row 1 Cell 3</td>
</tr>
<tr>
<td>Row 2 Cell 2</td>
<td>Row 2 Cell 3</td>
</tr>
<tr>
<td colspan = "3">Row 3 Cell 1</td>
</tr>
</table>
</body>
</html>
This will produce the following result −
30
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.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Background</title>
</head>
<body>
<table border = "1" bordercolor = "green" bgcolor = "yellow">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr>
<td rowspan = "2">Row 1 Cell 1</td>
<td>Row 1 Cell 2</td>
<td>Row 1 Cell 3</td>
</tr>
<tr>
<td>Row 2 Cell 2</td>
<td>Row 2 Cell 3</td>
</tr>
<tr>
<td colspan = "3">Row 3 Cell 1</td>
</tr>
</table>
31
</body>
</html>
The result is your answer −
Here is an example of using background attribute. Here we will use an image
available in /images directory.
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Background</title>
</head>
<body>
<table border = "1" bordercolor = "green" background = "/images/[Link]">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr>
<td rowspan = "2">Row 1 Cell 1</td>
<td>Row 1 Cell 2</td><td>Row 1 Cell 3</td>
</tr>
<tr>
<td>Row 2 Cell 2</td>
<td>Row 2 Cell 3</td>
</tr>
<tr>
<td colspan = "3">Row 3 Cell 1</td>
</tr>
</table>
</body>
</html>
This will produce the following result.
32
Table Height and Width
You can set a table width and height using width and height attributes. You can
specify table width or height in terms of pixels or in terms of percentage of available
screen area.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Width/Height</title>
</head>
<body>
<table border = "1" width = "400" height = "150">
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
</tr>
</table>
</body>
</html>
This will produce the following result −
Table Caption
The caption tag will serve as a title or explanation for the table and it shows up at
the top of the table. This tag is deprecated in newer version of HTML/XHTML.
Example
<!DOCTYPE html>
<html>
<head>
33
<title>HTML Table Caption</title>
</head>
<body>
<table border = "1" width = "100%">
<caption>This is the caption</caption>
<tr>
<td>row 1, column 1</td><td>row 1, columnn 2</td>
</tr>
<tr>
<td>row 2, column 1</td><td>row 2, columnn 2</td>
</tr>
</table>
</body>
</html>
This will produce the following result −
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 −
● <thead> − to create a separate table header.
● <tbody> − to indicate the main body of the table.
● <tfoot> − to create a separate table footer.
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>
Example
<!DOCTYPE html>
<html>
<head>
34
<title>HTML Table</title>
</head>
<body>
<table border = "1" width = "100%">
<thead>
<tr>
<td colspan = "4">This is the head of the table</td>
</tr>
</thead>
<tfoot>
<tr>
<td colspan = "4">This is the foot of the table</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</tbody>
</table>
</body>
</html>
This will produce the following result −
Nested Tables
You can use one table inside another table. Not only tables you can use almost all
the tags inside table data tag <td>.
Example
Following is the example of using another table and other tags inside a table cell.
35
<!DOCTYPE html>
<html>
<head>
<title>HTML Table</title>
</head>
<body>
<table border = "1" width = "100%">
<tr>
<td>
<table border = "1" width = "100%">
<tr>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>Ramesh Raman</td>
<td>5000</td>
</tr>
<tr>
<td>Shabbir Hussein</td>
<td>7000</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
This will produce the following result −
36
- With the div tag, you can group large sections of HTML elements together
and format them with CSS.
The <div> tag is used as a container for HTML elements - which is then styled
with CSS or manipulated with JavaScript.
It is possible to place any HTML element within a <div> tag, including another
<div>.
Note: By default, browsers always place a line break before and after
the <div> element.
For example:
<!DOCTYPE html>
<html>
<head>
<title>HTML div Tag</title>
</head>
<body>
<div style=” line-height: 20px;margin: 30px;padding-bottom: 20px;text-align:
justify;width: 140px;color: red;”>
<p>Welcome to our website. We provide tutorials on various subjects.</p>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>HTML div Tag</title>
37
</head>
<body>
<span style=” line-height: 20px;margin: 30px;padding-bottom: 20px;text-align:
justify;width: 140px;color: red;”>
<p>Welcome to our website. We provide tutorials on various subjects.</p>
</span>
</body>
</html>
The <span> tag is an inline container used to mark up a part of a text, or a part of
a document.
The <span> tag is easily styled by CSS or manipulated with JavaScript using the
class or id attribute.
The <span> tag is much like the <div> element, but <div> is used with a block-
level element and <span> is used with an inline element.
38
HTML Lists
HTML lists allow web developers to group a set of related items in lists.
All lists must contain one or more list elements.
i. Unordered Lists
ii. Ordered Lists
iii. Definition Lists/Description Lists
The list items will be marked with bullets (small black circles) by default.
For example:
<html>
<head>
<title></title>
</head>
<body>
<h2>Unordered Lists</h2>
<ul>
<li>Coffee</li>
<li>Tea</li>
39
<li>Milk</li>
</ul>
</body>
</html>
The type attribute for <ul> tag is used to define the style of the list item marker.
Value Description
For example:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h2>Unordered Lists With Type</h2>
<ul type="disc">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<ul type="circle">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
40
</ul>
<ul type="square">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<ul type="none">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>
Ordered HTML List <ol>
41
Ordered HTML List - The Type Attribute
The type attribute of the <ol> tag can be used to define the type of the list item
marker.
Type Description
type=”I” The list items will be numbered with uppercase roman numbers
type=”i” The list items will be numbered with lowercase roman numbers
For example:
<!DOCTYPE html>
<html>
<head>
<title>Ordered Lists</title>
</head>
<body>
<h2>Ordered Lists With Type</h2>
<ol type="1">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<ol type="A">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<ol type="a">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
42
<ol type="I">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<ol type="i">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
43
HTML Definition Lists
For example:
<!DOCTYPE html>
<html>
<head>
<title>Definition Lists</title>
</head>
<body>
<h2>Definition (or) Description Lists</h2>
<dl>
<dt>Coffee</dt>
<dd>_black hot drink.</dd>
<dt>Milk</dt>
<dd>_cold white drink.</dd>
</dl>
</body>
</html>
44
Linking Documents
The most important attribute of the <a> element is the href attribute, which
indicates the link's destination.
The link text is the part that will be visible to the reader.
Clicking on the link text, will send the reader to the specified URL address.
<!DOCTYPE html>
<html>
<head>
<title>Anchor Tag Example</title>
</head>
<body>
<h2>Link Example</h2>
<a href="www.w3S[Link]
</body>
</html>
45
HTML Links - The target Attribute
By default, the linked page will be displayed in the current browser window. To
change this, you must specify another target for the link.
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
<base href = "[Link]
</head>
<body>
<p>Click any of the following links</p>
<a href = "/html/[Link]" target = "_blank">Opens in New</a> |
<a href = "/html/[Link]" target = "_self">Opens in Self</a> |
<a href = "/html/[Link]" target = "_parent">Opens in Parent</a> |
<a href = "/html/[Link]" target = "_top">Opens in Body</a>
</body>
</html>
46
HTML Forms
The HTML <form> element is used to create an HTML form for user input.
The HTML <form> element can contain one or more of the following form
elements:
• <input>
• <label>
• <select>
• <textarea>
• <button>
• <fieldset>
• <legend>
• <datalist>
• <output>
• <option>
• <optgroup>
47
Here are some of the type attribute:
Type Description
<input type="radio"> Displays a radio button (for selecting one of many choices)
<input type="reset"> Displays a reset button (reset all form values to their default
values)
<input type="email"> Displays input fields that should contain an e-mail address
48
Text Fields
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname">
</form>
Password Fields
<form>
<label for="username">Username:</label><br>
<input type="text" id="username" name="uname"><br>
<label for="pwd">Password:</label>
<input type="password" id="pwd" name="pwd">
</form>
Hidden Fields
<form>
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<input type="hidden" id="custId" name="custId" value="3487">
<input type="submit" value="Submit">
</form>
Radio Buttons
<form>
<input type="radio" id="html" name="fav_language" value="HTML">
<label for="html">HTML</label><br>
<input type="radio" id="css" name="fav_language" value="CSS" checked>
<label for="css">CSS</label><br>
<input type="radio" id="javascript" name="fav_language" value="JavaScr
ipt">
<label for="javascript">JavaScript</label>
</form>
Checkboxes
<form>
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
49
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label>
</form>
Email Fields
<form>
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email">
</form>
Number Fields
<form>
<label for="quantity">Quantity (between 1 and 5):</label>
<input type="number" id="quantity" name="quantity" min="1" max="5">
</form>
Date Fields
<form>
<label for="birthday">Birthday:</label>
<input type="date" id="birthday" name="birthday">
</form>
File Upload
<form>
<label for="myfile">Select a file:</label>
50
<input type="file" id="myfile" name="myfile">
</form>
HTML Video
The HTML <video> element is used to show a video on a web page.
The controls attribute adds video controls, like play, pause, and volume.
51
The <source> element allows you to specify alternative video files which the
browser may choose from. The browser will use the first recognized format.
To start a video automatically, use the autoplay attribute.
HTML Audio
The HTML <audio> element is used to play an audio file on a web page.
52