HTML Unit 3
HTML Unit 3
LISTS:
Lists are used to store data or information in web pages in ordered or
unordered form. HTML supports several types of list elements that can
be included in the <BODY>tag of the document. These elements may
also be nested, i.e., the onset of elements can be embedded within
another. There are three types of lists available in HTML:
• Unordered List
• Ordered List
• Description list
Now before moving to the list first of all, we understand what is a list
item tag.
List item tag is used to define each item of a list. Once we define list
items with the <li> tag, the list appears in Web browsers in the bulleted
form (by default). It is used inside both ordered and unordered lists.
Syntax:
<li> content </li>
Example
<html >
<head>
<title>inline style attribute</title>
</head>
<body>
<li>sachin</li>
<li>sujay</li>
<li>Amraditya</li>
<li>shivam</li>
<li>Parth</li>
</body>
</html>
Output:
Ordered list
An ordered list defines a list of items in which the order of the items are
matters. An ordered list is also called a number list. The ordering is
given by a numbering scheme, using Arabic numbers, letters, Roman
numerals. Or in other words, ordered list tag is used to create an
ordered list.
Different ways to number the ordered lists using the type attribute:
2. start: This attribute is used to specify the start value of the list.
Syntax:
<ol start = “number”>
3. type: This attribute is used to specify the type of list item maker. The
value of this attribute is decimal(Default)/lower-roman/upper
roman/lower-alpha/upper alpha
Syntax:
<ol type = “1|b|A|i|I”>
HTML Ordered Lists
HTML Ordered List is created by the HTML <ol> tag, to display
elements in an ordered form, either numerical or alphabetical. Each
item within the list is placed within a <li> tag, which stands for “list
item”.
The list is automatically numbered by the browser, but the style of
numbering can be adjusted using attributes and CSS.
Syntax:
<ol>
<li>...</li>
<li>...</li>
<li>...</li>
</ol>
Example – Creating a Basic Ordered List
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<ol>
<li>Prepare dinner</li>
</ol>
</body>
</html>
OUTPUT:
My To-Do List
1. Go grocery shopping
2. Pay utility bills
3. Prepare dinner
Type Descriptions
<html>
<head>
</head>
<body>
<ol>
<li>JavaScript</li>
<li>Python</li>
<li>Java</li>
<li>C++</li>
<li>C#</li>
</ol>
</body>
</html>
OUTPUT:
1. JavaScript
2. Python
3. Java
4. C++
5. C#
<html>
<head>
<title>
</title>
</head>
<body>
<ol type="A">
<li>Apple</li>
<li>Banana</li>
<li>Cherry</li>
<li>Date</li>
</ol>
</body>
</html>
OUTPUT:
A. Apple
B. Banana
C. Cherry
D. Date
<html>
<head>
<title>
</title>
</head>
<body>
<ol type="a">
<li>RCB</li>
<li>CSK</li>
<li>DC</li>
<li>MI</li>
</ol>
</body>
</html>
OUTPUT:
a. RCB
b. CSK
c. DC
d. MI
<html>
<head>
<title>
</title>
</head>
<body>
<h2>
</h2>
<ol type="I">
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Fourth item</li>
</ol>
</body>
</html>
OUTPUT:
I. First item
II. Second item
III. Third item
IV. Fourth item
<html>
<head>
<title>
</title>
</head>
<body>
<h2>
</h2>
<ol type="i">
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Fourth item</li>
</ol>
</body>
</html>
OUTPUT:
i. First item
ii. Second item
iii. Third item
iv. Fourth item
Reverse Ordered List in HTML
To create a reverse-ordered list in HTML, you can use the
‘reversed' attribute in the <ol> tag. This will make the list count down
from the highest number.
Example:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<ol reversed>
<li>The Godfather</li>
<li>Inception</li>
<li>Interstellar</li>
<li>Pulp Fiction</li>
</ol>
</body>
</html>
OUTPUT:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<ol start="5">
<li>Item 5</li>
<li>Item 6</li>
<li>Item 7</li>
<li>Item 8</li>
</ol>
</body>
</html>
OUTPUT:
5. Item 5
6. Item 6
7. Item 7
8. Item 8
<html>
<head>
</head>
<body>
<ol>
<li>
JavaScript
<ol>
<li>React</li>
<li>Angular</li>
<li>Vue.js</li>
</ol>
</li>
<li>
Python
<ol>
<li>Django</li>
<li>Flask</li>
<li>Pyramid</li>
</ol>
</li>
</ol>
</body>
</html>
OUTPUT:
1. JavaScript
1. React
2. Angular
3. Vue.js
2. Python
1. Django
2. Flask
3. Pyramid
HTML Unordered Lists
An HTML Unordered List is defined with the <ul> tag, where “ul”
stands for “unordered list.” Each item within the list is marked by a <li>
tag, standing for “list item.”
The items in an unordered list are typically displayed with bullet points,
which can be styled or changed using CSS.
Syntax:
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
HTML Unordered Lists Examples
Below are some examples showing the use of HTML Unordered lists.
Example
<!DOCTYPE html>
<html>
<head>
<title>
HTML Unordered Lists
</title>
</head>
<body>
<h2>HTML Unordered Lists</h2>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>Javascript</li>
<li>React</li>
</ul>
</body>
</html>
OUTPUT:
Values Descriptions
Output:
<!DOCTYPE html>
<html>
<head>
<title>
Circle type unordered list
</title>
</head>
<body>
<h2> Circle type unordered list</h2>
<ul style="list-style-type:circle;">
<li>HTML</li>
<li>CSS</li>
<li>Javascript</li>
<li>React</li>
</ul>
</body>
</html>
Output:
<!DOCTYPE html>
<html>
<head>
<title>
None type unordered list
</title>
</head>
<body>
<h2>None type unordered list</h2>
<ul style="list-style-type:none;">
<li>HTML</li>
<li>CSS</li>
<li>Javascript</li>
<li>React</li>
</ul>
</body>
</html>
Output:
Output:
Horizontal Unordered List
An Unordered list can also be aligned in the Horizontal manner, which
acts similar to the Nav bar.
Example: Implementation of Unordered List horizontally.
<!DOCTYPE html>
<html>
<head>
<title>HTML Horizontal Unordered List</title>
<style>
body {
text-align: center;
}
ul {
overflow: hidden;
background-color: #1d6b0d;
list-style-type: none;
}
li {
float: left;
}
li a {
text-decoration: none;
color: white;
padding: 0.5rem;
}
</style>
</head>
<body>
<h3>HTML Horizontal Unordered List</h3>
<ul>
<li><a href="#course">Course</a></li>
<li><a href="#Blog">Blogs</a></li>
<li>
<a href="#Content">Content</a>
</li>
</ul>
</body>
</html>
OUTPUT:
Method Description
Event Handlers
HTML hr Tag
The <hr> tag in HTML is used to create a horizontal rule or line that
visually separates content. It is a self-closing tag and does not require
an end tag. It also supports the Global Attributes and Event Attributes.
<!DOCTYPE html>
<html>
<body>
<p>
There is a horizontal rule
below this paragraph.
</p>
<hr>
<p>
This is a horizontal rule
above this paragraph.
</p>
</body>
</html>
OUTPUT:
Attributes
The table below shows a few attributes that allow customization:
<!DOCTYPE html>
<html>
<body>
<p>
Normal horizontal line.
</p>
<hr>
<p>
Horizontal line with height
of 30 pixels
</p>
<hr size="30">
<p>
Horizontal line with height
of 30 pixels and noshade.
</p>
<hr size="30" noshade>
</body>
</html>
OUTPUT:
HTML br Tag
The <br> tag in HTML is used to create a line break in the text, causing
the content that follows it to appear on a new line. It is a self-closing tag,
meaning it does not need a separate closing tag.
<!DOCTYPE html>
<html
<body>
</body>
</html>
OUTPUT:
Dear Reader,
This is printed after a line break.
<!DOCTYPE html>
<html>
<body>
<p>
</p>
</body>
</html>
OUTPUT:
HTML Images
The HTML <img> tag is used to embed an image in web pages by
linking them. It creates a placeholder for the image, defined by attributes
like src, width, height, and alt, and does not require a closing tag.
There are two ways to insert the images into a webpage:
• By providing a full path or address (URL) to access an internet
file.
• By providing the file path relative to the location of the current
web page file.
Basic Example of the <img> Tag:
<!DOCTYPE html>
<html>
<body>
<img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20210915115837/gfg3-
300x300.png"
</body>
</html>
OUTPUT:
In this example:
• The <img> tag is used to embed an image into the webpage.
• src attribute: Specifies the source URL of the image, which in
this example is https://media.geeksforgeeks.org/wp-
content/uploads/20210915115837/gfg3-300×300.png. The
image is loaded from this URL when the webpage is accessed.
• alt attribute: Provides alternative text for the image, “GFG
image,” which describes the image content. If, for any reason,
the image cannot be displayed, the text “GFG image” will be
shown instead.
Various HTML <img> Tag Attributes
Attribute Description
Provides alternate text for the image, useful for accessibility and
alt
when the image cannot be displayed.
<!DOCTYPE html>
<html>
<body>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-
uploads/20190710102234/download3.png"
alt="GeeksforGeeks logo"
width="200"
height="200"
</body>
</html>
OUTPUT:
<!DOCTYPE html>
<html>
<body>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-
uploads/20190710102234/download3.png"
alt="GeeksforGeeks logo"
width="200"
height="200"
border="5" />
</body>
</html>
OUTPUT:
<!DOCTYPE html>
<html>
<body>
<img
src="https://media.geeksforgeeks.org/wp-content/cdn-
uploads/20190710102234/download3.png"
alt="GeeksforGeeks logo"
align="right" />
</body>
</html>
OUTPUT:
<!DOCTYPE html>
<html>
<body>
<a href="https://ide.geeksforgeeks.org/tryit.php">
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-
uploads/20190710102234/download3.png"
alt="GeeksforGeeks logo" />
</a>
</body>
</html>
OUTPUT:
<!DOCTYPE html>
<html>
<head>
<title>HTML Links</title>
</head>
<body>
<a href="https://www.geeksforgeeks.org">
GeeksforGeeks
</a>
</body>
</html>
OUTPUT:
Attribute Description
_top Opens the linked document in the full body of the window.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h3>
Target Attribute
</h3>
<p>
</p>
<a href="https://www.geeksforgeeks.org"
target="_blank">
GeeksforGeeks
</a>
<p>
</p>
<a href="https://www.geeksforgeeks.org"
target="_self">
GeeksforGeeks
</a>
<p>
</p>
<a href="https://www.geeksforgeeks.org"
target="_top">
GeeksforGeeks
</a>
<p>
parent frame.
</p>
<a href="https://www.geeksforgeeks.org"
target="_parent">
GeeksforGeeks
</a>
</body>
</html>
Output:
Linking Different HTML Elements
Below are examples of how to link different HTML elements with their
respective code snippets
Element to
Interlink Specific Code
Link to an Email
<a href="mailto:[email protected]">Send Email</a>
Address
Link to
<a href="file.pdf" download>Download File</a>
Download File