Courses / Application of ICT (GEN-103) – BS 1st Semester
Week 16 Theory – Introduction to HTML, Text Formatting and Lists
Week 16 – HTML Basics: Structure, Text Formatting and Lists · 80 min read · 46 MCQs to check yourself
What is HTML?
HTML (HyperText Markup Language) is the standard markup language used to create web pages. It describes the structure and content of a page (headings, paragraphs, lists, links, images, tables) using tags. Browsers read HTML and display the page.
- HyperText – text containing links to other text/pages.
- Markup language – text is "marked up" with tags; HTML is not a programming language (no logic/calculations).
- Created by Tim Berners-Lee (1991); current version HTML5. Styling is done with CSS and behaviour with JavaScript.
- HTML files are saved with the extension
.htmlor.htmand can be written in any text editor (Notepad, Notepad++, VS Code).
HTML tags and elements
- A tag is a keyword enclosed in angle brackets:
<p>. - Most tags come in pairs: an opening tag
<b>and a closing tag</b>(with a forward slash). - An element = opening tag + content + closing tag:
<b>Pakistan</b>. - Empty (void / singular) tags have no content and no closing tag:
<br>,<hr>,<img>. - Attributes give extra information inside the opening tag as
name="value":<font color="red" size="5">Hello</font> - HTML is not case-sensitive (
<B>=<b>), but lowercase is recommended. - Tags must be properly nested:
<b><i>text</i></b>✔, not<b><i>text</b></i>✘. - Comments are not displayed:
<!-- This is a comment -->.
Basic structure of an HTML document
<!DOCTYPE html>
<html>
<head>
<title>My First Web Page</title>
</head>
<body>
<h1>Welcome to ICT</h1>
<p>This is my first web page.</p>
</body>
</html>
| Tag | Purpose |
|---|---|
<!DOCTYPE html> |
Declaration telling the browser this is an HTML5 document (not a tag) |
<html> … </html> |
Root element – contains the whole page |
<head> … </head> |
Head section – information about the page (title, meta data, links to CSS/scripts); not shown in the page body |
<title> … </title> |
Text shown on the browser tab/title bar and in bookmarks/search results; placed inside <head> |
<body> … </body> |
Body section – all visible content of the page (text, images, links, tables) |
Body attributes (older HTML): bgcolor="lightblue" (background colour), text="navy" (text colour), background="bg.jpg" (background image), link, vlink, alink (link colours). In modern HTML these are done with CSS.
Headings, paragraphs, line breaks and spaces
- Headings – six levels from
<h1>(largest, most important) to<h6>(smallest):
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
- Paragraph –
<p> … </p>starts a new block with space above and below. Attributealign="center|left|right|justify". - Line break –
<br>(empty tag) moves to the next line without starting a new paragraph. - Horizontal rule –
<hr>draws a horizontal line (attributes:width,size,color,align). - Non-breaking space –
adds an extra space. Browsers collapse many spaces into one, so use for several spaces. - Pre-formatted text –
<pre> … </pre>keeps spaces and line breaks exactly as typed.
Character entities
| Entity | Shows |
|---|---|
|
non-breaking space |
< |
< |
> |
> |
& |
& |
© |
© |
" |
" |
Text formatting tags
| Tag | Effect | Example output |
|---|---|---|
<b> … </b> |
Bold | ICT |
<strong> … </strong> |
Important text (bold) | Warning |
<i> … </i> |
Italic | ICT |
<em> … </em> |
Emphasised text (italic) | note |
<u> … </u> |
Underline | ICT (underlined) |
<strike> … </strike> / <s> … </s> / <del> … </del> |
||
<sup> … </sup> |
Superscript (raised) | x², 1st → x<sup>2</sup> |
<sub> … </sub> |
Subscript (lowered) | H₂O → H<sub>2</sub>O |
<center> … </center> |
Centres text (deprecated in HTML5; use CSS text-align:center) |
|
<big>, <small> |
Bigger / smaller text | |
<mark> … </mark> |
Highlighted text |
<p>Water formula: H<sub>2</sub>O</p>
<p>Area = a<sup>2</sup></p>
<p><b>Bold</b>, <i>Italic</i>, <u>Underline</u>, <strike>Strike</strike></p>
<center>This text is centred</center>
Font size, font colour and font face
The <font> tag (deprecated in HTML5, but still supported by browsers and part of your syllabus) changes the appearance of text:
<font size="5" color="blue" face="Arial">Welcome to PrepOasis</font>
<font size="+2" color="#FF0000" face="Times New Roman">Red text</font>
- size – 1 to 7 (default 3); can be relative:
+1,-1. - color – colour name (
red,green) or hexadecimal code#RRGGBB(#FF0000= red,#00FF00= green,#0000FF= blue,#000000= black,#FFFFFF= white). - face – font name (Arial, Verdana, Times New Roman); a list can be given as fallbacks.
Modern equivalent with CSS: <p style="font-size:20px; color:blue; font-family:Arial;">Text</p>.
Lists in HTML
1. Unordered list (bulleted) – <ul>
<ul type="square">
<li>Keyboard</li>
<li>Mouse</li>
<li>Scanner</li>
</ul>
type = disc (default ●), circle (○), square (■).
2. Ordered list (numbered) – <ol>
<ol type="A" start="3">
<li>Planning</li>
<li>Analysis</li>
<li>Design</li>
</ol>
type = 1 (default 1, 2, 3), A (A, B, C), a (a, b, c), I (I, II, III), i (i, ii, iii). start sets the starting number; reversed counts down.
3. Definition (description) list – <dl>
<dl>
<dt>CPU</dt>
<dd>Central Processing Unit – the brain of the computer.</dd>
<dt>RAM</dt>
<dd>Random Access Memory – volatile main memory.</dd>
</dl>
<dl>= definition list,<dt>= definition term,<dd>= definition description.
4. Nested list – a list inside a list item
<ul>
<li>Input devices
<ol>
<li>Keyboard</li>
<li>Mouse</li>
</ol>
</li>
<li>Output devices
<ul type="circle">
<li>Monitor</li>
<li>Printer</li>
</ul>
</li>
</ul>
<li> (list item) is used in both <ul> and <ol>.
HTML Tutorial for Beginners: HTML Crash Course (Programming with Mosh)
HTML Lists Tutorial – Ordered, Unordered & Description (Dave Gray)
Short and long questions
1. What is an attribute? Give an example.
Model answer
An attribute provides additional information about an element and is written in the opening tag as name="value", e.g. <body bgcolor="lightblue"> or <font color="red">.
2. What is HTML? Differentiate between container and empty tags.
Model answer
HTML (HyperText Markup Language) is the standard markup language for creating web pages using tags. Container (paired) tags have an opening and closing tag with content between them, e.g. <b>Text</b>. Empty (singular) tags have no content and no closing tag, e.g. <br>, <hr>, <img>.
3. Explain the basic structure of an HTML document and the purpose of html, head, title and body tags. Also explain heading and paragraph tags.
Model answer
An HTML document starts with <!DOCTYPE html>, then <html> (root element that contains everything). Inside it, <head> holds information about the page — most importantly <title>, whose text appears on the browser tab and in bookmarks. Then <body> contains all visible content; it can have attributes such as bgcolor, text and background.
<!DOCTYPE html>
<html>
<head><title>ICT Notes</title></head>
<body>
<h1>Chapter 1</h1>
<h2>Introduction</h2>
<p align="justify">A computer is an electronic device...</p>
</body>
</html>
Headings: six levels <h1> (largest) to <h6> (smallest) for titles and sub-titles. Paragraph: <p> creates a block of text with spacing; align sets alignment; <br> breaks a line and <hr> draws a horizontal line.
4. Differentiate between the head and body sections.
Model answer
The head (<head>) contains information about the page such as the title, meta data and links to CSS/scripts; it is not displayed in the page area. The body (<body>) contains all the visible content — text, headings, images, links, lists and tables.
5. Write the basic structure of an HTML document.
Model answer
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> visible content </body> </html> — html is the root, head holds information such as the title, and body holds the visible content.
6. What is the use of <br and ?
Model answer
<br> inserts a line break (moves following content to the next line without starting a new paragraph). inserts a non-breaking space; it is used to add extra spaces because browsers collapse multiple ordinary spaces into one.
7. Write an HTML program to display your name as a heading, a paragraph about ICT with bold, italic, underlined, subscript and superscript text, and a red Arial font line.
Model answer
<!DOCTYPE html>
<html>
<head>
<title>Formatting Demo</title>
</head>
<body bgcolor="lightyellow">
<h1>Ali Raza</h1>
<p>
<b>ICT</b> stands for <i>Information and Communication Technology</i>.<br>
It is a <u>compulsory</u> subject. Water is H<sub>2</sub>O and area of a square is a<sup>2</sup>.<br>
Old price: <strike>Rs. 500</strike> New price: Rs. 400
</p>
<center>
<font size="5" color="red" face="Arial">Welcome to the World Wide Web</font>
</center>
</body>
</html>
The heading uses <h1>, the paragraph uses <p> with <b>, <i>, <u>, <sub>, <sup>, <strike>, <br> and , and the last line uses <center> and <font> with size, color and face.
8. Name any six text formatting tags.
Model answer
<b> bold, <i> italic, <u> underline, <strike> strike-through, <sup> superscript, <sub> subscript (also <strong>, <em>, <center>, <mark>).
9. Write HTML code to display H₂O and a² + b².
Model answer
H<sub>2</sub>O and a<sup>2</sup> + b<sup>2</sup>.
10. Write the attributes of the <font tag with an example.
Model answer
size (1–7, default 3), color (name or hex code like #0000FF) and face (font name). Example: <font size="6" color="green" face="Verdana">ICT Course</font>.
11. Explain the types of lists in HTML with examples of code.
Model answer
1. Unordered list – bulleted items: <ul type="disc|circle|square"> <li>Keyboard</li> <li>Mouse</li> </ul>.
2. Ordered list – numbered items: <ol type="1|A|a|I|i" start="1"> <li>Planning</li> <li>Analysis</li> </ol>; type changes the numbering style and start sets the first number.
3. Definition list – terms with descriptions: <dl> <dt>CPU</dt> <dd>Central Processing Unit</dd> <dt>RAM</dt> <dd>Random Access Memory</dd> </dl>.
4. Nested list – a list inside a list item:
<ul>
<li>Input devices
<ol><li>Keyboard</li><li>Mouse</li></ol>
</li>
<li>Output devices
<ul type="square"><li>Monitor</li><li>Printer</li></ul>
</li>
</ul>
12. Name the types of lists in HTML.
Model answer
Unordered list (<ul>), ordered list (<ol>), definition/description list (<dl> with <dt> and <dd>) and nested lists (a list inside another list).
This lesson ends with a quiz of 46 MCQs. Open the lesson on PrepOasis to take it and save your progress.
Previous: Week 15 Lab 15 – HTML: Text Formatting Practice · Next: Week 16 Lab 16 – HTML: Creating Lists and Tables
All lessons in Application of ICT (GEN-103) – BS 1st Semester