HTML 4
HTML 4
INTRODUCTION TO HTML
HTML stands for “Hypertext Markup Language”. “Hypertext” means “the text that can be
transferred from internet server to internet client”.
HTML is a markup language. A markup language is a language that syntax will be in the form of
tags.
HTML is used to design web pages. That means HTML is used to create elements (such as headings,
paragraphs, icons, menus, logos, images, textboxes, buttons etc.) in the web pages.
HTML is easy language to understand.
HTML is “client side language”. That means the html code executes on the client (browser).
HTML is supported by all the browsers such as Google Chrome, Mozilla Firefox, Microsoft Internet
Explorer, Safari, Opera and other browsers.
HTML is developed by “Tim Berners-Lee” and maintained by “W3C” (World Wide Web
Consortonium).
HTML is used in all real web sites today.
The file extension should be “.html”.
HTML is the interpreter-based language. That means the HTML code will be converted into
machine language in line-by-line format. Browser interprets HTML code.
TAG
A tag is a keyword, enclosed within “<” and “>” in HTML language.
SYNTAX : <tag>
TYPES OF TAGS
Tags are two types:
Paired tags: Contains starting tag and ending tag.
Ex: <h1>hello</h1>
Unpaired tags: Contains single tag only (no separate ending tag).
Ex: <hr>
<html>
<body>
Your web page content here
</body>
</html>
<html>
<body>
Hello, World
</body>
</html>
<P>
It is used to create a paragraph.
It is a paired tag.
SYNTAX:
<p>paragraph here</p>
EXAMPLE
<p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. </p>
<H1>
It is used to create first level heading (main heading).
It is a paired tag.
SYNTAX
<h1>heading here</h1>
EXAMPLE
<h1>Heading 1 here</h1>
<H2>
It is used to create second level heading (sub heading).
It is a paired tag.
SYNTAX
<h2>heading here</h2>
EXAMPLE
<h2>Heading 2 here</h2>
<H3>
It is used to create third level heading (sub heading).
It is a paired tag.
SYNTAX
<h3>heading here</h3>
EXAMPLE
<h3>Heading 3 here</h3>
<H4>
It is used to create third level heading (sub heading).
It is a paired tag.
SYNTAX
<h4>heading here</h4>
EXAMPLE
<h4>Heading 4 here</h4>
<H5>
It is used to create third level heading (sub heading).
It is a paired tag.
SYNTAX
<h5>heading here</h5>
EXAMPLE
<h5>Heading 5 here</h5>
<H6>
It is used to create third level heading (sub heading).
It is a paired tag.
SYNTAX
<h6>heading here</h6>
EXAMPLE
<h6>Heading 6 here</h6>
<B>
It is used to display the text in bold.
It is a paired tag.
SYNTAX
<b>bold text</b>
EXAMPLE
<b>Hello</b>
<I>
It is used to display the text in italic.
It is a paired tag.
SYNTAX
<i>italic text</i>
EXAMPLE
<i>Hello</i>
<STRONG>
It is used to display the text in strong. <b> and <strong> both are same.
It is a paired tag.
SYNTAX
<strong>strong text</strong>
EXAMPLE
<strong>Hello</strong>
<EM>
It is used to display the text in emphasis. <i> and <em> both are same.
It is a paired tag.
SYNTAX
<em>emphasis text</em>
EXAMPLE
<em>Hello</em>
<U>
It is used to display the text in underline.
It is a paired tag.
SYNTAX
<u>underline text</u>
EXAMPLE
<u>Hello</u>
<STRIKE>
It is used to display the text in strikeout.
It is a paired tag.
SYNTAX
<strike>strikeout text</strike>
EXAMPLE
<strike>Hello</strike>
<SUP>
It is used to display the text in superscript (The text appears a bit upper side of normal line).
It is a paired tag.
SYNTAX
<sup>superscript text</sup>
EXAMPLE
<sup>Hello</sup>
<SUB>
It is used to display the text in subscript (The text appears a bit bottom side of normal line).
It is a paired tag.
SYNTAX
<sub>subscript text</sub>
EXAMPLE
<sub>Hello</sub>
<BR>
It is used to moves the cursor to the next line.
It is an unpaired tag.
SYNTAX
<br>
EXAMPLE
<br>
<HR>
It is used to display a horizontal line (horizontal ruler).
It is an unpaired tag.
SYNTAX
<hr>
EXAMPLE
<hr>
<ABBR>
It is used to display full-form of a short-form when the user places mouse pointer on it.
It is a paired tag.
SYNTAX
<abbr title="full form here">short form here</abbr>
EXAMPLE
<abbr title="as soon as possible">ASAP</abbr>
<BDO>
bdo stands for Bi-Directional Override.
The <bdo> tag is used to override the current text.
It is a paired tag.
SYNTAX
<bdo dir="rtl">your text here</bdo>
EXAMPLE
<bdo dir="rtl">Hai how are you</bdo>
ATTRIBUTES
dir:
ltr: It displays the text in left-to-right.
rtl: It displays the text in right-to-left.
<PRE>
It is used to display the text as-it-is, along with the spaces and line breaks.
It is a paired tag.
SYNTAX
<pre>your text here</pre>
EXAMPLE
<pre>
one two
three four five
</pre>
<IMG>
It is used to display an image in the web page.
It is an unpaired tag.
SYNTAX
<img src="image path here">
EXAMPLE
<img src="img1.jpg" width="200px" height="130px" title="this is tooltip">
ATTRIBUTES
src
It is used to specify path of the image file. If the image file and html file both are in the
same folder, no need to specify the full path of the image.
width
It is used to specify width (horizontal size) of the image.
height
It is used to specify height (vertical size) of the image.
title
It is used to specify the tooltip (that appears when the user places mouse pointer on the
image).
alt
It is used to specify the alternate text (that appears when the image is not loaded in the
browser at run time).
<A>
It is used to create a hyperlink. When the user clicks on the hyperlink, the specified web page or
web site will be opened.
It is a paired tag.
SYNTAX
<a href="target url here">link text here</a>
<a href="document to download" download>Display Text</a>
EXAMPLE
<a href="http://www.google.com">Google</a>
<a href="sample.docx" download>Sample Document</a>
ATTRIBUTES
href:
It is used to specify the address of web page or web site that is to be opened when the user
clicks on the hyperlink.
target="_blank":
It is used to open the target web page or web site in a separate browser tab.
download:
It is used to download the specified document.
<UL>
UL stands for “Unordered List”.
It is used to display the list of items with bullets.
Inside <ul> tag, you should place one or more <li> tags.
It is a paired tag.
SYNTAX
<ul>
<li>text here</li>
<li>text here</li>
…
</ul>
EXAMPLE
<ul>
<li>India</li>
<li>UK</li>
<li>US</li>
<li>Canada</li>
</ul>
ATTRIBUTES
type
"disc" or "square" or "circle".
<OL>
OL stands for “Ordered List”.
It is used to display the list of items with numbers.
Inside <ol> tag, you should place one or more <li> tags.
It is a paired tag.
SYNTAX
<ol>
<li>text here</li>
<li>text here</li>
…
</ol>
EXAMPLE
<ol>
<li>India</li>
<li>UK</li>
<li>US</li>
</ol>
Attributes
type
"1" or "A" or "a" or "I" or "i"
<DL>
DL stands for “Definition List”.
It is used to display a collection of definitions.
Inside <dl> tag, you should place one or more <dt> and <dd> tags.
It is a paired tag.
<dt> and <dd> tags are also paired tags.
<dt> is used to specify definition title.
<dd> is used to specify definition data.
SYNTAX
<dl>
<dt>title here</dt>
<dd>definition here</dd>
<dt>title here</dt>
<dd>definition here</dd>
…
</dl>
EXAMPLE
<dl>
<dt>HTML</dt>
<dd>HTML is used to design web pages.</dd>
<dt>CSS</dt>
<dd>CSS is used to apply styles.</dd>
<dt>JavaScript</dt>
<dd>JavaScript is used to create functionality.</dd>
</dl>
<TABLE>
<table> tag is used to display table type of data in the web page.
A table is a collection of rows. Each row is a collection of cells.
A table is represented as <table> tag; A row is represented as <tr>; A cell is represented as <td>.
Inside the <table> tag, we have to use <tr>; Inside the <tr> tag, we have to use <td>.
If the cell is representing the column heading, you can use <th> tag, instead of <td> tag.
<caption> tag is used to specify a title for the table.
“tr” stands for “Table row”.
“td” stands for “Table data”.
“th” stands for “Table header”.
<table>, <tr>, <th>, <td> and <caption> tags are paired tags.
SYNTAX
<table>
<tr>
<td>data here</td>
<td>data here</td>
…
</tr>
…
</table>
EXAMPLE
<table border="1">
<tr>
<td>One</td>
<td>Two</td>
</tr>
<tr>
<td>Three</td>
<td>Four</td>
</tr>
<tr>
<td>Five</td>
<td>Six</td>
</tr>
</table>
<IFRAME>
<iframe> tag is used to display another web page or web site within the current web page.
Iframe stands for “inline frame”.
<iframe> is a paired tag.
SYNTAX
<iframe src="web site address here" width="n px" height="n px">
</iframe>
EXAMPLE
<iframe src="http://www.airtel.in/" width="400px" height="300px">
</iframe>
HTML ENTITIES
HTML Entities are pre-defined codes for displaying special symbols within the web page.
HTML Entities are case sensitive. These must be used in lower case only.
<TITLE>
<title> tag is used to specify the title of the web page that appears in the browser’s title bar.
<title> tag should be used in <head> tag only.
<head> tag is used to specify non-content information of the page.
<title> is a paired tag.
SYNTAX
<title>Title here</title>
EXAMPLE
<title>My title</title>
<META>
<meta> tag is used to specify meta data (additional details) about the web page.
<meta> tag provides information about the web page. Google like search engines will display your
web page in the google search results, whenever one or more keywords are matching. You must
upload your web page in the internet server to really use this.
<meta> tag is an unpaired tag.
EXAMPLE
<meta name="keywords" content="Sony, Television, Price, Hyderabad">
<meta name="description" content="Sony LED BRAVIA Prices">
<meta name="author" content="Harsha">
<FORM>
<form> tag is used to group-up the input elements; so that we can submit the entire form to the
server.
A form is a collection of form elements such as <input>, <textarea> and <select>.
<form> is a paired tag.
SYNTAX
<form action="server page address here" method="get">
form elements here
</form>
EXAMPLE
<form action="page2.aspx" method="get">
<input type=”text” name=”Username”>
<input type=”submit”>
</form>
<INPUT>
<input> tag is used to create a form control (form element).
Form elements such as Textbox, Checkbox, Radio button, Browser button, submit button etc.
<input> is an unpaired tag.
SYNTAX
<input type="option here">
EXAMPLE
<input type="text">
checked=”checked”
Used to check the checkbox or radio button, in case of <input type=”checkbox”> or <input
type=”radio”>
disabled=”disabled”
Used to disable the button.
<LABEL>
<label> tag is used to create field heading.
When the user clicks on the label, cursor will be appeared in the associated textbox
automatically.
<label> is a paired tag.
SYNTAX
<label for="id of textbox here">label text here</label>
EXAMPLE
<label for="TextBox1">Username</label>
ATTRIBUTES OF <LABEL> TAG
for: Used to specify the id of the textbox that is associated with the textbox.
<BUTTON>
<button> tag is used to display a submit button with image and text.
<button> is a paired tag.
SYNTAX
<button>
<img src="image file path here">
Text here
</button>
EXAMPLE
<button>
<img src="ok.png">
<br>
OK
</button>
<SELECT>
<select> tag is used to create a dropdownlist or listbox.
DropDownList is used to display few options to the user and allow the user to select any one of
them.
ListBox is used to display few options to the user and allow the user to select one or more of them.
Inside <select> tag, you should use <option> tags. Each <option> tag represents an option in the
drop downlist.
Optionally, <optgroup> tag can be used to group-up the <option> tags.
<select>, <option> and <optgroup> tags are paired tags.
SYNTAX
<select name="name here">
<option value="short name here">Full name here</option>
<option value="short name here">Full name here</option>
…
</select>
EXAMPLE
<select name="PaymentMode">
<option value="Select">Select</option>
<option value="DC">Debit Card</option>
<option value="CC">Credit Card</option>
<option value="NB">Net Banking</option>
</select>
<TEXTAREA>
<textarea> tag is used to create a multi-line textbox.
<textarea> tag is a paired tag.
SYNTAX
<textarea name="name here" rows="no. of rows" cols="no. of columns">
</textarea>
EXAMPLE
<textarea name="comments" rows="5" cols="25"></textarea>
<FIELDSET>
<fieldset> tag is used to display a box around a set of fields.
<fieldset> tag is a paired tag.
SYNTAX
<fieldset>
Your textboxes here
</fieldset>
EXAMPLE
<fieldset>
<input type=”text”> <br>
<input type=”text”>
</fieldset>
<LEGEND>
<legend> tag is used to display a title for the fieldset.
<legend> tag is a paired tag.
SYNTAX
<fieldset>
<legend>title here</legend>
Your textboxes here
</fieldset>
EXAMPLE
<fieldset>
<legend>User details</legend>
<input type=”text”> <br>
<input type=”text”>
</fieldset>
<DIV>
<div> is a container.
Inside <div> tag you can place any content like normal text or any other html tags.
When you want to divide your web page as no. of parts, each part is represented as <div> tag.
<div> is a paired tag.
SYNTAX
<div>
Your content here
</div>
EXAMPLE
<div>
Hello
</div>
<SPAN>
<span> represents a small amount of text, for which you can apply some special formatting.
<span> is a paired tag.
SYNTAX
<span>Your content here</span>
EXAMPLE
<span>Hello</span>
2. INLINE ELEMENTS
All remaining tags (like <span>, <b>, <i>, <u>, <a>, <img>, <input>, <select> etc.) are inline
elements.
Will be displayed side-by-side.
"HTML 4.01 Strict (1999)" supports HTML 4 tags and attributes, except deprecated tags like <font>,
<basefont>, <center>, <marquee>, <bgsound> etc., and also <frameset>.
Same as "HTML 4.01 Strict (1999)", and also we should follow the specified 10 rules of XHTML.
HTML 5 (2012)
"HTML 5 (2012)" supports HTML 5 tags and attributes, except deprecated tags like <font>, <center>,
<marquee>, <bgsound> etc., and also <frameset>.
<!DOCTYPE html>
XHTML
WHAT IS XHTML?
XHTML stands for EXtensible HyperText Markup Language
XHTML is almost identical to HTML
XHTML is stricter than HTML
XHTML is HTML defined as an XML application
XHTML is supported by all major browsers
WHY XHTML?
<html>
<head>
<title>This is bad HTML</title>
Today's market consists of different browser technologies. Some browsers run on computers, and
some browsers run on mobile phones or other small devices. Smaller devices often lack the resources
or power to interpret "bad" markup.
XML is a markup language where documents must be marked up correctly (be "well-formed").
By combining the strengths of HTML and XML, XHTML was developed.
XHTML is HTML redesigned as XML.
THE MOST IMPORTANT DIFFERENCES FROM HTML
DOCUMENT STRUCTURE
XHTML DOCTYPE is mandatory
The xmlns attribute in <html> is mandatory
<html>, <head>, <title>, and <body> are mandatory
XHTML ELEMENTS
XHTML elements must be properly nested
XHTML elements must always be closed
XHTML elements must be in lowercase
XHTML documents must have one root element
XHTML ATTRIBUTES
Attribute names must be in lower case
Attribute values must be quoted
Attribute minimization is forbidden
This is correct:
A break: <br /> A horizontal rule: <hr /> An image: <img src="happy.gif" alt="Happy face" />
This is correct:
<body> <p>This is a paragraph</p> </body>
This is correct:
<table width="100%">
This is correct:
<table width="100%">
Correct:
<input type="checkbox" name="vehicle" value="car" checked="checked" />
Wrong:
<input type="text" name="lastname" disabled />
Correct:
<input type="text" name="lastname" disabled="disabled" />
XHTML RULES
<!DOCTYPE> is must.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>, <head>, <body>, <title> tags are must.
A <meta> tag with content-type is mandatory.
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
xmlns attribute is must in <html> tag
<html xmlns="http://www.w3.org/1999/xhtml">
Case sensitive (code should be in lower case only).
Attribute's values should be in double quotes.
All paired tags must be closed.
All unpaired tags must be end with /
Inner-most tag should be closed first.
Attribute minification not allowed