Every topic starts at New. Sign in and your practice counts.
Hypertext Markup Language (HTML) is the language used to define and display your contents in the form of a webpage. With the help of tags, you will define different contents what they are, correspondingly HTML will display them accordingly. Html identifies and provides support for every object in a webpage on the basis of tags. For example, "This is my first attempt for a webpage." is a sentence which you want to get displayed in a web browser, so you have to put it like this:
<p>"This is my first attempt for a webpage."</p>
Character(s) between angle brackets '<' and '>' are called tags. The said character(s) is as per the defined HTML rules and is one of the elements that we can use. Every component of Html is identified by a starting and terminating tag. Additionally, we have to define from where to start and end the effect of every component. Therefore, we place <p>, the starting marker, in the start of the sentence and </p>, the closing marker, after the sentence. Now, you have put your sentence between two tags with a component to take effect. The 'p' tag is used for paragraph/sentences.
Similarly, there are tags for everything in HTML. But, the main point to note here is that you can write your html code in a notepad and run it in a browser. There are many softwares/IDE environments available that help in minimizing your coding efforts. Visual Studio, Netbeans, etc. For this chapter, we will be using the Visual Studio
version 2022 environment, but the codes mentioned here will be applicable to any other environment, as well.
Installing Visual Studio
For installing the latest Integrated Development Environment (IDE) of Microsoft Visual Studio, visit https://visualstudio.microsoft.com/vs/ and download the installer. The installer is an executable file (.exe extension) and you just need to double click to start the installation.
Microsoft Visual Studio is a wide-ranging IDE which can be used for writing and running code for more than 30 languages. Therefore, it allows you to choose the language environment. Once
selected, click "install" and it will download and install the environment on your system (PC/ Laptop). After the installation, you can run the IDE from your system.
The Document Object Model (DOM) is a standard which provides mutual interpretation where grammar of a language can be associated with and can coexist on various operating systems. In HTML, every file is interpreted as a DOM-tree where hierarchy of the said file is defined.
Different elements which comprise of a webpage
like text, images, etc. are all part of DOM. So
when browser reads HTML file it creates the respective DOM automatically and correspondingly correctly displays the page.
As discussed in last chapter, a tree consists of nodes and links, so is the case here where every object and component of HTML is treated as node. Hence, the file, components, features, script and even comments which exist in a web page all are treated as objects by HTML as shown in fig 5.
'Document' comes at the top of the tree for whole webpage. Thereafter comes 'html' node which contains the HTML which has two sub-nodes, 'head' node that holds title of page and 'body' node where the content of HTML are placed like heading, paragraph, unordered list, etc.
In programming a good practice is to use comments within the code. This way, not only for the programmer but also for others it becomes easy to understand what the code or program is about. Comments are only visible in the code and are not part of the output, as output is dependent only on the code itself. Anything between '<!-'and '-->' is treated as comments and is ignored by the browser, as shown in Fig-6.
</-- This is a comment in HTML. It will not appear on the webpage. -->
<p>This paragraph will be visible on the webpage.</p>
Html is a tag based programming language so you should recognize the most important and frequent tags that you will encounter in the development. With a little bit of practice, these tags will be on your fingertips as the tags themselves are quite selfexplanatory. Every tag is used for different task and is easy to recognizable as tags are enclosed in '<' and '>'. Starting tag will look like <tag> while the ending of tag will be recognized with the help of a '/' like </tag>. For example is used for line break, <strong> is used to make text bold, etc.
Any html is identified with the <html> tag-pair,i.e. anything written between this tagpair is recognized as a html document. An HTML document is arranged just like a simple document that you write and prepare in Notepad, Wordpad or MS Word, etc., with headings, sub-headings, sentences, etc. Similar to <html> tag-pair, everything is characterized according to its respective tag-pair. The extension of an html file is '.html'.
The <head> tag-pair is defined, where tags can be placed which are not part of the main body of html, like the title of the webpage.
Just like every document has a name, the <title> tag-pair allows your webpage a name. In case, even if multiple pages or tabs are open in the browser, a webpage is easily identifiable. The title of the webpage is visible on the browser tag.
<html lang="en"> <!-- Start of the HTML document, Language is English -->
<head> <!-- Head section containing meta information -->
<title> Title-comes-here </title> <!-- Title of the webpage -->
</head>
<body>
<!-- Body section where webpage content gors. -->
This text is in the body section
</body>
</html>
<!-- End of the HTML document
. | Tip
Tip
OUTPUT
OUTPUT
This text is in the body section
Fig.7: Title and Body Sections of a Html Webpage
The main part of the html is the 'body', all the main constituents html, of the document are arranged in the <body> tag-pair. Fig-7 shows placement of head, title & body tag & respective output.
The headings are of different levels provided by html and there are 6 defined levels, 1 being the largest and 6 is the smallest heading. The heading tag pair looks like <h2>...</h2>; for a second level heading. Sample of headings are shown in Fig. 8.
<html lang="en">
<head>
<title>Heading Example</title>
</head>
<body>
<h1>Welcome to My Website</h1> <!-- Main heading (Largest important) -->
<h2>About Us</h2> </-- Subheading under main heading -->
<h3>Our Team</h3> ? </-- Further subheading -->
<h4>Team Members</h4> : <!-- Even smaller subheading -->
</body>
</html>
Welcome to My Website
About Us
OUTPUT
OUTPUT
Our Team
Team Members
Fig-8: Different levels of Headings in Html
To split a sentence into multiple lines a tag is used. If this tag is not used between 2 sentences and even you write the second sentence on a new line; html does not recognize this style and will put both the sentences in the same line, one after the other.
The code in Fig. 9 shows how you can setup your web page. The title of the page is between head tag-pair followed by the body and is shown on the browser's tab in the output. Note that everything written in the body is displayed on the webpage. Thereafter, you can assign suitable headings and paras, with necessary line breaks, as we applied in lines 7 and 8.
<html lang="en">
<head>
<title>Line Break Example</title>
</head>
<body>
<h1>Line Break Example</h1>
<p>This is the first line.<br>
Its 2nd line after line break.<br>
And here is the third line.</p>
</body>
</html>
OUTPUT
ˋ () Une Preak Example
+ + 0
(i) File
E/NBF/9th%20dass%20book/after%20pr
Line Break Example
This is the first line.
Its 2nd line after line break.
And here is the third line.
Fig-9: Line Break in Html
Span is used to provide style and arrangement to a line. For multiple lines you need to assign the <span> tag-pair on every line. Whereas, <div> provides the same effect to a set of lines present in the page. The style and classes, etc. are generally applied in the div tag-pair. The 'i' tag-pair is used for a sentence to be in italics, like a note. The <em> tagpair is for emphasis, whereas <b> and <strong> tag-pair are used for display of bold and strong characters. Frequently used tags are listed in Table 3-1.
Fig. 10 shows result of various text-tags, like "i" tag-pair used in line 7, "u" tag-pair for underline, etc.
<html lang="en">
<head>
<title>Text Styling</title>
</head>
<body>
<p><b>Bold text</b><p>...................> DON
<p><i>Italic text</i></p>
<p><u>Underlined text</u></p>
<p><em>Emphasized text</em></p>
<p><strong>Strong text</strong></p>
<p><sup>Superscript text</sup></p>
<p><sub>Subscript text</sub></p>
<p><small>Small text</small></p>.
</body>
</html>
v Text Styling
Text Styling
x
← →
→
C
(i) File
E/NBF/9th%20c
Bold text
Italic text
Underlined text
Emphasized text
Strong text
Superscript text
Subscript text
Small text
Fig-10: Text Tags
Teacher's Guide
W3Schools offers a thorough introduction to HTML which can help students understand the organization of static content by going deeper into the fundamental components of webpages.
(https://www.w3schools.com/ html/)
Table.3.1: List of Frequent Tags used in Text
| Tag-Pair | For the Task |
|---|---|
| p | Paragraph, sentence |
So, as you have observed so far, that HTML provides support for a document to be presentable just like a word-editor. Additionally, we can insert an image in the webpage by assigning the 'src' meaning the path where the file is located along with the name of the file, as shown in line 7 of Fig-11. The 'alt' parameter provides description of.the image. Additionally, the dimensions of the image can also be mentioned in terms of width and height of the image, otherwise it will load the image in its actual size.
<html lang="en">
<head>
<title>Image Tag Example</title>
</head>
<body>
<!-- Image Tag Exampie -->
<img src="html-logo.jpg" alt="Logo of HTML" width="300">
</body>
</html>
3.2.3.9 Bullets & Numbering
Html treats bullets and numbering in the form of an unordered <ul> and ordered list <ol>, respectively. Bullets can be of type circle, square or disc. The numbered list have the option of numerals and alphabets to choose from, just like a word-editor.
v<html lang="en">
v <head>
<title>List Items Example</title>
</head>
v <body>
<!-- Unordered List Example -->
<h3>Unordered List</h3>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<!-- Ordered List Example:-->
<h3>Ordered List</h3>
<ol>
<li>First Item</li>
<li>Second Item</li>
<li>Third Item</li>
</ol>
</body>
</html>
In Fig-12, form lines 8-12 an unordered list is described while in lines 14-18 ordered list is stated along with respective output.
Add 5 sentence using an undordered list such that odd-numbered sentences should be bold and even-numbered should be italicized.
Tables in HTML
Tables are a good way to enlist data which is visually appealing. Html provides 'table' tagpair to allocate and designate data within the table. In Fig-13 a table is created starting from line 7. Further 'tr' tag pair defines the row in a table, like on lines 8,13 and 18. The first row of the table is the header row and is generally used for headings and is defined with the 'th' tag-pair, as on lines 9-11. Whereas data is manipulated through 'td' tag-pair as on lines 14-16 and 19-21.
<html lang="en">
<head>
<title>Table Example</title>
</head>
<body>
<!-- Table structure -->
<table>
<tr>
<th>Student Name</th>
<th>Class</th>
<th>Fee Dues</th>
</tr>
<tr>
<td>Alia</td>
<td>9</td>
<td>200</td>
</tr>
<tr>
<td>Zia</td>
<td>9</td>
<td>0</td>
</tr>
</table>
</body>
</html>
Fig-13: Table of student records with Fee submitted.
Links are helpful components of a webpage, via which you can redirect to another webpage or a document. Links are called Hyperlinks in html with 'a' tag-pair. Hyperlinks are easy to identify on a webpage, as the mouse cursor changes as soon as the cursor touches a link element. Hyperlinks can be associated not only to text, but to images as well.
The general syntax for defining a links is like "<a href="url">link text</a>", where href refers to the address alongwith the path and link-text is for user information. Target is an optional parameter but its value defines where to open the webpage. If the value chosen is 'blank', it will open in a new tab or window; however for the value of 'self' the destination address will open in the same tab or window. Fig-14 depicts result of adding the following line of code in the body of the webpage:
<a href="https://www.nbf.org/" target="_blank">National Book Foundation </a>
v<html lang="en">
v <head>
<title>Link Tag Example</title>
</head>
v <body>
<!-- External Link -->
<a href="https://www.nbf.org.pk">Visit National Book Foundation</a>
<br>
<!-- Internal Link -->
<a href="Headings.html">Go to Headings HTML example</a>
</body>
</html>
✓ (›) Link Tag Example
← → C (1) File E/NBF/9th%20class%20book/aft
Visit National Book Foundation Go to Headings HTML example
Visit National Book Foundation Go to Headings HTML exampte
Fig-14: Adding a Resource Link in a webpage
| b |
| To make characters bold |
| i | Text is shown in italics |
| em | When you need to emphasize a word but with italics. |
| strong | When emphasize a word but with bold |
| sup | Superscript, helpful in formula and footnotes |
| sub | Subscript, helpful in formula and footnotes |
| u | Underline a text |
| small | Smaller text size, like footnote |