Chapter 2
Chapter 2
Chapter 2
Designing and Building Web Pages with HTML5 Elements
1.1. Getting Started with HTML
The Hypertext Markup Language (HTML) is the backbone of the World Wide Web. Every website,
regardless of its complexity, is built upon HTML. It provides the structure of web pages, allowing
developers to define content such as text, images, links, forms, and multimedia. In this section, we explore
what HTML is, its role in web development, and how to create a basic HTML document.
Hypertext refers to the linking of documents through hyperlinks, enabling navigation across web
pages.
Markup refers to the use of elements (tags) that describe the structure of content (e.g., headings,
paragraphs, lists).
HTML defines the structure of web content, such as headings, paragraphs, and tables. It works together
with CSS (Cascading Style Sheets) to handle the visual styling and with JavaScript to add interactivity and
dynamic behavior. Serving as the foundation of all websites and web applications, HTML provides the
essential framework upon which every other web technology is built.
HTML5 Overview
The current standard is HTML5, introduced in 2014. It brought new features to make the web more
powerful and semantic.
<!DOCTYPE html>
<html>
<head>
<title>My First Page</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is my first HTML page.</p>
</body>
</html>
Explanation of elements:
<head>: Contains metadata, such as the page title and links to stylesheets.
<body>: Holds all the visible content (text, images, links, etc.).
In this section, we will learn how to use HTML tags to define headings, paragraphs, line breaks, formatted
text, quotations, and code snippets. We will also explore the difference between block-level and inline
elements and understand how <div> and <span> are used for layout and grouping.
Example:
<h1>Main Title</h1>
<h2>Section Title</h2>
<h3>Subsection Title</h3>
Use only one <h1> tag per page, typically for the main title, to establish a clear hierarchy. Subsequent
headings such as <h2>, <h3>, and others should be used to organize content logically and maintain a well-
structured document. Following proper heading practices enhances both readability for users and search
engine optimization (SEO), making the content more accessible and easier to index.
Paragraphs (<p>)
Paragraphs are used to represent blocks of text. The browser automatically adds spacing before and after
each paragraph.
Example:
Line Break (<br>): Used to start text on a new line without creating a new paragraph.
o <p>Address:<br>Addis Ababa,<br>Ethiopia</p>
Horizontal Rule (<hr>): Inserts a horizontal line to separate sections or topics.
o <hr>
These tags help create well-styled and meaningful documents when used properly.
Quotations
Quotations are important when referencing statements or citing external sources. HTML offers specific
tags for this purpose:
<blockquote>
“The best way to predict the future is to invent it.” - Alan Kay
</blockquote>
Inline quotation (<q>) – Used for short quotes within a sentence.
<p>Alan Kay once said, <q>The best way to predict the future is to invent
it.</q></p>
Citation (<cite>) – Refers to the title of a cited work (book, article, etc.).
Example:
<pre>
for i in range(3):
print(i)
</pre>
In this section, we will explore how to use hyperlinks and images in HTML, including advanced features
like image maps and favicons.
Hyperlinks (<a>)
The <a> tag (short for anchor) is used to create hyperlinks in HTML. Hyperlinks connect web pages,
documents, or external resources.
The href (hypertext reference) attribute specifies the destination of the link.
Example:
Types of Links
1. Absolute URLs
These contain the full web address, including protocol and domain name.
<a href="[Link] W3C Website</a>
2. Relative URLs
These point to resources within the same website or directory.
<a href="[Link]">About Us</a>
Use this when linking pages within your own project folder.
3. Email Links
HTML allows creating links that open the user’s default email client.
<a href="[Link] Email</a>
4. Phone Links
On mobile devices, you can make a link that initiates a phone call.
<a href="[Link] Us</a>
Additional Attributes
Images (<img>)
Images make web pages more appealing and can communicate information visually.
Basic Syntax
Attributes:
title Adds tooltip text when hovering. <img src="[Link]" title="Our Team">
width and Define image dimensions (in pixels <img src="[Link]" width="300"
height or percentages). height="200">
Example
If the image file cannot be found, the browser displays the alt text instead, a critical accessibility feature
for screen readers.
Example
<map name="worldmap">
<area shape="rect" coords="50,50,150,150" href="[Link]"
alt="Africa">
<area shape="circle" coords="300,200,50" href="[Link]"
alt="Europe">
</map>
Explanation:
<map> defines the image map and is given a name (referenced by usemap).
A favicon is a small icon that represents a website, displayed in the browser tab and bookmarks.
Example
<head>
<link rel="icon" type="image/png" href="images/[Link]">
</head>
Notes:
Favicons should be small (usually 16×16 or 32×32 pixels).
Common formats include .ico, .png, or .svg.
It helps build brand identity and improve the website’s professional appearance.
1.4. Lists
Lists are an essential part of web pages because they help organize content into a clear, readable, and
logical format. HTML provides three types of lists, ordered, unordered, and description lists, each serving
a unique purpose. Lists can also be nested, allowing developers to create structured and hierarchical
content, such as menus or outlines.
In this section, we will explore how to create and style different types of lists using HTML elements.
Syntax:
<ol>
<li>Step One</li>
<li>Step Two</li>
<li>Step Three</li>
</ol>
Example:
By default, ordered lists use numbers (1, 2, 3, …). However, you can customize the numbering style using
the type attribute.
Example:
<ol type="A">
<li>Introduction</li>
<li>Body</li>
<li>Conclusion</li>
</ol>
Syntax:
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
You can change the bullet style using the type attribute (though CSS is preferred for styling).
Type Description
disc Default filled circle
circle Hollow circle
square Solid square
Example:
<ul type="square">
<li>Apples</li>
<li>Bananas</li>
<li>Cherries</li>
</ul>
Syntax:
<dl>
<dt>HTML</dt>
<dd>The standard language for creating web pages.</dd>
<dt>CSS</dt>
<dd>A style sheet language used to describe the look of a
webpage.</dd>
</dl>
Explanation:
<dl> - Defines the start of a description list.
<dt> - Stands for “definition term.”
<dd> - Stands for “definition description.”
Example:
<h3>Web Technologies</h3>
<dl>
<dt>HTML</dt>
<dd>Defines the structure of web content.</dd>
<dt>CSS</dt>
<dd>Styles and formats web pages.</dd>
<dt>JavaScript</dt>
<dd>Adds interactivity to websites.</dd>
</dl>
Nested Lists
Lists can be nested, meaning one list can be placed inside another. This is useful for creating menus,
outlines, or categorized data.
Example:
<h3>Course Topics</h3>
<ul>
<li>Frontend Development
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</li>
<li>Backend Development
<ol>
<li>PHP</li>
<li>[Link]</li>
</ol>
</li>
</ul>
Explanation:
A <ul> list can contain another <ul> or <ol> inside its <li> items.
Proper indentation improves readability.
1.5. Tables
Tables in HTML are used to organize data into rows and columns, making it easier to display structured
information such as schedules, price lists, or statistical data. The <table> element provides a flexible way
to present tabular content on a web page.
Although modern web design often uses CSS for page layout, HTML tables remain essential for displaying
structured data clearly and accessibly. In this section, we will explore the fundamental table elements and
attributes, how to merge cells, add captions, and organize large tables using grouping elements.
Example:
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
<tr>
<td>Abebe</td>
<td>22</td>
<td>Addis Ababa</td>
</tr>
<tr>
<td>Selam</td>
<td>24</td>
<td>Hawassa</td>
</tr>
</table>
Explanation:
<th> cells represent headings (e.g., column or row titles).
</table>
Example:
<table border="1">
<caption>Student Grades for 2025</caption>
<tr>
<th>Name</th>
<th>Subject</th>
<th>Grade</th>
</tr>
<tr>
<td>Abebe</td>
<td>Math</td>
<td>A</td>
</tr>
</table>
By default, the caption appears above the table, though CSS can change its position.
<tfoot> - Defines the footer section, often used for totals or summaries.
Example:
<table border="1">
<caption>Monthly Sales Report</caption>
<thead>
<tr>
<th>Month</th>
<th>Sales</th>
<th>Profit</th>
</tr>
</thead>
<tbody>
<tr>
<td>January</td>
<td>$5,000</td>
<td>$1,200</td>
</tr>
<tr>
<td>February</td>
<td>$6,000</td>
<td>$1,500</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Total</th>
<th>$11,000</th>
<th>$2,700</th>
</tr>
</tfoot>
</table>
Benefits of Grouping:
Styling Attributes
Although modern developers use CSS for styling, HTML still supports a few basic table attributes that help
visualize structure quickly during learning or prototyping.
Attribute Description Example
border Defines the thickness of table borders. <table border="1">
cellpadding Adds space inside each cell (between text and border). <table cellpadding="5">
cellspacing Adds space between cells. <table cellspacing="5">
Example:
<table border="1" cellpadding="5" cellspacing="3">
<tr>
<th>Product</th>
<th>Price</th>
</tr>
<tr>
<td>Bread</td>
<td>$2</td>
</tr>
</table>
action - specifies the URL where the form data will be sent.
Example:
<form action="[Link]" method="post">
<!-- form elements go here -->
</form>
Input Types
The <input> tag is used to collect various types of data. Common input types include:
Input Type Description
text Single-line text input.
password Masked input for passwords.
email Validates email format.
number Allows numeric input with optional range.
date Date picker control.
file Lets users upload files.
color Color selection interface.
range Slider control for numeric ranges.
checkbox Used for multiple selections.
radio Used for single-choice options.
Example:
Labels make forms more accessible by linking descriptive text to input controls using the <label for>
attribute.
Example:
<label for="email">Email:</label>
<input type="email" id="email" name="email">
The <fieldset> tag groups related form elements, and <legend> provides a title for the group.
Example:
<fieldset>
<legend>Personal Information</legend>
<input type="text" name="fullname">
<input type="date" name="birthdate">
</fieldset>
Dropdown Lists
Dropdown menus are created using the <select> element, with individual options inside <option>. The
<optgroup> tag can group related options.
Example:
<select name="country">
<optgroup label="Africa">
<option value="ethiopia">Ethiopia</option>
<option value="kenya">Kenya</option>
</optgroup>
<optgroup label="Asia">
<option value="china">China</option>
<option value="india">India</option>
</optgroup>
</select>
Text Area
The <textarea> tag is used for multi-line text input, such as comments or messages.
Example:
Buttons
Buttons perform actions like submitting or resetting the form. Common types:
Example:
<button type="submit">Submit</button>
<button type="reset">Clear</button>
Form Validation
HTML provides built-in validation attributes to ensure correct input before submission:
Example:
Get vs Post
1.7. Multimedia
Multimedia elements enhance web pages by allowing the inclusion of audio, video, and interactive
content. HTML provides built-in tags to easily embed and control such media without external plugins.
Audio Element
The <audio> tag is used to embed sound content such as music or narration. It supports attributes like:
Example:
<audio controls autoplay loop>
<source src="sound.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Video Element
The <video> tag embeds video content directly into web pages. It can include multiple sources and
several useful attributes:
Example:
The <track> tag adds text tracks, such as subtitles or captions, to video elements. It improves
accessibility and comprehension.
Example:
<video controls>
<source src="lesson.mp4" type="video/mp4">
<track src="[Link]" kind="captions" srclang="en"
label="English">
</video>
The <iframe> tag embeds external resources such as web pages, maps, or videos (e.g., from YouTube).
Example:
<iframe
src="[Link]
width="560"
height="315"
allowfullscreen>
</iframe>
Example:
<header>
<h1>Tech Today</h1>
<nav>
<a href="#home">Home</a>
<a href="#articles">Articles</a>
<a href="#contact">Contact</a>
</nav>
</header>
<main>
<article>
<h2>The Rise of AI</h2>
<p>Artificial Intelligence is shaping the future of
technology...</p>
</article>
<aside>
<h3>Related Topics</h3>
<ul>
<li>Machine Learning</li>
<li>Neural Networks</li>
</ul>
</aside>
</main>
<footer>
<p>© 2025 Tech Today. All rights reserved.</p>
</footer>
Accessibility: Screen readers and assistive technologies can better understand the content
structure.
SEO Improvement: Search engines can interpret and rank content more effectively.
Cleaner Code: Enhances readability, maintainability, and organization of HTML documents.
Open Graph tags are used to improve how web pages appear when shared on social media platforms like
Facebook, LinkedIn, and X (Twitter).
Base Element
The <base> tag defines a base URL for all relative links within a document. It ensures that all internal links
reference the correct root location.
Example:
<base href="[Link]
<a href="[Link]">Contact Us</a> <!-- becomes
[Link] -->
Noscript Element
The <noscript> tag provides fallback content for users whose browsers do not support or have disabled
JavaScript.
Example:
<noscript>
<p>JavaScript is disabled in your browser. Some features may not work
properly.</p>
</noscript>
The <details> element is used to create collapsible content sections that can be expanded or hidden
by the user. The <summary> tag defines the visible heading or label for that section.
Example:
<details>
<summary>Learn More About HTML5</summary>
<p>HTML5 introduces semantic, multimedia, and interactive elements
that enhance web development.</p>
</details>
Uses:
<dialog> Element
The <dialog> tag defines a dialog box or popup window that can be opened or closed programmatically
or by the user.
Example:
<dialog id="infoDialog">
<p>Welcome to the course!</p>
<button
onclick="[Link]('infoDialog').close()">Close</button>
</dialog>
<button
onclick="[Link]('infoDialog').showModal()">Open
Dialog</button>
Attributes:
open – displays the dialog by default.
Both elements visually represent numeric values, but they serve slightly different purposes.
Benefits:
<canvas> Introduction
The <canvas> element allows drawing graphics directly on a web page using JavaScript. It’s commonly
used for animations, games, and visualizations.
<script>
const canvas = [Link]('myCanvas');
const ctx = [Link]('2d');
// Draw rectangle
[Link] = "lightblue";
[Link](20, 20, 100, 50);
// Draw circle
[Link]();
[Link](150, 75, 25, 0, 2 * [Link]);
[Link] = "orange";
[Link]();
</script>
Key Methods:
Accessibility focuses on making web content understandable and navigable for all users, especially those
using assistive technologies like screen readers.
Additional Tips:
ARIA Basics
ARIA (Accessible Rich Internet Applications) attributes improve accessibility in dynamic web content,
particularly when JavaScript updates the page without reloading.
Note: ARIA should be used to enhance, not replace, proper semantic HTML.
HTML Entities
HTML entities are used to display special characters or symbols that might otherwise be interpreted as
code. They begin with an ampersand (&) and end with a semicolon (;).
Entity Displayed As Meaning / Usage
< < Less-than symbol.
> > Greater-than symbol.
& & Ampersand character.
© © Copyright symbol.
(non-breaking space) Prevents line breaks between words or elements.
Example: