CSE 205 Lesson 2
CSE 205 Lesson 2
What is HTML?
HTML is the language in which most websites are written. HTML is used to create
pages and make them functional.
HTML full form is HyperText Markup Language.
• Hypertext: Hypertext means that the document contains links that allow the
reader to jump to other places in the document or to another document
altogether. Apart from text, hypertext may contain HTML tables, HTML
lists, HTML forms, HTML images, etc.
• Markup language: Markup language uses tags to define elements within a
document. It contains familiar words that are human-readable
like forms, tables, links, titles, etc. Every tag in a markup language has a special
meaning of its own and performs a particular operation.
The History of HTML
• Sir Tim Berners-Lee developed HTML in late 1989, and he is considered as the
Father of HTML.
• In 1996, the World Wide Web Consortium (W3C) became the authority to
maintain the HTML specifications.
• HTML became an international standard (ISO) in 2000.
Features of HTML
There are various features of HTML, but in this HTML tutorial, we will discuss the most
important ones.
• HTML describes the structure of a webpage.
• Human-readable HTML tags represent elements in a webpage. Hence, they are
easy to remember.
• HTML is universally supported by all browsers. It is a standard markup language
for website development.
• HTML 5 can give support in enhancing the experience in gaming arena.
• It is easy to learn and implement. You can quickly learn HTML programming in a
few days and create your first web page.
• It is platform independent, i.e., it works on all the operating systems.
HTML 1991
XHTML 2000
HTML 5 2014
First Program:
<!DOCTYPE html>
<html lang="en">
<HTML>
<head>
<title> Page Title </title>
</head>
<body>
<h1> This is a Heading </h1>
<p> This is a Paragraph </p>
</body>
</html>
Output
This is a Heading
This is a Paragraph
What is HTML Tag?
HTML Tags are pre-defined elements in HTML, enclosed within these < > signs. For
example: <html>, <table>, etc. All HTML tags have a particular work associated with them.
Each one has a special function and a combination of various tags forms a website. For
example, a <p> tag defines a paragraph in the website and a <table> tag displays a table.
All HTML Tags are predefined, i.e., you cannot make HTML tags by yourself. Look at the
example below, this is an example of a paired tag. Observe that there are two tags of same
name, but the latter one has a slash / before it, it is a closing tag. Now, what is a closing
tag? Let's start with different types of tags!
Paired Tags
Paired tags are a set of two tags with the same name. In each Paired tag set, one is an
opening tag, and the other one is the closing tag. The closing tag has a / slash, it means
that the tag is closed now.
It is necessary to close a paired tag; otherwise, it can result in the malfunctioning of the
website. When the content is written within paired tags, then it ensures that the effect of
those tags would be limited to only the content between them.
Look at the list of some paired tags in HTML below. Notice that each tag has a closing tag
with a slash(/) before the name of the tag.
<html> </html>
<table> </table>
Open Tag Close Tag
<form> </form>
<span> </span>
<ul> </ul>
<p> </p>
<head> </head>
<div> </div>
Look below the list of some Unpaired Tags in HTML. Notice the use of slash(/) in the tags,
to close them.
Open Tag
<br>
<hr>
Open Tag
<meta>
<input>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Heading Tag </title>
</head>
<body>
<h1> This is Heading 1 </h1>
<h2> This is Heading 2 </h2>
<h3> This is Heading 3 </h3>
<h4> This is Heading 4 </h4>
<h5> This is Heading 5 </h5>
<h6> This is Heading 6 </h6>
</body>
</html>
Output
This is Heading 1
This is Heading 2
This is Heading 3
This is Heading 4
This is Heading 5
This is Heading 6
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Paragraph Tag </title>
</head>
<body>
<p> This is First Paragraph </p>
<p> This is Second Paragraph </p>
<p> This is Third Paragraph </p>
</body>
</html>
Output
This tag is called anchor tag and anything between the opening <a> tag and the
closing </a> tag becomes part of the link, and a user can click that part to reach to the linked
document.
<!DOCTYPE html>
<HTML lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Anchor Tag </title>
</head>
<body>
<a target="_blank" href="https://www.google.com"> This is a link </a>
</body>
</html>
Output
This is a link
Note: Use 'target = _blank' as an attribute in <a> tag to open the link in a new tab.
The 'alt' attribute is used as an alternative in a case if the image is not shown. Anything
written as a value of this attribute will be displayed. It will give information about the image.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Image Tag </title>
</head>
<body>
<img src="HTML-Image.png" width="400px" height="200px">
</body>
</html>
Output
HTML Attributes
HTML attribute defines the characterstics of any HTML element. These attributes provide
additional information to the browser about the element like, its size, color, behaviour, etc.
If a browser cannot find an image, it will display the value of the alt attribute :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Image Alt Attribute </title>
<body>
<img src="HTML-Image.png" alt="HTML5 Image" style="width:400px; height:250px;">
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Inline Styles </title>
</head>
<body>
<h4 style="color:green"> This is Green Color </h4>
<h4 style="color:blue"> This is Blue Color </h4>
</body>
</html>
Output
All the formatting tags are paired tags. Anything written between any formatting tag will be
displayed according to the tag in the browser. For example, anything written
between <i> and </i> will display as italic text in the browser.
There are different tags for various formatting tags. Each Tag has its own type of formatting
associated with it.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Bold Text </title>
</head>
<body>
<p> This is Normal text. </p>
<b> This is Bold Text. </b>
</body>
</html>
Output
This is normal text.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Strong Text </title>
</head>
<body>
<p> This is Normal text </p>
<strong> This Text is Strong </strong>
</body>
</html>
Output
This is Normal text
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Italic Text </title>
</head>
<body>
<p> This is normal text </p>
<i> This is italic Text </i>
</body>
</html>
Output
This is normal text
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Underlined Text </title>
</head>
<body>
<p> This is Normal text </p>
<u> This is Underlined Text </u>
</body>
</html>
Output
This is Normal text
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Small Text </title>
</head>
<body>
This text is <small> small </small>.
</body>
</html>
Output
This text is small .
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Big Tag </title>
</head>
<body>
This text is <big> BIG </big>
</body>
</html>
Output
This text is BIG
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Mark Tag </title>
</head>
<body>
This text is <mark> Marked. </mark>
</body>
</html>
Output
This text is Marked.
HTML Emphasized Text
The HTML <em> element defines Emphasized text. It will give the text the same Italic
formatting. This tag is important for screen readers. The screen readers give extra
emphasize on this type of text and read it with verbal stress.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Emphasize Text </title>
</head>
<body>
This text is Normal.
This text is <em> Emphasized. </em>
</body>
</html>
Output
This text is Normal.
This text is Emphasized.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Delete Text </title>
</head>
<body>
<p> This text is Normal. </p>
This text is <del> Deleted. </del>
</body>
</html>
Output
This text is Normal.
This text is
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Subscript Text </title>
</head>
<body>
This text is <b> bold. </b>
This text is <i> italic. </i>
This text is <sup> Subscripted. </sup>
</body>
</html>
Output
This text is bold.
This text is italic.
This text is Subscripted.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Superscript Tag </title>
</head>
<body>
This text is <b> bold. </b>
This text is <i> italic. </i>
This text is <sup> Superscripted.
</body>
</html>
Output
A <p> tag is very important tag, as all the content written on a website needs to get
formatted in the form of paragraphs. Browsers automatically add blank lines above and
below a paragraph to seaprate it from other content or othe paragraphs on the page.
HTML Paragraphs are block level elements, i.e., a new paragraph will always start from a
new line. Also, Paragraph tags gets automatically closed if another block-element gets
parsed before the </p> tag.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Paragraph Tag </title>
</head>
<body>
<p> This is First Paragraph </p>
<p> This is Second Paragraph </p>
<p> This is Third Paragraph </p>
</body>
</html>
Output
The <pre> tag is also a paired tag. It can be used when you want to display a certain amount
of text with preformatted spaces and line breaks. For example, to display a block of code of
a programming language or to display a poem with proper line breaks.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Pre Tag </title>
</head>
<p>The pre tag preserves both spaces and line breaks:</p>
<pre>
This is a Paragraph Tag.
This is a Paragraph Tag.
This is a Paragraph Tag.
This is a Paragraph Tag.
</pre>
</body>
</html>
Output
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Change Link Color </title>
</head>
<body alink="green" vlink="red">
<p> Click following link </p>
<a href="https://google.co.in/"> Welcome to Google </a>
</body>
</html>
Welcome to Google
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Image Tag </title>
</head>
<body>
<img src="HTML-Image.png" width="400px" height="200px">
</body>
</html>
Output
HTML Table
We all are familiar with the concept of table, we are not talking about the numeric tables
here, the HTML table we are going to learn is the one with rows and column. It’s similar
like the structure of a matrix with proper rows and columns. This type of structure with
rows and columns is very helpful in representing data in an easy and simple manner.
The tabular form of data creates a good expression wherever it is used due to its
representation of necessary data in a simple and accurate manner.
Tables are also used in websites to present any data to the user. It looks really neat and
also everyone prefers tabular form of data nowadays. The HTML tables allows to
arrange data like text, images, etc. into rows and columns.
Example :
HTML Table
We all are familiar with the concept of table, we are not talking about the numeric tables
here, the HTML table we are going to learn is the one with rows and column. It’s similar
like the structure of a matrix with proper rows and columns. This type of structure with
rows and columns is very helpful in representing data in an easy and simple manner.
The tabular form of data creates a good expression wherever it is used due to its
representation of necessary data in a simple and accurate manner.
Tables are also used in websites to present any data to the user. It looks really neat and
also everyone prefers tabular form of data nowadays. The HTML tables allows to
arrange data like text, images, etc. into rows and columns.
Example :
<!DOCTYPE html>
<html lang="en">
<HTML>
<head>
<meta charset="UTF-8">
<title> HTML Table </title>
</head>
<body>
<table>
<tr>
<th> Name </th>
<th> Salary </th>
<th> Age </th>
</tr>
<tr>
<td> Anshuman </td>
<td> Rs. 2,00,000 </td>
<td> 25 </td>
</tr>
<tr> <td> Kuldeep </td>
<td> Rs. 5,00,000 </td>
<td> 22 </td>
</tr>
</table> </body>
</html>
Output:
Table 1
Table Row
A table row can be defined with the <tr> tag It is also a paired tag with </tr> as a closing
tag. Whatever written between these tags will be displayed in a single row of the table.
To create a new row another <tr> tag is written after closing the previous one.
Table heading
A table header in HTML tables is a special case of a table row. It starts with <th> tag and
ends with </th> tag. There only difference between a row and a heading is that text
written inside <th> tags is displayed in bold fonts and is by default centered aligned by
the browser. Because of its properties this tag is used only for writing Heading of the
table. You can also make a <tr> tags content bold and centered by using CSS It will
work exactly like <th> tag.
Table Cells
A table cell in an HTML table is defined by <td> tag. It is also a paired tag with </td> as a
closing tag. Each pair of these tags represents a cell in a row. It is used
inside &glt;tr> tags only. Without <tr> tags it is of no value. After declaring the rows
the <td> tags are used to enter data in the table. Whatever is written inside
the <td> and </td> tags will be displayed by the browser in the tables as it is.
Table Attributes
The <table> Tag in HTML table has many attributes which can be used to further define
the structure of the table than just a standard one. These attributes can make a table
look a bit more attractive. Let’s see one by one the different attributes of the table tag
and then we will use them in an example and will see the changes in the table.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Table Border Attribute </title>
</head>
<body>
<table border="1" width="100%">
<tr>
<th> Name </th>
<th> Salary </th>
<th> Age </th>
</tr>
<tr>
<td> Anshuman </td>
<td> Rs. 2,00,000 </td>
<td> 25 </td>
</tr>
<tr>
<td> Kuldeep </td>
<td> Rs. 5,00,000 </td>
<td> 22 </td>
</tr>
</table>
</body>
</html>
Output:
Table 2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Table Border Style </title>
<style>
table, th, td {
border: 1px solid black;
text-align: center;
}
</style>
</head>
<body>
<table width="100%">
<tr>
<th> Name </th>
<th> Salary </th>
<th> Age </th>
</tr>
<tr>
<td> Anshuman </td>
<td> Rs. 2,00,000 </td>
<td> 25 </td>
</tr>
<tr>
<td> Kuldeep </td>
<td> Rs. 5,00,000 </td>
<td> 22 </td>
</tr>
</table>
</body>
</html>
Output
Table 3
Cellpadding attribute
The Cellpadding attribute is used to specify the space between the content of the cell
and its borders. It provides padding to the content of the cell. As its value increases the
space between the cell’s content and its border is also increases. The value of this
attribute is taken in pixels by the browser. The cellpadding is applied to all the four sides
of the content. The value can also be defined in percentages.
Cellspacing attribute
The Cellspacing attribute is used to specify the space between the cells of the table. Its
value can be in pixels or in percentages. It works similar to the Cellpadding attribute but
only between cells. It is applied to all the sides of the cells.
Note: These two attributes defined above are no longer a part of HTML 5. So it is better
to use CSS to color the tables.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Table Cellpadding Attribute </title>
</head>
<body>
<table border="1" cellpadding="5" cellspacing="5" style="width:100%">
<tr>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>Peter</td>
<td>5000</td>
</tr>
<tr>
<td>John</td>
<td>7000</td>
</tr>
</table>
</body>
</html>
Output
Table 4
Name Salary
Peter 5000
John 7000
The 'Rowspan'
The rowspan attribute is used to merge two or more rows together to form a single row. A
single row occupies space of the number of merged rows.
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
</style>
</head>
<body>
<h2>Cell that spans two rows:</h2>
<table style="width:100%">
<tr>
<th>Name:</th>
<td>Bill Gates</td>
</tr>
<tr>
<th rowspan="2">Telephone:</th>
<td>9998887776</td>
</tr>
<tr>
<td>9998887776</td>
</tr>
</table>
</body>
</html>
OUTPUT
Table 5
Person_Name Mobile
Bill Gates 9998887776 9998887775
HTML Caption
To add a caption to a table, use the <caption> tag.
• A caption can be aligned around the table by using align attribute with values -
left/right/top/bottom.
• The default alignment is top.
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Table Colspan Attribute </title>
</head>
<body>
<table border="1" width="80%">
<tr>
<th> Person_Name </th>
<th colspan="2"> Mobile </th>
</tr>
<tr>
<td> Bill Gates </td>
<td> 9998887776 </td>
<td> 9998887775 </td>
</tr>
</table>
</body>
</html>
Table 6
Monthly savings
Month Savings
January $100
February $50
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Font Size </title>
</head>
<body>
<font size="1">Hello HTML 5!</font>
<font size="2">Hello HTML 5!</font>
<font size="3">Hello HTML 5!</font>
<font size="4">Hello HTML 5!</font>
<font size="5">Hello HTML 5!</font>
<font size="6">Hello HTML 5!</font>
<font size="7">Hello HTML 5!</font>
</body>
</html>
Output:
Hello HTML 5!
Hello HTML 5!
Hello HTML 5!
Hello HTML 5!
Hello HTML 5!
Hello HTML 5!
Hello HTML 5!
The Font Face
You can set font face using 'face' attribute but be aware that if the user viewing the page
doesn't have the Font installed, they will not see it. Instead, the user will see the default
font style.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML Font Face Attribute </title>
</head>
<body>
<font face="Times New Roman" size="5">Times New Roman</font>
<font face="Verdana" size="5">Verdana</font>
<font face="Comic sans MS" size="5">Comic Sans MS</font>
<font face="WildWest" size="5">WildWest</font>
<font face="Bedrock" size="5">Bedrock</font>
</body>
</html>
Output:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Font Face Alternative Attribute </title>
</head>
<body>
<font face="Times New Roman,Verdana,Comic sans MS,WildWest" size="5">Times New
Roman</font><br />
<font face="Lucida Calligraphy,Comic Sans MS,Lucida Console" size="5">Bedrock</font>
</body>
</html>
Output:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML Font Color</title>
</head>
<body>
<font color="#69C">This text is in Blue</font><br />
<font color="green">This text is Green</font>
</body>
</html>
Ex.-For a numbered order list, the numbering starts at one and is incremented by one
for each successive ordered list element tagged with <li>.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Ordered List </title>
</head>
<body>
<h2>HTML Ordered list</h2>
<ol>
<li>Audi</li>
<li>Mercedes</li>
<li>Lamborghini</li>
</ol>
</body>
</html:>
Output
1. Audi
2. Mercedes
3. Lamborghini
Value Description
type="I" The list items will be numbered with uppercase roman numbers.
type="i" The list items will be numbered with lowercase roman numbers.
List of Numbers
Numbers as type - <ol type="1">. Here the numbers will be used to order the elements.
Each new element will get incremented value from the previous one in the list.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Ordered List </title>
</head>
<body>
<h2>HTML Ordered list</h2>
<ol>
<li>Audi</li>
<li>Mercedes</li>
<li>Lamborghini</li>
</ol>
</body>
</html>
OUTPUT:
1. Audi
2. Mercedes
3. Lamborghini
Uppercase
Uppercase alphabets as type - <ol type="A">. Here, Uppercase alphabets will be used to
order the elements.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Ordered List Uppercase </title>
</head>
<body>
<ol type="A">
<li>Audi</li>
<li>Mercedes</li>
<li>Lamborghini</li>
</ol>
<ol type="a">
<li>Audi</li>
<li>Mercedes</li>
<li>Lamborghini</li>
</ol>
<ol type="I">
<li>Audi</li>
<li>Mercedes</li>
<li>Lamborghini</li>
</ol>
Output:
A. Audi
B. Mercedes
C. Lamborghini
a. Audi
b. Mercedes
c. Lamborghini
I. Audi
II. Mercedes
III. Lamborghini
li. Audi
lvi. Mercedes
lvii. Lamborghini
Look at the example below to understand how to use HTML Unordered List:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Unordered List </title>
</head>
<body>
<h2> Unordered List </h2>
<ul>
<li>Audi</li>
<li>Mercedes</li>
<li>Lamborghini</li>
</ul>
</body>
</html>
Output
• Audi
• Mercedes
• Lamborghini
Value Description
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Unordered List Disc Attribute </title>
</head>
<body>
<h2> Unordered List </h2>
<ul type="disc">
<li> BMW </li>
</ul>
<ul type="circle">
<li> BMW </li>
<ul type="square">
<li> BMW </li>
<ul type="none">
<li> BMW </li>
</body>
</html>
OUTPUT
• BMW
o BMW
▪ BMW
BMW