UNIT - 3 Ip
UNIT - 3 Ip
Internet Programming
Unit - III
HTML
An HTML file is a text file, so to create an HTML file any text editor can be used. There are various text
editors available such as Notepad, Notepad++, Sublime Text, Vim, etc. After writing the code in a text editor,
the HTML file is saved with the extension .htm or .html.
Features of HTML
1) It is a very easy and simple language. It can be easily understood and modified.
2) It is very easy to make an effective presentation with HTML because it has a lot of formatting tags.
3) It is a markup language, so it provides a flexible way to design web pages along with the text.
4) It facilitates programmers to add a link on the web pages (by html anchor tag), so it enhances the
interest of browsing of the user.
5) It is platform-independent because it can be displayed on any platform like Windows, Linux, and
Macintosh, etc.
6) It facilitates the programmer to add Graphics, Videos, and Sound to the web pages which makes it
more attractive and interactive.
7) HTML is a case-insensitive language, which means we can use tags either in lower-case or uppercase.
HTML Tags
HTML tags are like keywords which define that how web browser will format and display the content. With
the help of tags, a web browser can distinguish between an HTML content and a simple content. These tags are
enclosed within angle braces <Tag Name>.
Container Tags: Container tag is that tag which includes both opening and closing tag. The start or
opening tag is simply a tag name enclosed in angled brackets whereas the end or closing tag is
identified by including a forward slash (/) before the tag name in angled brackets. For Example:
<B>…………….</B>
<P>……………..</P> Empty Tags: Empty
tag is tag without content or a closing tag.
For Example:
<Br>
<Hr>
For Example:
HTML Attributes
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 like name = “value”.
Syntax:
For Example:
<html>
<body>
Document body related tags
</body>
</html>
<html>
It specifies the document as a webpage that can be seen in the web browser. The
1 entire document is enclosed within <html> and </html> tags. It actually tells the
web browser where the page starts and where it ends. It usually consists of two parts
HEAD and BODY.
<head>
This tag represents the document's header which can keep other HTML tags like
2
<title>, <link> etc.
<title>
3 The <title> tag is used inside the <head> tag to mention the document title.
<body>
This tag contains the actual contents of HTML document that can be seen by the
4 end user. This tag represents the document's body which keeps other HTML tags
like <h1>, <div>, <p> etc.
For Example:
<html>
<head>
<title>Web page title</title>
</head> <body>
HTML Comments:
Comment is a piece of code which is ignored by any web browser. Comments of any code make code easy to
understand and increase readability of code.
HTML comments are placed in between <!-- ... --> tags. So, any content placed with-in <!-- ... --> tags will
be treated as comment and will be completely ignored by the browser.
Syntax:
For Example:
<html>
<!- - This is header Section - ->
<head>
<title>Web page title</title>
</head> <body>
<!- - This is body Section - ->
<h1>Write Your First Heading</h1>
<p>Write Your First Paragraph. </p>
</body>
</html>
HTML Headings:
A HTML heading can be defined as a title or a subtitle which user want to display on the webpage. There are
six different HTML headings which are defined with the <h1> to <h6> tags. <h1> is the largest heading tag
and <h6> is the smallest one. So <h1> is used for most important heading and <h6> is used for least important.
Attribute:
ALIGN = LEFT/RIGHT/CENTER
For Example:
<html>
Aman Choudhary Student (BCA-II) Seth G. L. Bihani S. D. PG College
<head>
<title>Heading Example</title>
</head>
<body>
<h1>This is heading 1</h1>
<h2 align = “right”>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4 align = “center”>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
</body>
</html>
HTML Paragraph:
HTML paragraph tag is used to define a paragraph in a webpage. An HTML <p> tag indicates starting of new
paragraph.
Attribute:
ALIGN = LEFT/RIGHT/CENTER/JUSTIFY
For Example:
<html>
<head>
<title>Paragraph Example</title>
</head>
<body>
<h1>First Paragraph</h1>
<p align = “right”> Dreams and hopes are what drive us in life
and there is a world where dreams are sold. </p>
</body>
</html>
Formatting Text
HTML Formatting is a process of formatting text for better look and feel. HTML provides the facility to
format text without using CSS. There are many formatting tags in HTML. These tags are used to make text
o Physical tag: These tags are used to provide the visual appearance to the text. o
Logical tag: These tags are used to add some logical or semantic value to the text.
Syntax:
<B> text </B>
Example:
<B> Hello World!!! </B>
Syntax:
<U> text </U>
Example:
<U><B> Hello World!!! </B></U>
Syntax:
<I> text </I>
Example:
<I> Hello World!!! </I>
Similarly
Element name Description
<strong> This is a logical tag, which tells the browser that the text is important.
<em> This is a logical tag which is used to display content in italic.
<tt> This tag is used to appear a text in teletype.
<strike> This tag is used to draw a strikethrough on a section of text.
<sup> It displays the content slightly above the normal line.
<sub> It displays the content slightly below the normal line.
This tag is used to display the deleted content. Browsers will usually
<del>
strike a line through deleted text.
Aman Choudhary Student (BCA-II) Seth G. L. Bihani S. D. PG College
This tag displays the content which is added. Browsers will usually
<ins>
underline inserted text.
<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.
Images
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. Following is the simple syntax to use this
tag.
<img src = "Image URL" ... attributes-list>
• Src : It is a necessary attribute that describes the source or path of the image. It instructs the
browser where to look for the image on the server.
• Alt : The alt attribute defines an alternate text for the image, if it can't be displayed. The
value of the alt attribute describe the image in words.
• Width : It is an optional attribute which is used to specify the width to display the image.
• Height : It is an optional attribute which is used to specify the height to display the image.
Example
<html>
<head>
<title> Using Image in Webpage </title>
</head>
<body>
<p>Simple Image Insert</p>
<img src = "/html/images/test.png" alt = "Test Image" Height=”150”>
</body>
</html>
Syntax
<span>Write your content here......</span>
Example
<html>
<head>
<title>Span Tag</title>
</head> <body>
<h2>Example of span tag</h2>
<p>I have choosen only
<span style="color: red;">red</span>,
<span style="color: blue;">blue</span>, and
<span style="color: green;">green</span> colors for my painting.
</p>
</body>
</html>
Text in a <pre> element is displayed in a fixed-width font, and the text preserves both spaces and line breaks.
The text will be displayed exactly as written in the HTML source code.
Example
<html>
Aman Choudhary Student (BCA-II) Seth G. L. Bihani S. D. PG College
<head>
<title>HTML pre Tag</title>
</head>
<body>
<pre>
This text is
in a fixed-pitch
font, and it preserves
both spaces and line breaks
</pre>
</body>
</html>
Hyperlink
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.
The <a> tag defines a hyperlink, which is used to link from one page to another. This tag is called anchor tag
and anything between the opening <a> tag and the closing </a> tag becomes part of the link
The most important attribute of the <a> element is the href attribute, which indicates the link's destination.
Syntax
Example
<html>
<head>
<title>Hyperlink Example</title>
</head>
<body>
<p>Click following link</p>
Attribute:
Type : This attribute is used in <ul> tag to specify the type of bullet shown in front of list
items. By default, it is a disc. Following are the possible options – Square, Disc, Circle.
Example:
<html>
<head>
<title> HTML Unordered List </title>
</head>
<body>
<ul type = “square”>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ul>
</body>
</html>
HTML Ordered Lists
In ordered lists the list items are displayed in a numbered list instead of bulleted. This list is created by using
<ol> tag. The numbering starts at one and is incremented by one for each successive ordered list element
tagged with <li>.
Attribute:
Type : This attribute is used in <ul> tag to specify the type of number shown in front of list items. By
default, it is a number. Following are the possible options – A, a, i, I, 1.
: This attribute is used to specify the starting point of numbering.
Start
Example:
<html>
<head>
Aman Choudhary Student (BCA-II) Seth G. L. Bihani S. D. PG College
<title> HTML Ordered List </title>
</head>
<body>
<ol type = "i" start = "4">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
Example:
<html>
<head>
<title> HTML Definition List </title>
</head>
<body>
<dl>
<dt> <b> HTML </b> </dt>
<dd> This stands for Hyper Text Markup Language </dd>
<dt> <b> HTTP </b> </dt>
<dd> This stands for Hyper Text Transfer Protocol </dd>
</dl>
</body>
</html>
Example
<html>
<head>
<title> HTML Tables </title>
</head>
<body>
<table>
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
</tr>
</table>
</body>
</html>
Attributes of Table
• Colspan and Rowspan Attributes colspan attribute is used to merge two or more columns into a
single column. Similar way rowspan is used to merge two or more rows.
• Tables Backgrounds
Table background can be set using one of the following two ways −
bgcolor attribute − You can set background color for whole table or just for one cell.
background attribute − You can set background image for whole table or just for one cell.
FORMS
HTML Forms are required, 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.
The HTML <form> tag is used to create an HTML form and it has following syntax −
<form action = "Script URL" method = "GET|POST">
</form>
Form Attributes
Apart from common attributes, following is a list of the most frequently used form attributes −
Sr. No Attribute & Description
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.
Example
Here is a basic example of a single-line text input used to take first name and last name −
<html>
<head>
<title>Text Input Control</title>
</head>
<body>
<form >
First name: <input type = "text" name = "first_name" > <br>
Last name: <input type = "text" name = "last_name" >
Aman Choudhary Student (BCA-II) Seth G. L. Bihani S. D. PG College
</form>
</body>
</html>
Attributes
Following is the list of attributes for <input> tag for creating text field.
Sr. No Attribute & Description
1
type
Indicates the type of input control and for text input control it will be set to text.
2
name
Used to give a name to the control which is sent to the server to be recognized and get the value.
3
value
This can be used to provide an initial value inside the control.
4
size
Allows to specify the width of the text-input control in terms of characters.
5
maxlength
Allows to specify the maximum number of characters a user can enter into the text box.
Example
Here is a basic example of a single-line password input used to take user password −
<html>
<head>
<title>Password Input Control</title>
</head>
<body>
<form >
User ID : <input type = "text" name = "user_id" > <br>
Aman Choudhary Student (BCA-II) Seth G. L. Bihani S. D. PG College
Password: <input type = "password" name = "password" >
</form>
</body>
</html>
Attributes
Following is the list of attributes for <input> tag for creating password field.
Sr. No Attribute & Description
1
type
Indicates the type of input control and for password input control it will be set to password.
2
name
Used to give a name to the control which is sent to the server to be recognized and get the value.
3
value
This can be used to provide an initial value inside the control.
4
size
Allows to specify the width of the text-input control in terms of characters.
5
maxlength
Allows to specify the maximum number of characters a user can enter into the text box.
Example
Here is a basic example of a multi-line text input used to take item description −
<html>
<head>
<title>Multiple-Line Input Control</title>
</head>
<body>
<form>
Aman Choudhary Student (BCA-II) Seth G. L. Bihani S. D. PG College
Description : <br />
<textarea rows = "5" cols = "50" name = "description">
Enter description here...
</textarea>
</form> </body>
</html>
Attributes
Following is the list of attributes for <textarea> tag.
Sr. No Attribute & Description
1
name
Used to give a name to the control which is sent to the server to be recognized and get the value.
2
rows
Indicates the number of rows of text area box.
3
cols
Indicates the number of columns of text area box
Checkbox Control
Checkboxes are used when more than one option is required to be selected. They are also created using HTML
<input> tag but type attribute is set to checkbox.
Example
Here is an example HTML code for a form with two checkboxes −
<html>
<head>
<title>Checkbox Control</title>
</head>
<body>
<form>
<input type = "checkbox" name = "maths" value = "on"> Maths
<input type = "checkbox" name = "physics" value = "on"> Physics
</form>
</body>
</html>
1
Type
Indicates the type of input control and for checkbox input control it will be set to checkbox.
2
name
Used to give a name to the control which is sent to the server to be recognized and get the value.
3
value
The value that will be used if the checkbox is selected.
4
checked
Set to checked if you want to select it by default.
Example
Here is example HTML code for a form with two radio buttons −
<html>
<head>
<title>Radio Box Control</title>
</head>
<body>
<form>
<input type = "radio" name = "subject" value = "maths"> Maths
<input type = "radio" name = "subject" value = "physics"> Physics
</form>
</body>
</html>
Attributes
Following is the list of attributes for radio button.
Sr. No Attribute & Description
3
value
The value that will be used if the radio box is selected.
4
checked
Set to checked if you want to select it by default.
Example
Here is example HTML code for a form with one drop down box
<html>
<head>
<title>Select Box Control</title>
</head>
<body>
<form>
<select name = "dropdown">
<option value = "Maths" selected>Maths</option>
<option value = "Physics">Physics</option>
</select>
</form>
</body>
</html>
Attributes
Following is the list of important attributes of <select> tag −
Sr. No Attribute & Description
3
multiple
If set to "multiple" then allows a user to select multiple items from the menu.
1
value
The value that will be used if an option in the select box box is selected.
2
selected
Specifies that this option should be the initially selected value when the page loads.
3
label
An alternative way of labeling options
Button Controls
There are various ways in HTML to create clickable buttons. You can also create a clickable button using
<input>tag by setting its type attribute to button. The type attribute can take the following values −
Sr. No Type & Description
1
submit
This creates a button that automatically submits a form.
3
button
This creates a button that is used to trigger a client-side script when the user clicks that button.
4
image
This creates a clickable button but we can use an image as background of the button.
Example
Here is example HTML code for a form with three types of buttons −
<html>
<head>
<title>File Upload Box</title>
</head>
<body>
<form>
<input type = "submit" name = "submit" value = "Submit" >
<input type = "reset" name = "reset" value = "Reset" >
<input type = "button" name = "ok" value = "OK" >
<input type = "image" name = "imagebutton" src = "/html/images/logo.png" >
</form>
</body>
</html>