Courses / Application of ICT (GEN-103) – BS 1st Semester

Week 15 Lab 15 – HTML: Text Formatting Practice

Week 15 – World Wide Web · 90 min read · 7 MCQs to check yourself

Lab objectives

Practise <title>, <br>, &nbsp;, headings <h1>–<h6>, bold, underline, italics, strike-out, superscript, subscript, centre, and font size/colour/face.

Task 1 – Headings, breaks and spaces

Create format.html:

<!DOCTYPE html>
<html>
<head>
  <title>Text Formatting Practice</title>
</head>
<body>
  <h1>Heading Level 1</h1>
  <h2>Heading Level 2</h2>
  <h3>Heading Level 3</h3>
  <h4>Heading Level 4</h4>
  <h5>Heading Level 5</h5>
  <h6>Heading Level 6</h6>
  <hr>
  <p>Line one<br>Line two<br>Line three</p>
  <p>Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ayesha Khan</p>
  <p>Without nbsp:      the extra spaces disappear.</p>
</body>
</html>

Observe: heading sizes decrease from h1 to h6; <br> breaks lines inside one paragraph; &nbsp; keeps five spaces while normal spaces collapse into one.

Task 2 – Text formatting tags

Add to the body:

<p><b>This text is bold.</b></p>
<p><i>This text is italic.</i></p>
<p><u>This text is underlined.</u></p>
<p><strike>This text is struck out.</strike> Now only Rs. 999</p>
<p>Einstein: E = mc<sup>2</sup></p>
<p>Glucose: C<sub>6</sub>H<sub>12</sub>O<sub>6</sub></p>
<p>Today is the 21<sup>st</sup> of March.</p>
<center>This line is centred on the page.</center>
<p><b><i><u>Bold, italic and underlined together</u></i></b></p>

Task 3 – Font size, colour and face

<font size="1">Size 1</font><br>
<font size="3">Size 3 (default)</font><br>
<font size="7">Size 7</font><br>
<font size="+2">Two sizes bigger</font><br>
<font color="red">Red text</font><br>
<font color="#008000">Green text using hex code</font><br>
<font face="Arial">Arial font</font><br>
<font face="Courier New">Courier New font</font><br>
<font size="5" color="blue" face="Verdana">Size 5, blue, Verdana</font>

CSS equivalent (modern way):

<p style="font-size:24px; color:blue; font-family:Verdana; text-align:center;">Styled with CSS</p>

Task 4 – A formatted page

Create notice.html – a college notice:

<!DOCTYPE html>
<html>
<head><title>Notice Board</title></head>
<body bgcolor="#FFFDE7">
  <center>
    <h1><font color="darkred" face="Georgia">NOTICE</font></h1>
    <h3>Department of Information Technology</h3>
  </center>
  <hr>
  <p>All students of <b>BS IT Semester 1</b> are informed that the
     <u>ICT Mid-Term Practical</u> will be held on <b>15<sup>th</sup> November</b>.</p>
  <p>Venue:&nbsp;&nbsp;<i>Computer Lab 2</i><br>
     Time:&nbsp;&nbsp;&nbsp;<i>9:00 am – 12:00 pm</i></p>
  <p><strike>Old venue: Lab 1</strike></p>
  <p align="right"><font size="2">Head of Department</font></p>
</body>
</html>

Lab exercise (submit)

Create chemistry.html showing: a title; h1 "Chemical Formulas"; formulas H₂O, CO₂, H₂SO₄ using <sub>; math expressions a² + b² = c² and 2¹⁰ = 1024 using <sup>; a struck-out wrong formula; one line in each of three font faces, three sizes and three colours; and a centred footer with your name in bold italics.

HTML Crash Course (text formatting) – Programming with Mosh

Short and long questions

1. Write a complete HTML page that uses headings h1 to h3, line breaks, non-breaking spaces, bold, italic, underline, strike, superscript, subscript, center and font tags.

Model answer
<!DOCTYPE html>
<html>
<head><title>Formatting Page</title></head>
<body>
  <h1>Information Technology</h1>
  <h2>Semester 1</h2>
  <h3>ICT Practical</h3>
  <p>Name:&nbsp;&nbsp;&nbsp;<b>Bilal Ahmed</b><br>
     Roll No:&nbsp;<i>25-BSIT-021</i></p>
  <p><u>Important formulas</u>: E = mc<sup>2</sup>, H<sub>2</sub>O</p>
  <p>Price: <strike>Rs. 1500</strike> Rs. 1200</p>
  <center><font size="5" color="green" face="Verdana">Thank you</font></center>
</body>
</html>

It shows three heading levels, <br> for new lines, &nbsp; for spaces, <b>, <i>, <u>, <strike>, <sup>, <sub>, and <center> with <font> attributes size, color and face.

2. Write HTML code to display "Welcome" in size 6, red colour and Arial font, centred.

Model answer

<center><font size="6" color="red" face="Arial">Welcome</font></center>.

3. Write HTML code to display: a² + b² = c² and H₂SO₄.

Model answer

a<sup>2</sup> + b<sup>2</sup> = c<sup>2</sup> and H<sub>2</sub>SO<sub>4</sub>.

This lesson ends with a quiz of 7 MCQs. Open the lesson on PrepOasis to take it and save your progress.

Previous: Week 15 Theory – The World Wide Web · Next: Week 16 Theory – Introduction to HTML, Text Formatting and Lists

All lessons in Application of ICT (GEN-103) – BS 1st Semester