HTML Notes
HTML Notes
The HTML table tag (<table>) is used to represent data in a structured way by creating a table.
For example,
<tr>
<th>Name</th>
<th>Age</th>
<th>Country</th>
</tr>
<tr>
<td>Harry Depp</td>
<td>28</td>
<td>Britain</td>
</tr>
<tr>
<td>John Smith</td>
<td>35</td>
<td>USA</td>
</tr>
<tr>
<td>Ram Krishna</td>
<td>19</td>
<td>Nepal</td>
</tr>
</table>
Browser Output
<table>
….
<table>
<tr>
<th>Name</th>
<th>Country</th>
</tr>
<tr>
Browser Output
In the above example, Item and Count are table headers and they are used to
represent the category of data in a particular row.
Here, the styling of the table headers is bold and center-aligned. This is
because the <th> tag has some default styling.
The <td> tag is used to define table cells (data). The table cells store data to be
displayed in the table. For example,
<tr>
<td>Apple</td>
<td>Mango</td>
<td>Orange</td>
</tr>
Table cells are generally inside the table row or table headers.
Table Border
<table border="1">
...
</table>
In HTML, the border attribute is used to add a border to a table and all the
cells.
The colspan attribute merges cells across multiple columns. For example,
<table>
<tr>
<th>S.N</th>
<th>Item</th>
<th>Quantity</th>
</tr>
<tr>
<td>1</td>
<td>Apple</td>
<td>2</td>
</tr>
<tr>
<td>2</td>
<td>Mango</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>Orange</td>
<td>1</td>
</tr>
<tr>
<td colspan="2">Total</td>
<td>5</td>
</tr>
</table>
Browser Output
In the above example, you can see that the last row only has 2 cells with one
cell occupying 2 columns.
The value of the colspan attribute determines how many columns the cell
occupies.
Rowspan
The rowspan attribute merges cells across multiple rows. For example,
<table>
<tr>
<th>Name</th>
<th>Subject</th>
<th>Marks</th>
</tr>
<tr>
<td>English</td>
<td>67</td>
</tr>
<tr>
<td>Maths</td>
<td>82</td>
</tr>
<tr>
<td>Science</td>
<td>91</td>
</tr>
</table>
Browser Output
HTML Lists
HTML lists are used to display related information in an easy-to-read and concise way as
lists.
We can use three types of lists to represent different types of data in HTML:
Unordered List <ul>
Unordered List
The unordered list is used to represent data in a list for which the order of items does not
matter.
In HTML, we use the <ul> tag to create unordered lists. Each item of the list must be a
<li> tag which represents list items. For example,
<ul>
<li>Apple</li>
<li>Orange</li>
<li>Mango</li>
</ul>
Browser Output
Ordered List
The ordered list is used to represent data in a list for which the order of items has
significance.
The <ol> tag is used to create ordered lists. Similar to unordered lists, each item in the
ordered list must be a <li> tag. For example,
ol>
<li>Ready</li>
<li>Set</li>
<li>Go</li>
</ol>
Browser output
Description List
The HTML description list is used to represent data in the name-value form.
We use the <dl> tag to create a definition list and each item of the description
list has two elements:
<dl>
<dt>HTML</dt>
<dt>CSS</dt>
<dd>Cascading StyleSheets</dd>
<dt>JS</dt>
<dd>Javascript</dd>
</dl>
Browser Output
Tags used in HTML lists
Tag Explanation
We use the HTML unordered list to define a list where the sequence or order of the list items
doesn't matter. We can use an unordered list for keeping track of groceries, supplies and
random objects.
In HTML, we use the <ul> tag to create an unordered list. For example,
<ul>
<li>Apple</li>
<li>Mango</li>
<li>Orange</li>
<li>Banana</li>
</ul>
Browser Output
Each item of the list is enclosed inside the <li> tag and they are represented by the dot bullet
point symbol.
By default, the symbol to represent an unordered list in HTML is a dot bullet point, however, we
can change them as per our choice.
Nesting Lists
In HTML, we can create a nested list by adding one list inside another. For example,
<ul>
<li>
Coffee
<ul>
<li>Cappuccino</li>
<li>Americano</li>
<li>Espresso</li>
</ul>
</li>
<li>
Tea
<ul>
<li>Milk Tea</li>
<li>Black Tea</li>
</ul>
</li>
<li>Milk</li>
</ul>
Browser Output
We use the HTML ordered list to define a list where the sequence or order of
the list items is important. We can use the HTML ordered list for recipes,
algorithms, top ten lists, and so on.
<li>Name</li>
<li>Address</li>
<li>Phone Number</li>
</ol>
Browser Output
Each item of the list is enclosed inside the <li> tag and they are numbered by decimal numbers.
By default, ordered lists are ordered by numbers, however, we can change them as per our
choice.
We use the type attribute to change the marker for the list. There are five
types of numbering in the ordered list. They are
Type Description
start Attribute
We use the start attribute to change the starting point for the numbering of the list. For example,
<ol start='5'>
<li>Harry</li>
<li>Ron</li>
<li>Sam</li>
</ol>
Browser Output
Nesting Lists
In HTML, we can create a nested list by adding one list inside another. For example,
<ol type="I">
<li>
Chapter 1
<ol type="a">
<li>Lesson 1</li>
<li>Lesson 2</li>
</ol>
</li>
<li>
Chapter 2
<ol type="a">
<li>Lesson 1</li>
<li>Lesson 2</li>
<li>Lesson 3</li>
</ol>
</li>
<li>
Chapter 3
<ol type="a">
<li>Lesson 1</li>
</ol>
</li>
</ol>
Browser Output
HTML Description List
We use the HTML description list to create a list where list items include terms and descriptions
of the term.
In HTML, we use the <dl> tag to create a description list. For example,
<dl>
<dt>HTML</dt>
<dt>CSS</dt>
</dl>
Browser Output
<p>
</p>
Browser Output
HTML Links
HTML links or hyperlinks connect one resource on the web to another. The resource may be an
image, a web page, a program, a video clip, an audio clip, an element within a web page, etc, or
anything that can be hosted on the internet.
We use the HTML <a> tag to create hyperlinks. The syntax for the <a> tag is
Here,
Clicking on the text will navigate you to the resource in the URL
For example,
Browser Output
Here, clicking on the Swift Continue Statement will take you to
https://www.programiz.com/swift-programming/continue-statement.
target Attribute
By default, any link clicked will open in the same browser window. This may
lead to a bad user experience. This is where the target attribute becomes
useful. For example,
<a href="https://www.programiz.com" target="_blank">Programiz</a>
We use the target attribute to specify where the link is opened. The target
attribute has 4 values.
Target Description
_top Opens the link in the current tab window (topmost parent).
Here, clicking on this link will scroll the web page to the element with the id of title
Here, clicking on this link will take us to the URL programiz.com/html/head and then scroll to the
element with the id title-tag.
Email
We can also use HTML links as email links and call links to help users contact us or someone
else using their email client or call app.
Email links:
The email link opens the user's default mail client to make it easier for the user to send mail to a
specific address. For example,
Browser Output
HTML Images
The HTML <img> tag embeds an image within the HTML web page. For example,
<img src="logo.png">
Browser Output
Here, the <img> tag inserts the image logo.png on the webpage.
Note: The <img> tag is an empty tag, i.e. It doesn't require a closing tag.
Browser Output
In the above example, the src attribute tells the browser to load the image from the same
directory where the webpage is located.
Similarly, if the image is stored in a subdirectory, the path in the src attribute would be written as
If the image is located on another server entirely or if we want to use an image from the web, we
can provide an absolute URL for the image. For example,
<img src="https://www.example.com/images/tictactoe.png">
Browser Output
The alt attribute's contents are shown if the user cannot view the image (slow internet, wrong
src attribute, or using a screen reader).
We can use the style attribute to specify the height and width of an Image. For example,
Alternatively, we can also use the height and width attributes to set the height and width. For
example,
Browser Output
We should always set the height or width of images. Otherwise when the image loads, the
content on the webpage will be shifted.
HTML Bold
We use the HTML <b> tag or the HTML <strong> tag to make text bold. For example,
<br>
Browser Output
HTML Italic
We use the HTML <i> tag or the HTML <em> tag to make the text italic.
The HTML <i> tag is a physical tag used to make the text italic. It is used to indicate foreign text,
scientific nomenclature, thoughts, etc.
<p> This text is <i>italic</i>.</p>
Browser Output
Browser Output
The HTML <sup> tag is used to create superscript text. The text inside the <sup> tag is
rendered half a character above the normal line and has a smaller font size. For example,
Browser Output
Usage of Superscript
Superscript text is generally used for exponents, measurement units, and ordinal numbers. For
example,
1. Superscript in exponents
Browser Output
Browser Output
Browser Output
Subscript
The HTML <sub> tag is used to create subscript text. The text inside the <sub> tag is rendered
half a character below the normal line and has a smaller font size. For example,
<p> This is a <sub>Subscript</sub> text.</p>
Browser Output
Usage of Subscript
Superscript text is generally used for mathematics and chemical formulas. For example,
Browser Output
Browser Output
The HTML <b> is a physical tag used to simply make text bold.
Browser Output
The HTML <u> tag is a physical tag used to make the text underlined.
Browser Output
Browser Output
The HTML <ins> tag is a semantic tag used to represent that the text has been inserted in the
document. The <ins> tag generally follows some deleted text.
Browser Output
The HTML <big> tag is a physical tag used to make text one font size larger than the
surrounding text.
Browser Output
The HTML <small> tag is a physical tag used to make text one font size smaller than the
surrounding text.