Unit 2
Unit 2
Advantage of HTML:
Create Web site - You can create a website or customize an existing web
template if you know HTML well.
Become a web designer - If you want to start a career as a professional web
designer, HTML and CSS designing is a must skill.
Understand web - If you want to optimize your website, to boost its speed
and performance, it is good to know HTML to yield best results.
Learn other languages - Once you understand the basic of HTML then other
related technologies like javascript, php, or angular are become easier to
understand.
2
Output:
Applications of HTML
Web pages development - HTML is used to create pages which are rendered
over the web. Almost every page of web is having html tags in it to render its
details in browser.
Internet Navigation - HTML provides tags which are used to navigate from
one page to another and is heavily used in internet navigation.
Responsive UI - HTML pages now-a-days works well on all platform,
mobile, tabs, desktop or laptops owing to responsive design strategy.
Offline support HTML pages once loaded can be made available offline on
the machine without any need of internet.
3
Game development- HTML5 has native support for rich experience and is
now useful in gaming development arena as well.
Structure of HTML Document:
The first line of every HTML document is DOCTYPE i.e. DOCTYPE is declared at
the beginning of html document which specifies document type to be HTML and
helps the browser to display a webpage correctly. DOCTYPE stands for document
type and tells the browser which version of HTML we are using. HTML is not case
sensitive so all cases are accepted but we will use small case.
Syntax:
<!DOCTYPE html> : For html 5
After DOCTYPE, html documents must include the four tags <html>, <head>
<title> and <body>.
The <html> tag identifies the root element of the document and must be close at the
end of document by </html>. The html element includes an attribute “lang” which
specifies the language in which the document is written as shown below:
<html lang = “en”> where en means English.
After html tag, a html documents contains two parts head and body. The head
element provides information about the document but does not provide its content.
It always contains two elements, one is title element which is used to provide title
for document and is define by <title> tag.
Another is meta element which is used to provide additional information about
document. The meta element has no content but provides information through its
attribute. The charset attribute specifies the character encoding for the HTML
document. The HTML5 specification encourages web developers to use the UTF-8
(UTF-8 (Universal Character Set + Transformation Format—8-bit) is a character
encoding; capable of encoding all possible characters (called code points) in
Unicode. The encoding is variable-length and uses 8-bit code units.) character set,
which covers almost all of the characters and symbols in the world!
4
<head>
<title> this is html document </title>
<meta charset = “utf- 8” />
</head>
The body of the document provides the content of the documents and is specified by
<body> tag.
Complete syntax for structure of html document:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h2>This is the heading section</h2>
</body>
</html>
In above example, the DOCTYPE defines the document type to be HTML. The text
between <html> and </html> describes an HTML documents. The text between
<head> and </head> provides information about the documents. The text between
<title> and </title> provide title for the document and display at the top of the page.
The text between <body> and </body> describes the visible page content. The text
between <h1> and </h1> describes heading.
have been haphazardly written. The second problem with HTML 4.0 is that its
specification does not define how a user agent (HTML processor or browser) is to
recover when erroneous code is encountered because every browser uses its own
variation of error recovery. HTML author have high degree of freedom to use their
own syntactic preference to create documents. But this freedom will lack in
consistency both in low level syntax and in overall structure.
XHTML stands for Extended Hyper Text Mark Up Language based on XML have
three standards: strict, transitional and frame set. Strict syntactic rule of XHTML
imposed a consistent structure on all XHTML document. Strict syntactic rule implies
that all the syntax should be written without mistake i.e. all tags should be properly
closed, all attributes should be properly enclosed, all nested should be done properly
and all the empty tags should be closed properly.
For example:
<!DOCTYPE html>
<html>
<head>
<title> this is html document </html>
<meta charset = “utf- 8” />
</head>
<body>
<h1> this is heading one
<p> this is first paragraph
<br>
<img src = “[Link]” alt = “my text”>
</body>
6
</html>
In above example, the syntax for heading, paragraph, image and break is incorrect
because tags are not closed properly but the output is generated or displayed if
HTML is used. If XHTML is used then the above code will generate error because
strictness of code in XHTML needs every tag to be closed properly. All the tags and
attribute are required to be written in lower case in XHTML.
Tag Content
Types of Tags:
Empty tag/ Singular Tags:
In this kind of tags in which there is no any content and are closed in single tag. For
example:
7
For example:
<html>
<head> </head>
<body>
<h1> this is heading 1 </h1>
<h2> this is heading 2 </h2>
element
</body>
</html>
Heading Tags
Any document starts with a heading. You can use different sizes for your headings.
HTML also has six levels of headings, which use the elements <h1>, <h2>, <h3>,
<h4>, <h5>, and <h6>. While displaying any heading, browser adds one line before
and one line after that heading.
Paragraph Tag
The <p> tag offers a way to structure your text into different paragraphs. Each
paragraph of text should go in between an opening <p> and a closing </p> tag.
8
Whenever you use the <br /> element, anything following it starts from the next
line. This tag is an example of an empty element, where you do not need opening
and closing tags, as there is nothing to go in between them.
The <br /> tag has a space between the characters br and the forward slash. If you
omit this space, older browsers will have trouble rendering the line break, while if
you miss the forward slash character and just use <br> it is not valid in XHTML.
Centering Content
You can use <center> tag to put any content in the center of the page or any table
cell.
Horizontal Lines
Horizontal lines are used to visually break-up sections of a document. The <hr> tag
creates a line from the current position in the document to the right margin and
breaks the line accordingly.
The <hr /> element has a space between the characters hr and the forward slash. If
you omit this space, older browsers will have trouble rendering the horizontal line,
while if you miss the forward slash character and just use <hr> it is not valid in
XHTML.
Preserve Formatting
Sometimes, you want your text to follow the exact format of how it is written in the
HTML document. In these cases, you can use the preformatted tag <pre>.
Any text between the opening <pre> tag and the closing </pre> tag will preserve
the formatting of the source document.
Nonbreaking Spaces
9
Suppose you want to use the phrase "I am a hunter" Here, you would not want a
browser to split the "I, am, a, and hunter" across two lines.
In cases, where you do not want the client browser to break text, you should use a
nonbreaking space entity instead of a normal space.
Example: Demonstration of some commonly used html tags
<!DOCTYPE html>
<html>
<head>
<title>Tags Example</title>
</head>
<body>
<h1>Heading Tags</h1>
<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>
<h1>Paragraph Tags</h1>
<p>This is paragraph</p>
<h1>Centering Tags</h1>
<center>
<h2>Im center tag :)</h2>
</center>
<pre>
*****
****
***
**
*
</pre>
</body>
</html>
Character Entities:
HTML provides collection of special characters that are sometimes needed in a
document but cannot be typed as themselves.
HTML Attributes:
We have seen few HTML tags and their usage like heading tags <h1>,
<h2>, paragraph tag <p> and other tags. We used them so far in their simplest form,
but most of the HTML tags can also have attributes, which are extra bits of
information.
An attribute is used to define the characteristics of an HTML element and is placed
inside the element's opening tag. All attributes are made up of two parts −
a name and a value
The name is the property you want to set. For example, the
paragraph <p> element in the example carries an attribute whose name
is align, which you can use to indicate the alignment of paragraph on the page.
The value is what you want the value of the property to be set and always put
within quotations. The below example shows three possible values of align
attribute: left, center and right.
20
Attribute names and attribute values are case-insensitive. However, the World Wide
Web Consortium (W3C) recommends lowercase attributes/attribute values in their
HTML 4 recommendation.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Align Attribute Example</title>
</head>
<body>
<p align = "left">This is left aligned</p>
<p align = "center">This is center aligned</p>
<p align = "right">This is right aligned</p>
</body>
</html>
Global Attributes
There are few HTML attributes which are standard and associated to all the HTML
tags. These attributes are called Global Attributes.
These are not valid in base, head, html, meta, script, style, and title elements.
Element Description
name
<b> This is a physical tag, which is used to bold the text written between it.
<strong> This is a logical tag, which tells the browser that the text is important.
<tt> This tag is used to appear a text in teletype. (not supported in HTML5)
<big> This tag is used to increase the font size by one conventional unit.
<small> This tag is used to decrease the font size by one unit from base font size.
Block elements appear on the screen as if they have a line break before and after
them. For example, the <p>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <ul>, <ol>,
<dl>, <pre>, <div>,<hr />, <blockquote>, and <address> elements are all block level
elements. They all start on their own new line, and anything that follows them
appears on its own new line.
25
<div>
The HTML division tag, called "div" for short, is a special element that lets you
group similar sets of content together on a web page. You can use it as a generic
container for associating similar content.
The <div> tag is used as a container for HTML elements which is then styled with
CSS or manipulated with JavaScript. The <div> tag is easily styled by using the class
or id attribute. Any sort of content can be put inside the <div> tag!
Note: By default, browsers always place a line break before and after
the <div> element.
Syntax:
<div>
Html elements
</div>
List Tags:
List tags are used to display the content in list view. There are some lists tags as:
An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.
The list items will be marked with bullets (small black circles) by default:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
26
</head>
<body>
<ul>
<li>Web Tech</li>
<li>Math</li>
<li>DBMS</li>
<li>English</li>
</ul>
</body>
</html>
Output:
Ordered List:
An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.
</ol>
</body>
</html>
Output:
Description List:
</html>
Output:
Hyperlink Tag:
A webpage can contain various links that take you directly to other pages and even
specific parts of a given page. These links are known as hyperlinks.
Hyperlinks allow visitors to navigate between Web sites by clicking on words,
phrases, and images. Thus you can create hyperlinks using text or images available
on a webpage.
A link is specified using HTML tag <a>. 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. Following is the simple
syntax to use <a> tag.
Syntax: <a href="Document URL" ... attributes-list>Link Text</a>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body link="red" alink="yellow" vlink="blue">
<a href="[Link] target="_self">Google</a>
</body>
</html>
29
Option Description
_blank Opens the linked document in a new window or tab.
_self Opens the linked document in the same frame.
_parent Opens the linked document in the parent frame.
_top Opens the linked document in the full body of the window.
In HTML 5 applet is not support so instead of that embed, object, video, audio tags
are used to implement multimedia files and other applications in html page.
<embed>
The <embed> tag in HTML is used for embedding external applications which are
generally multimedia content like audio or video, web pages, pictures, or plug-in
applications into an HTML document. It is used as a container for embedding plug-
ins such as flash animations. This tag is a new tag in HTML 5, and it requires only
starting tag.
<object>
The <object> tag defines a container for an external resource. This tag is used to
embed multimedia files on webpage. The <object> tag can include multimedia files
such as video, audio, image, PDF, Java Applets, or another page on your page.
If you insert text between the <object> and </object> tags, then it will only be
displayed if the browser does not support the <object> tag.
Example:
<!DOCTYPE html>
<html>
<body>
<h1>Embed tag</h1>
<embed src="multimedia/[Link]" type="image/webp" width="200px"
height="150px">
<embed src="multimedia/ujyalo.mp3" type="audio/mp3" width="300px"
height="100px">
<embed src="multimedia/EC.mp4" type="video/mp4" width="300px" height="200px">
<embed src="[Link]" type="text/html" width="300px" height="300px">
<h1>Video Tag</h1>
<video src="multimedia/EC.mp4" width="300px" height="200px" controls></video>
<h1>Audio Tag</h1>
<audio src="multimedia/ujyalo.mp3" controls></audio>
<h2>Object tag</h2>
31
Image Tag:
HTML img tag is used to display image on the web page. HTML img tag is an
empty tag that contains attributes only, closing tags are not used in HTML image
element.
The <img> tag is used to embed an image in an HTML page.
Images are not technically inserted into a web page; images are linked to web pages.
The <img> tag creates a holding space for the referenced image.
The <img> tag has two required attributes:
In HTML, an element called MAP lets you associate URLs with various regions of
an image; then, when the image is clicked in one of the designated regions, the
browser loads the appropriate URL. This form of mapping is known as a client-side
image map, since the determination of which URL to contact is made on the client
and no server-side program is involved.
The <map> tag can include many <area> elements that define the coordinates and
type of the area. You can simply link any area of a picture to other pages using the
<map> tag without dividing the image.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h2>Click on any clickable area of the image and see the result </h2>
<img src="multimedia/[Link]" alt="laptop" usemap="#imgmap"
width="400px" height="380" style="margin-left: 100px">
<map name="imgmap">
<area shape="rect" coords="34,44,270,350" href="[Link]"
alt="Computer">
<area shape="circle" coords="337,300,44" href="[Link]" alt="Coffee">
<area shape="rect" coords="290,172,333,250" href="[Link]" alt="Mobile
Phone">
<area shape="poly" coords="300,10,320,15,325,20,320,25,300,30,280,20"
href="[Link]" alt="Blank Space">
</map>
</body>
</html>
33
Example:
<!DOCTYPE html>
<html>
<body>
HTML Table:
The HTML tables allow web authors to arrange data like text, images, links, other
tables, etc. into rows and columns of cells.
The HTML tables are created using the <table> tag in which the <tr> tag is used to
create table rows and <td> tag is used to create data cells or columns. The elements
under <td> are regular and left aligned by default.
Example: Structure or syntax of table
34
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h2>Syntax of table</h2>
<table border="1">
<tr>
<td>cell 1</td>
<td>Cell 2</td>
</tr>
<tr>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
<tr>
<td>Cell 5</td>
<td>Cell 6</td>
</tr>
</table>
</body>
</html>
Output:
35
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<table border="1">
<caption> This is the caption</caption>
<thead>
<tr>
<td colspan="3">This is the header of the table</td>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="3"> This is the footer of the table</td>
</tr>
</tfoot>
<tbody>
<tr>
36
<th>Heading 1</th>
<th>Heading 2</th>
<th>Heading 3</th>
</tr>
<tr>
<td>Content 1</td>
<td>Contant 2</td>
<td>Content 3</td>
</tr>
<tr>
<td>Content 1</td>
<td>Contant 2</td>
<td>Content 3</td>
</tr>
</tbody>
</table>
</body>
</html>
Output:
Table Alignment:
The HTML <table> align Attribute is used to specify the alignment of the table
and its content.
Aligning Entire Table:
This is the horizontal alignment of the content in the table, to align entire table to
left or right or center we can use align attribute in the <table> tag.
Syntax:
37
Syntax;
Table Attributes:
Some of the common attributes of tables are given bellow:
Content Summary:
The summary attribute specifies a summary of the content of a table. The summary
attribute makes no visual difference in ordinary web browsers. This attribute can be
used by screen readers.
Syntax:
<table summary = “this is the table related to list of student information”>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
Background Color:
The HTML bgcolor attribute is used to set the background color of an HTML
element. Bgcolor is one of those attributes that has become deprecated with the
implementation of Cascading Style Sheets. We can use color value by name or RBG
color code.
We can implement this attributes in entire table through <table> tag, or in a specific
row through <tr> tag, or in specific cell through <td> tag.
Syntax:
<table bgcolor = “red” >
<tr bgcolor = “green” >
<td> </td>
39
<td> </td>
</tr>
<tr>
<td bgcolor = “#1018F5”> </td>
<td> </td>
</tr>
</table>
Adding a caption:
This attribute is used to insert the caption of table.
Syntax:
<table>
<caption> This is the caption of table </caption>
</table>
</tr>
</table>
Adding a border:
This attribute is used to enclose the contents of table by the line or border. The value
of border attribute can be written in px, em etc. This attribute is applied only in the
<table> tag.
Syntax:
<table border= “1px” >
<tr>
<td> </td>
<td> </td>
</tr>
</table>
Global Attributes:
The global attributes are attributes that can be used with all HTML elements.
The HTML <table> tag also supports the following global attributes
Header Section:
This is the heading of the table, this can implement by using the <thead> tag. This
section comes first in the table which can include the Rows and Columns. This is the
optional part of the table.
Syntax:
<thead>
<tr>
<td colspan= “2” > This is heading of the table </td>
</tr>
</thead>
Footer Section:
Unlike the header section, footer section is comes in the last position of the table.
This is implemented by the <tfoot> tag. This section also contains the Rows and
Columns. This is the optional part of the table.
Syntax:
<tfoot>
<tr>
<td colspan= “2” > This is the footer of the table </td>
</tr>
</tfoot>
Body Section:
Body section is come in the middle of the table enclosed by the header and footer
section. This section contains all the table elements like, rows, columns, and
contents. This section contains multiple table tags like, <th>, <tr>, <td> etc. This is
the mandatory part of the table.
Syntax:
<tbody>
45
<tr>
<td> cotent 1 </td>
<td> cotent 2 </td>
</tr>
<tr>
<td> cotent 3 </td>
<td> cotent 4 </td>
</tr>
</tbody>
Column Properties:
HTML table column has some useful properties like colspan, colgroup. It also
supports the HTML global attributes like id, style, bgcolor etc.
Colspan:
This is used to merge the two or more column in a single one.
Syntax:
<tr>
<td colspan= “3”> It merge 3 columns </td>
</tr>
Colgroup:
This property is used to apply table attributes to the specific group of columns.
Syntax:
<colgroup>
<col span = “3” bgcolor= “red” >
<col span = “2” bgcolor = “green”>
</colgroup>
46
Here in the above code, first 3 columns are design as bgcolor as red and other had
corresponding 2 columns will design as bgcolor green.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<table width="50%">
<thead>
<tr>
<td colspan="5" align="center"> Table Heading </td>
</tr>
</thead>
<colgroup>
<col span="3" bgcolor="red" width="100px">
<col span="2" bgcolor="green">
</colgroup>
<tr>
<td>c1</td>
<td>c2</td>
<td>c2</td>
<td>c4</td>
<td>c5</td>
</tr>
<tr>
<td>cell</td>
<td>cell</td>
<td>cell</td>
<td>cell</td>
<td>cell</td>
</tr>
<tr>
<td>cell</td>
<td>cell</td>
<td>cell</td>
<td>cell</td>
47
<td>cell</td>
</tr>
</table>
</body>
</html>
Output:
Question 2: Create a table to display the salary of the listed employee using
necessary sections and attributes.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<table width = "50%" height="100px">
<colgroup>
<col span="2" bgcolor="blue">
<col bgcolor="yellow">
</colgroup>
<caption>Salary of Employees</caption>
<thead bgcolor="red">
<tr>
<td colspan="3" align="center">Following are the salary of listed
employees</td>
</tr>
</thead>
<tfoot bgcolor="green">
48
<tr>
<td colspan="3" align="center">Medmax Inovation Pvt. Ltd.</td>
</tr>
</tfoot>
<tbody align="center">
<tr>
<th>SN</th>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>1</td>
<td>Ram</td>
<td>Rs.50000</td>
</tr>
<tr>
<td>2</td>
<td>Gopal</td>
<td>Rs.30000</td>
</tr>
<tr>
<td>3</td>
<td>Rahul</td>
<td>Rs.40000</td>
</tr>
<tr>
<td>4</td>
<td>Sudan</td>
<td>Rs.50000</td>
</tr>
</tbody>
</table>
</body>
</html>
Output:
49
Question 2: Create following table apply different background color for each Row
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h2>Syntax of table</h2>
<table border="1px" width="50%" height="200px">
<tr bgcolor="8D0909">
<th>SN</th>
<th>Name</th>
<th>Sal</th>
<th>Dob</th>
</tr>
<tr align="center" bgcolor="red">
<td rowspan="2">cel 1</td>
<td>cel 2</td>
50
<td>cel 3</td>
<td align="right" valign="top">cel 4</td>
</tr>
<tr bgcolor="green">
<td valign="bottom">cel 5</td>
<td colspan="2">cel 6</td>
</tr>
<tr bgcolor="yellow">
<td valign="bottom">cel 7</td>
<td>cel 8</td>
<td>cel 9</td>
<td valign="top">cel 10</td>
</tr>
</table>
</body>
</html>
Question 3: Write HTML code to draw following table, use section, header, footer,
body, and colgroup tags.
<!DOCTYPE html>
<html lang="en">
51
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<table width="50%" height="300px" border="1px" align="center">
<caption>Tabale 1: Table of Student</caption>
<thead>
<tr>
<td colspan="5" bgcolor="red" align="center"> DWIT</td>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="5" bgcolor="blue" align="center">© BCA-III</td>
</tr>
</tfoot>
<colgroup>
<col span="3">
<col bgcolor="purple">
</colgroup>
<tbody>
<tr>
<td colspan="2" bgcolor="yellow"></td>
<td></td>
<td></td>
<td rowspan="2" bgcolor="green"></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td colspan="2" bgcolor="pink"></td>
<td></td>
<td></td>
</tr>
</tbody>
52
</table>
</body>
</html>
HTML Frames:
HTML Frames are used to divide the web browser window into multiple sections
where each section can be loaded separately. A frameset tag is the collection of
frames in the browser window.
Creating Frames: Instead of using body tag, use frameset tag in HTML to use
frames in web browser. But this Tag is deprecated in HTML 5. The frameset tag is
used to define how to divide the browser. Each frame is indicated by frame tag and
it basically defines which HTML document shall open into the frame. To define the
horizontal frames use row attribute of frame tag in HTML document and to define
the vertical frames use col attribute of frame tag in HTML document.
Advantages:
It allows the user to view multiple documents within a single Web page.
It loads pages from different servers in a single frameset.
The older browsers that do not support frames can be addressed using the tag.
Disadvantages:
Due to some of its disadvantage it is rarely used in web browser.
Frames can make the production of website complicated.
A user is unable to bookmark any of the Web pages viewed within a frame.
The browser’s back button might not work as the user hopes.
The use of too many frames can put a high workload on the server.
Many old web browsers don’t support frames.
<frameset> tags
This tag is used to divide the frame in different rows and columns. The values of
rows and columns are written in either % or absolute value in pixels.
53
Syntax:
<frameset rows = “20%, 30%, 10” />
</framesett>
<frame> tag
This tag is used to create frame with contents, which are enclosed by frameset tag.
Syntax:
<frameset rows = “20%, 30%, 10” >
<frame name = “fram1” src= “url” />
<frame name = “fram1” src= “url” />
<frame name = “fram1” src= “url” />
<noframes>
<body>Your browser does not support frames.</body>
</noframes>
</framesett>
Note: for Horizontal framing we use rows and for vertical framing, we use cols
attribute.
Nesting Frameset:
Since, frame tag is not supported by HTML5, instead we can use ifram or div in
HTML5 to do similar task.
<iframe>
You can define an inline frame with HTML tag <iframe>. The <iframe> tag is not
somehow related to <frameset> tag, instead, it can appear anywhere in your
document. The <iframe> tag defines a rectangular region within the document in
which the browser can display a separate document, including scrollbars and
borders. An inline frame is used to embed another document within the current
HTML document.
The src attribute is used to specify the URL of the document that occupies the inline
frame.
Example:
<html>
<head>
</head>
<body>
<iframe src="[Link]" frameborder="1">
Sorry, your browser doesn't support iframe.
</iframe>
</body>
</html>
55
<div>tag
Frame tag is not supported by HTML 5 instead we can use div tag to do similar
work.
The div tag is known as Division tag. The div tag is used in HTML to make divisions
of content in the web page like (text, images, header, footer, navigation bar, etc).
Div tag has both open(<div>) and closing (</div>) tag and it is mandatory to close
the tag. The Div is the most usable tag in web development because it helps us to
separate out data in the web page and we can create a particular section for particular
data or function in the web pages.
</head>
<body>
<div style="width: 200px; height: 100px; color:blue; border:1px outset red;
background-color: aqua; text-align: center;">
This is division
</div>
</body>
</html>
Output:
HTML Forms:
HTML Forms are required, when you want to collect some data from the site visitor.
For example, during user registration you would like to collect information such as
name, email address, credit card, etc.
A form will take input from the site visitor and then will post it to a back-end
application such as CGI, ASP Script or PHP script etc. The back-end application
will perform required processing on the passed data based on defined business logic
inside the application.
There are various form elements available like text fields, textarea fields, drop-down
menus, radio buttons, checkboxes, etc.
57
1 Action
Backend script ready to process your passed data.
2 Method
Method to be used to upload data. The most frequently used are GET and POST
methods.
3 Target
Specify the target window or frame where the result of the script will be
displayed. It takes values like _blank, _self, _parent etc.
4 Enctype
You can use the enctype attribute to specify how the browser encodes the data
before it sends it to the server. Possible values are
58
Syntax:
<form action="#" method="get">
<input type="text" name="fname">
</form>
Note: Only form elements with a name attribute will have their values passed when
submitting a form.
Syntax:
<form action="#" method="get">
<input type="text" name="fname">
</form>
Syntax:
<form action="#" method="get">
<input type="text" name="name" disabled>
</form>
file_extension: It Specify the file extension(s) like .gif, .jpg, .png, .doc) the
user can pick from.
audio/*: The user can pick all sound files.
video/*: The user can pick all video files.
image/*: :A valid media type, with no parameters. Look at IANA Media
Types for a complete list standard media types
media_type: A valid media type without parameters.
Syntax:
<form action="#" method="get">
<select name="drop" id="drop">
<option value="Nepal">Nepal</option>
<option value="India">India</option>
<option value="Japan">Japan</option>
<option value="China">China</option>
</select>
<input type="submit" value="Submit">
</form>
Here, the value attribute is used to send the actual value when click on the submit
button.
Hidden:
The <input type="hidden"> defines a hidden input field (not visible to a user).
64
A hidden field lets web developers include data that cannot be seen or modified by
users when a form is submitted.
A hidden field often stores what database record that needs to be updated when the
form is submitted.
Note: While the value is not displayed to the user in the page's content, it is visible
(and can be edited) using any browser's developer tools or "View Source"
functionality. Do not use hidden inputs as a form of security!
Syntax:
<form action="#" method="get">
<label for="name">Enter your name:</label><br>
<input type="text" name="name">
<input type="hidden" id="myid" name="myid" value="123"><br>
<input type="submit" value="Submit">
</form>
Password:
The characters in a password field are masked (shown as asterisks or circles).
Syntax:
<form action="#" method="get">
<input type="password">
<input type="submit" value="Submit">
</form>
File Upload:
We can upload a file in the input field and send to the server. It has an accept attribute
to mention which type of file should be uploaded.
Syntax:
<form action="#" method="get">
<input type="file" accept=".png,.jpeg,.pdf">
65
If we do not use accept attribute then input field can accept all kinds of files.
Submit Button:
Submit button is used to send the input field data to the server.
Syntax:
<form action="#" method="get">
<input type="submit" value="Submit">
</form>
Here, type is the type of button and value is the display text over the button.
Reset Button:
Reset button is used to reset the input field in initial position. This is mostly used to
erase the data entered in the input fields.
Syntax:
<form action="#" method="get">
<input type="reset" value="Reset">
</form>
Radio Button:
Radio button is used to choose the one of the option to send the value as input data.
In this we can select only one option at a time. We can use checked attribute to set
default option.
Syntax:
<form action="#" method="get">
<input type="radio" value="Male" name="gender">
<label for="gender">Male</label>
<input type="radio" value="Female" name="gender">
66
<label for="gender">Female</label>
</form>
Checkbox:
Checkbox is used to choose multiple options to send the value as input data. In this
we can select more than one option together at same time. We can use checked
attribute to set default option.
Syntax:
<form action="#" method="get">
<input type="checkbox" value="HTML" name="html">
<label for="html">HTML</label>
<input type="checkbox" value="CSS" name="css">
<label for="css">CSS</label>
</form>
Email:
To enter the email with validation, we can use the email.
Syntax:
<form action="#" method="get">
<input type="email" name="email">
</form>
Number:
To insert the number only in the input field, we can use the number type.
Syntax:
<form action="#" method="get">
<input type="number" name="num">
</form>
In this type, we can set the limit as max and min to restrict the number.
67
Eg:
<form action="#" method="get">
<input type="number" name="num" max="100">
</form>
Syntax:
<form action="#" method="get">
<input type="data" name="date">
</form>
Date time:
We can select or insert date and time together using datetime-local type of input
field.
Syntax:
<form action="#" method="get">
Time:
To pick the specific time then we can use the time type.
Syntax:
<form action="#" method="get">
<input type="time" name="time">
</form>
Week:
To pick the specific week of the year, we can use week type.
Syntax:
<form action="#" method="get">
<input type="week" name="week">
</form>
Month:
To pick the specific month of the year, we can use the month type.
Syntax:
<form action="#" method="get">
<input type="month" name="mth">
</form>
Range:
The <input type="range"> defines a control for entering a number whose exact value
is not important (like a slider control). Default range is 0 to 100. However, you can
set restrictions on what numbers are accepted with the min, max, and step attributes:
Syntax:
69
Tel:
The <input type="tel"> is used for input fields that should contain a telephone
number.
<form action="#" method="get">
<input type="tel" name="phn" pattern="[0-9]{2,3}-[0-9]{5}">
<input type="submit" value="Submit">
</form>
Url:
To submit the valid url to the input field, url type is used. It required the valid url
like [Link]
Syntax:
<form action="#" method="get">
<input type="tel" name="phn" pattern="[0-9]{10}">
<input type="submit" value="Submit">
</form>
<form action="#" method="get">
<input type="url" name="url">
<input type="submit" value="Submit">
</form>
70
Color:
To pick the color, we can use color type.
Syntax:
<form action="#" method="get">
<input type="color" name="color">
<input type="submit" value="Submit">
</form>
Meta Characters:
\d [0-9]
\D [^0-9]
\w [a-zA-Z_0-9]
\W [^\w]
. any characters
^ position at start of line
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
72
<label for="tel">Telephone:</label><br>
<input type="text" name="tel" pattern="^[0][1-9]{1,2}[\-][1-9]{7}$"
required
title="first 2 or 3 digits then - then any 7 digits"><br><br>
<label for="email">Email:</label><br>
<input type="text" name="email" pattern="^[a-z0-9_\.]+[@][a-z]+[\.][a-
z\.]{3,}$" required
title="any lowercase alphanumeric followed by @ then lowercase
followed by dot"><br><br>
<label for="pw">Password:</label><br>
<input type="text" name="pw" pattern="^(?=.*[a-z])(?=.*[A-
Z])(?=.*[\d])(?=.*[!@#$%^&*-+=._])[a-zA-Z0-9!@#$%^&*-+=._]{6,}$" required
title="atleast 6 characte with one lowercase one uppercase and one
special character"><br><br>
<label for="web">Website:</label><br>
<input type="text" name="web" pattern="^https?::\/\/www\.[a-z0-9]+\.[a-
z\.]{2,}$" required
title="should start with https::// and followed by loweercase
alphanumeric and dot"><br><br>
[Link]
Here in [Link], first data submitted by client side page [Link] will
compare with the data stored in $name and $pass variable, if it matches the stay in
welcome page otherwise redirect to the [Link] page.
74
<?php
$name = "prakash";
$pas = "kathmandu";
$uname = $_GET['username'];
$pass = $_GET['pass'];
if($uname==$name && $pass==$pas)
{
echo'Welcome to my page <br>
<a href="[Link]">logout</a>';
}
else
{
header("Location:[Link]");
}
?>
[Link]
If you are not registered yet, you can register the from the [Link] page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="[Link]" method="post">
<label for="fname">First Name:</label><br>
<input type="text" name="fname" pattern="[a-zA-Z ]+" required><br><br>
<label for="mname">Middle Name:</label><br>
<input type="text" name="mname" pattern="[a-zA-Z ]+"><br><br>
<label for="lname">Last Name:</label><br>
<input type="text" name="lname" pattern="[a-zA-Z ]+" required><br><br>
<label for="uname">User Name:</label><br>
<input type="text" name="uname" pattern="[a-zA-Z0-9]+" required><br><br>
<label for="pass">Password:</label><br>
<input type="text" name="pass" pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-
9])(?=.*[!@#$%&*])[a-zA-Z0-9!@#$%&*]{6,}$" required><br><br>
<label for="dob">DOB:</label><br>
75
[Link]
When you submit the data from the register form, all the data will be display in
[Link] page.
<?php
$fname = $_POST['fname'];
$mname = $_POST['mname'];
$lname = $_POST['lname'];
$uname = $_POST['uname'];
$pass = $_POST['pass'];
$dob = $_POST['dob'];
</head>
<body>
<h2>Placing the similar field in a single group</h2>
<form action="#">
<fieldset style="width: 300px;">
<legend align="center">Log Information</legend>
<label for="user">User Name:</label><br>
<input type="text" name="user"><br><br>
<label for="pass">Password:</label><br>
<input type="password" name="pass"><br><br>
<button type="submit">Log In</button>
</fieldset>
</form>
</body>
</html>
Output:
77
onblur script Fires the moment that the element loses focus
onchange script Fires the moment when the value of the element is
changed
onfocus script Fires the moment when the element gets focus
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
78
</head>
<body>
<form action="#">
<label for="ltu">Lower to upper:</label><br>
<input type="text" name="ltu" id="ltu" onblur="LowerToUpper()"><br><br>
<label for="change">Change the value:</label><br>
<select id="mySelect" onchange="changeValue()">
<option value="Audi">Audi
<option value="BMW">BMW
<option value="Mercedes">Mercedes
<option value="Volvo">Volvo
</select><br>
<p id="p1"></p><br>
<label for="focus">Focus:</label><br>
<input type="text" name="focus" id="focus" onfocus="myFocus()"><br><br>
<label for="input">Input:</label><br>
<input type="text" name="input" id="input" oninput="myInput()"><br>
<p id = "p2"></p><br>
<label for="invalid">Input Validation:</label><br>
<input type="text" name="invalid" pattern="[a-zA-Z]+"
oninvalid="alert('Your data is invalid..')">
<script>
function LowerToUpper()
{
var x = [Link]("ltu");
[Link] = [Link]();
}
function changeValue()
{
var x = [Link]("mySelect").value;
[Link]("p1").innerHTML= "You Selected: "+x;
}
function myFocus()
{
[Link]("focus").[Link] = "red";
}
function myInput()
{
var x = [Link]("input").value;
79
Style Sheet:
Introduction:
Style Sheet also known as CSS (Cascading Style Sheet) describes the HTML
elements which are displayed on screen, paper, or in other media. It saves a lot of
time. It controls the layout of multiple web pages at one time. It sets the font-size,
font-family, color, background color on the page.
It allows us to add effects or animations to the website. We use CSS to
display animations like buttons, effects, loaders or spinners, and also animated
backgrounds. Without using CSS, the website will not look attractive.
CSS selectors:
In CSS, selectors are patterns used to select the element(s) you want to style. There
are several selectors used in CSS, some of frequently used selectors are:
Class selector:
This will select the html element by their class name.
Syntax:
<style>
.classname{
color:red;
}
</style>
80
Id Selector:
This will select the html element by their id.
Syntax:
<style>
#id{
color:red;
}
</style>
Universal Selector:
This will select all the element of the html.
Syntax:
<style>
*{
color:red;
81
}
</style>
Inline CSS
Internal/ Embedded CSS
External CSS
Inline CSS:
Inline CSS is used to style a specific HTML element. Add a style attribute to each
HTML tag without using the selectors. Managing a website may difficult if we use
only inline CSS. However, Inline CSS in HTML is useful in some situations. We
have not access the CSS files or to apply styles to element.
In the following example, we have used the inline CSS in <body> <p> and <h1> tag.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body style="background-color: #ffe6e6;">
<h1 style="color: green; font-family: Times New Roman; padding: auto;">
Inline CSS
</h1>
<p style="color:blue">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quaerat
voluptate saepe nulla molestiae quibusdam, fugit sed ? Quae beatae harum possimus
odit officiis esse vero tempore explicabo libero voluptatibus! Doloribus, rem?
</p>
</body>
</html>
82
Internal CSS:
The Internal CSS has <style> tag in the <head> section of the HTML document.
This CSS style is an effective way to style single pages. Using the CSS style for
multiple web pages is time-consuming because we require placing the style on each
web page.
We can use the internal CSS by using the following steps:
1. Firstly, open the HTML page and locate the <head>
2. Put the following code inside the <head> section
<style type="text/css">
CSS rules
</style>
Example 1: Adding internal CSS using element name selector in the HTML tags.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
83
<style>
body{
background-color: aliceblue;
}
h1{
color: blue;
padding: auto;
margin-left: 10px;
}
p{
color: brown;
font-family: sans-serif;
font-size: large;
}
</style>
</head>
<body>
<h1>Internal CSS</h1>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Obcaecati animi
quaerat nisi consectetur natus blanditiis nesciunt corrupti pariatur modi,
eveniet sit illo nemo eius reprehenderit facere quibusdam? Ab, non beatae.
</p>
</body>
</html>
Example 2: Adding internal CSS using id, class selector in the HTML tags.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* Class Selector */
.mybody{
background-color: azure;
}
84
.para{
color: pink;
font-family: 'Courier New';
}
/* Id Selector */
#myhead{
color:blue;
font-style: italic;
text-align: center;
}
</style>
</head>
<body class="mybody">
<h1 id="myhead">
Inline CSS using selector
</h1>
<p class="para">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Labore quod
magnam natus, fugiat harum explicabo exercitationem voluptatem, sequi possimus
odio ducimus distinctio eaque voluptatum architecto doloremque dolorem vitae cum
enim!
</p>
<p>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Repudiandae
quaerat necessitatibus inventore maiores reiciendis totam voluptatum accusamus
omnis molestiae dolores, eum dolorem, debitis illum consequuntur fugit d eserunt.
</p>
</body>
</html>
Example 3: Adding internal CSS using Universal selector in the HTML tags.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* Univarsal selector */
85
*{
color: blue;
text-align: center;
}
</style>
</head>
<body>
<h1>Universal CSS Selector</h1>
<p>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Placeat ea
adipisci, harum earum ullam vitae fugit fuga quas ut numquam delectus voluptates
doloribus hic accusantium nisi mollitia quis minima est?
</p>
</body>
</html>
External CSS:
In external CSS, we link the web pages to the external .css file. It is created by text
editor. The CSS is more efficient method for styling a website. By editing
the .css file, we can change the whole site at once.
To use the external CSS, follow the steps, given below:
1. Create a new .css file with text editor, and add CSS rules.
2. Add a reference to the external .css file right after <title> tag in the <head> section
of HTML sheet:
Example:
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="[Link]">
</head>
<body class="mybody">
<h1 id="myhead">
External CSS
</h1>
<p id="para">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Et hic veniam
reiciendis error totam sit impedit! Ab totam repellendus necessitatibus
dignissimos natus rem, ad eos ea? Eos reiciendis nobis et?
</p>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Fuga
dignissimos reprehenderit assumenda atque aspernatur beatae deleniti, dolore
saepe eum! Impedit iste obaecati necessitatibus placeat perferendi.
</p>
</body>
</html>
[Link]
.mybody{
background-color: aliceblue;
}
body #myhead{
text-align: center;
font-style: italic;
color: green;
}
body p{
font-size: large;
87
font-family: Impact;
}
body #para{
color: red;
}
HTML (HyperText Markup Language) is the standard language for creating web
pages.
Example
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My First HTML Page</title>
</head>
<body>
<h1>Welcome to HTML!</h1>
<p>This is a paragraph.</p>
</body>
</html>
2. HTML Documents
Example
html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document Structure</title>
</head>
<body>
<header>
<h1>Site Header</h1>
</header>
<main>
<p>Content goes here.</p>
</main>
<footer>
<p>Footer Information</p>
</footer>
</body>
</html>
Example
html
4. CSS Basics
CSS Syntax
css
selector {
property: value;
}
Example
html
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
h1 {
color: blue;
}
</style>
</head>
<body>
<h1>Styled Heading</h1>
</body>
</html>
Media Queries
css
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body {
font-size: 16px;
}
@media (max-width: 600px) {
body {
font-size: 12px;
}
}
</style>
</head>
<body>
<p>Resize the browser to see the effect!</p>
</body>
</html>
7. Frontend Frameworks
Bootstrap Example
<!DOCTYPE html>
<html lang="en">
<head>
<link
href="[Link]
rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row">
<div class="col">Column 1</div>
<div class="col">Column 2</div>
</div>
</div>
</body>
93
</html>