Basic HTML Workshop Module Guide
Basic HTML Workshop Module Guide
PHP WORKSHOP
MODULE
HTML
HTML Tags:
HTML markup tags are usually called HTML tags
• HTML tags are keywords (tag names) surrounded by angle brackets like <html>
• HTML tags normally come in pairs like <b> and </b>
• The first tag in a pair is the start tag, the second tag is the end tag
• The end tag is written like the start tag, with a forward slash before the tag name
• Start and end tags are also called opening tags and closing tags
• HTML tags are not case sensitive i.e., <HEAD>, <head> and <hEaD> are equal
• Styles must be switched off by an end tag
• Some characters have to be replaced in the text by escape sequences
• White space, tabs, and new lines are ignored by the browser
• If a browser doesn’t understand a tag it will usually ignore it
Structure of an HTML Document:
All HTML documents follow the same basic structure. The general structure of
HTML document (page) is as the following:
The comment tag is used to insert comments in the source code. Comments are not
displayed in the browsers. We can use comments to explain our code, which can help us
when we edit the source code at a later date. This is especially useful if we have a lot of code.
Comment tags start <! and end with >. Each comment can contain as many lines of
text as we like. If the comment runs over a number of lines, each must start with - - and must
not contain - - within its body.
Ex:
<!--This is a comment --
-- Comments are not displayed in the browser -->
Generally the software developers write the following information in the comments:
• The name of the application
• A description of the purpose of the code in the file
• The name of the author
• The original creation date
• A version number of the HTML
• Copyright information
The document head holds control information to be used by browsers and servers.
Most of the people never use head tags except the title tag i.e., <title> . . . </title>. All
HTML documents have just one title which is displayed at the top of the browser.
An HTML document's head is enclosed by the HTML head element and can contain
some of these element definitions:
• The document's title: Describes briefly what the document is about.
• Style declarations: Group of class definitions (style sheets) used by other tags to set
visual characteristics.
• Script functions: Set of functions declared inside the “HTML script element” to
provide functionality to the document.
• Meta statements: Declared through the “HTML meta tag”, set custom attributes and
values for the document.
• Global links: Defined using the “HTML link tag” designates resources related to the
actual document.
Document Body.
The body is the container for the visual part of a document. All the things written here
(except for special cases) will be shown when the document preparation is over. Most of the
tags in HTML can be inserted in the body section (inside the HTML body element) and will
shape the visual aspects of the document.
Blocks:
In HTML, the documents are prepared as blocks of text and each block is formatted
independently. A block has no meaning outside of a particular document. The main two
blocks of HTML documents are paragraph and heading.
Paragraph: Paragraphs are block-level elements that constitute a basic structure of a
document. The <p> tag defines a paragraph. Browsers automatically add
some space (margin) before and after each <p> element. The margins
can be modified with CSS (with the margin properties). The syntax of
<p> tag is:
<p [align=”left” | “center” | “right” | “justify”] . . . </p>
The “align” attribute is optional. It defines the horizontal alignment of
its content. Possible values are:
• left: Text is aligned to the left margin.
• right: Text is aligned to the right margin.
• center: Text is centered.
• justify: Text is justified to both margins.
Heading: The <h1> to <h6> tags are used to define HTML headings. <h1> defines
the most important heading and <h6> defines the least important heading.
The syntax of <h1> to <h6> tags are:
<h1 [align=”left” | “center” | “right” | “justify”] . . . </p>
The “align” attribute is optional. It defines the horizontal alignment of
its content.
<h1 [align=”left” | “center” | “right” | “justify”] . . . </h1>
<h2 [align=”left” | “center” | “right” | “justify”] . . . </h2>
<h3 [align=”left” | “center” | “right” | “justify”] . . . </h3>
<h4 [align=”left” | “center” | “right” | “justify”] . . . </h4>
<h5 [align=”left” | “center” | “right” | “justify”] . . . </h5>
<h6 [align=”left” | “center” | “right” | “justify”] . . . </h6>
Possible values are:
• left: Text is aligned to the left margin.
• right: Text is aligned to the right margin.
• center: Text is centered.
• justify: Text is justified to both margins.
Horizontal Line Tag: The HTML <hr> tag draws a horizontal line and that may be used as
separator. This tag has a set of attributes such as align, noshade, size
and width and they are optional. The <hr> tag does not require and
end tag.
Attribute Value Syntax Description
left Specifies the alignment of a <hr>
Align center <hr align="left|center|right"> element
right
Specifies that a <hr> element
should render in one solid color
Noshade noshade <hr noshade>
(noshaded), instead of a shaded
Color
<hr size="pixels"> Specifies the height of a <hr>
Size pixels element
<hr size="30">
Specifies the width of a <hr>
pixels <hr width="pixels|%">
element.
The width in pixels (like "100px" or
Width % <hr width="50%"> just "100").
The width in percent of the
available space (like "50%")
Output:
Ex:2 The font-family, color, and font-size properties defines the font, color, and size of the
text in an element:
<html>
<body>
<h1 style="font-family:verdana;">A heading</h1>
<p style="font-family:arial;color:red;font-size:20px;">A paragraph.</p>
</body>
</html>
Output:
Ex:3 The text-align property specifies the horizontal alignment of text in an element:
<html>
<body>
<h1 style="text-align:center;">Center-aligned heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Output:
Hyper Links.
The HTML <a> tag defines a hyperlink.
A hyperlink (or link) is a word, group of words, or image that you can click on to
jump to another document.
When we move the cursor over a link in a Web page, the arrow will turn into a little
hand.
The most important attribute of the <a> element is the href attribute, which indicates
the link’s destination.
By default, links will appear as follows in all browsers:
• An unvisited link is underlined and blue
• A visited link is underlined and purple
• An active link is underlined and red
HTML Link Syntax
The HTML code for a link is simple. It looks like this:
<a href="url">Link text</a>
Output:
The following code example demonstrates how to use a link to jump to another
part of a document.
Ex:
<html>
<body>
<p>
</p>
<h2>Chapter 1</h2>
<h2>Chapter 2</h2>
<h2>Chapter 3</h2>
<h2>Chapter 5</h2>
</body>
</html>
Output:
The following example demonstrates how to link to an e-mail address and generate
a new e-mail message in your default e-mail application (this works only if you have mail
installed).
Ex:
<html>
<body>
<p>
<a href="[Link]
again">
Send Mail</a>
</p>
<p>
properly.
</p>
</body>
</html>
Output:
A path is an absolute path if the entire URL and file name can be pasted into a
browser's address field to locate a specific page on the Internet. An absolute path specifies a
fully-qualified URL; the protocol ([Link] must be present in addition to the site's domain
name, and often a subfolder or specific file name is included as well.
This is an example of link to an absolute URL:
<a href="[Link] search engine</a>
The URL in the link above can be loaded regardless of the current page
displayed in a browser.
Relative Path:
A relative path specifies the name of the file to be linked to only as it is related
to the current document.
For example, if all the files in our Web site are contained within the same
directory (or folder), and we want to establish a link from [Link] to [Link], the code
on [Link] will look like this:
<a href="[Link]">Go to page 2</a>
This link will be valid only from within the same directory that [Link] is
saved in. The browser receives the request for the new page, looks in the current directory
(folder) of the current page, and finds a file named [Link] to display.
LISTS in HTML.
HTML supports three types of lists. They are
1. Ordered Lists
2. Unordered Lists
3. Definition Lists
1. Ordered Lists:
An ordered list can be numerical or alphabetical. The <ol> tag defines an ordered list.
The <li> tag is used to define list items.
Ex:
<html>
<body>
<h3> An Order List is</h3>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<ol start="50">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
Output:
Ex:1
Output:
Ex:2
<html>
<body>
<h4>Disc bullets list:</h4>
<ul type="disc">
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
</ul>
3. Definition Lists:
A definition list is not a list of single items. It is a list of items (terms), together
with a description of each item (term). A definition list starts with a <dl> tag (definition list).
Each term starts with a <dt> tag (definition term). Each description starts with a <dd> tag
(definition description).
Ex:
<html>
<body>
<h4>A Definition List:</h4>
<dl>
<dt>Coffee</dt>
<dd>Black hot drink</dd>
<dt>Milk</dt>
<dd>White cold drink</dd>
</dl>
</body>
</html>
Output:
Nested Lists:
A nested list is a list within another list. Usually the second list is indented
another level and the item markers will appear differently than the original list.
Ex:
<html>
<body>
<h4>A Nested List:</h4>
<ul>
<li>Coffee</li>
<li>Tea
<ul>
<li>Black tea</li>
<li>Green tea
<ul>
<li>China</li>
<li>Africa</li>
</ul>
</li>
</ul>
</li>
<li>Milk</li>
</ul>
</body>
</html>
Output:
Tables in HTML.
Tables are an excellent way to organize and display information on a page.
Tables are defined using the <table> tag. A table is divided into rows with the <tr> tag, and
each row is divided into data cells using the <td> tag. The letters td stand for “table data,”
which is the content of a data cell. A data cell can contain text, images, lists, paragraphs,
forms, horizontal rules, tables, and so on.
Ex:
Note: nowrap - Specifies that the content inside a header cell should not wrap
valign-Vertical aligns the content in a header cell
width-Specifies the width of a header cell
Ex:1 The following code creates a table with one row and one column.
<html>
<body>
<h4>One column:</h4>
<table border="1">
<tr>
<td>100</td>
</tr>
</table>
</body>
</html>
Output:
Ex:2 The following code creates a table with one row and three columns.
<html>
<body>
<table border="1">
<tr>
<td>100</td>
<td>200</td>
<td>300</td>
</tr>
</table>
</body>
</html>
Output:
Ex:3 The following code creates a table with two rows and three columns.
<html>
<body>
<table border="1">
<tr>
<td>100</td>
<td>200</td>
<td>300</td>
</tr>
<tr>
<td>400</td>
<td>500</td>
<td>600</td>
</tr>
</table>
</body>
</html>
Output:
Table Borders:
The border attribute controls the appearance of the table’s borders or lines. The
default border is 0, so if we do not specify a border attribute, the table is displayed without
any borders. Sometimes this is useful, but most of the time, we want the borders to be visible.
Ex:4 The following code demonstrates the use of different table borders.
<html>
<body>
Output:
<td>100</td>
<td>200</td>
<td>300</td>
</tr>
<tr>
<td>400</td>
<td>500</td>
<td>600</td>
</tr>
</table>
</body>
</html>
Output:
Headings in a Table:
Table headings are defined with the <th> tag.
Ex:6 The following explains how to use the headings in a table.
<html>
<body>
<table border="1">
<tr>
<th>Heading</th>
<th>Another Heading</th>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
<h4>Vertical headers:</h4>
<table border="1">
<tr>
<th>First Name:</th>
<td>Bill Gates</td>
</tr>
<tr>
<th>Telephone:</th>
<td>555 777 1854</td>
</tr>
<tr>
<th>Telephone:</th>
<td>555 777 1855</td>
</tr>
</table>
Output: </body>
</html>
</td>
<td>HELLO</td>
</tr>
</table>
</body>
</html>
Output:
</tr>
<tr>
<td align="left">Make-Up</td>
<td align="right">$30.00</td>
<td align="right">$44.45</td>
</tr>
<tr>
<td align="left">Food</td>
<td align="right">$730.40</td>
<td align="right">$650.00</td>
</tr>
<tr>
<th align="left">Sum</th>
<th align="right">$1001.50</th>
<th align="right">$744.65</th>
</tr>
</table>
</body>
</html>
Output:
<th>Savings</th>
</tr>
</thead>
<tfoot>
<tr>
<td>Sum</td>
<td>$180</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</tbody>
</table>
</body>
</html>
Output:
HTML Colors:
HTML colors are defined using a hexadecimal notation (HEX) for the
combination of Red, Green, and Blue color values (RGB). The lowest value that can be given
to one of the light sources is 0 (in HEX: 00). The highest value is 255 (in HEX: FF). HEX
values are specified as 3 pairs of two-digit numbers, starting with a # sign. The combination
of Red, Green, and Blue values from 0 to 255, gives more than 16 million different colors
(256 x 256 x 256).
The 17 standard colors are: aqua, black, blue, fuchsia, gray, green, lime,
maroon, navy, olive, orange, purple, red, silver, teal, white, and yellow.
Sorted by Color Name:
141 color names are defined in the HTML and CSS color specification (17
standard colors plus 124 more). The table below lists them all, along with their hexadecimal
values.
bgcolor attribute:
The “bgcolor” attribute specifies the background color of a document.
<html>
<body bgcolor="red">
<h1>Hello world!</h1>
</body>
</html>Web Technologies 36
When we execute the above code, the background color of the web page changes
to red.
color attribute:
The color attribute specifies the color of the text inside a <font> element.
Ex:
<font color="red">This is some text!</font>
Images in HTML.
In HTML, images are defined with the <img> tag. The img tag is empty, which
means that it contains attributes only and it has no closing tag.
To display an image on a page, we need to use the src attribute. src stands for
“source”. The value of the src attribute is the URL of the image we want to display on our
page. The syntax of defining an image:
<img src="url" />
The URL points to the location or address where the image is stored.
<img> Tag Syntaxes:
1. <body background=”URL”>…</body>
Sets the background of the page to use the given image.
Ex:
<html>
<body>
<p>
An image:
</p>
<p>
<img src="E:/[Link]-2013/JS/Examples/[Link]" width="100"
height="100" />
</p>
</body>
</html>
Output:
Each shape is defined by co-ordinates pairs of the integers which give location
of the image in pixels.
• The default location does not require coordinates is used to indicate what
happens if the user clicks outside of the mapped areas. Each image map can
have only one default.
CIMAGE GROUP OF INSTITUTIONS Page 41
Web Technologies 38
• A rectangle has four coordinates which are paired . The first pair defines the
top left corner and second pair is the bottom right corner of the area.
• A circle is defined by its center and its radius. The center is given by a pair
of values , the radius by a single value. Therefore this requires just three
values in the coordinate string.
• A polygon is made from a set of coordinates with the last pair listed being
joined to the first to complete the shape.
Background Images:
The following example demonstrates how to add a background image to
an HTML page.
Ex:
<html>
<body background="E:/[Link]-2013/JS/Examples/[Link]">
<font color=”red”>
<h3>Look: A background image!</h3>
<p>Both gif and jpg files can be used as HTML
backgrounds.</p>
<p>If the image is smaller than the page, the image will repeat
itself.</p>
</font>
</body>
</html>
Output:
alt Attribute:
The alt attribute is used to define an alternate text for an image. The alt
attribute tells the reader what he or she is missing on a page if the browser can’t load
images. The browser will then display the alternate text instead of the image.
The value of the alt attribute is an author-defined text:
<img src="[Link]" alt="Big Boat" />
It is a good practice to include alternate text for every image on a page to
improve the display and usefulness of our document who have text-only browsers.
Ex: The following example shows what happens when the image file is not
available.
<html>
<body>
<p>
An image:
<img src="E:/[Link]" alt=”HAI” width="200" height="50">
</p>
</body>
</html>
Output:
21. Create a page with a link at the top of it that when clicked will jump all the way to the
bottom of the page.
28.
29.
31.
32.
33.
Module-2
Multimedia Objects
Applets:
Frame Tag in HTML
FORMS in HTML
HTML Document Head in detail.
<DOCTYPE> element
XHTML in brief.
1. The <object> tag defines an embedded object within an HTML document. This
element inserts multimedia such as audio, video, Java applets, ActiveX, PDF, and
Flash in to the web pages.
Syntax:
<object classid=”URL” data=”URL” [codebase=”URL”]
type=”string” [standby=”string”] height=”n” width=”n”
[title=”string”]>…</object>
Where classid : Defines a class ID value as set in the Windows Registry or a URL
data : Specifies the URL of the resource to be used by the object
codebase : Defines where to find the code for the object
type : Specifies the MIME type of data specified in the data attribute
standby : Defines a text to display while the object is loading
height : Specifies the height of the object
width : Specifies the width of the object
title : This attribute is to provide a title for the element
2. We can also use the <object> tag to insert another webpage into our HTML
document.
3. We can use the <param> tag to pass parameters to plugins that have been embedded
with the <object> tag.
Syntax:
<param name=”string” value=”string” type=”string” valuetype=[“ref” | “object”
| “data”]>
Where name : Specifies the name of a parameter
value : Specifies the value of the parameter
type : Specifies the MIME type of the parameter
valuetype : Specifies the type of the value
Ex
:
<html>
<head>
<title>Embedded Object</title>
</head>
<body>
<p>The next paragraph contains and object and some
parameters</p>
<object classid="clsid:6bf52a52-394a-11d3-b153-00c04F79faa6"
width="300" height="265">
<param name="autostart" value="false">
<param name="stretchtofit" value="true">
<param name="urmode" value="full">
<param name="url" value="C:/Users/Public/Videos/Sample
Videos/[Link]">
<p>This browser does not support Windows Media Player using the
object tag.</p>
</object>
</body>
</html>
Output:
Applets:
“Applet is a java program which runs via java-enabled browser.” Applets are
embedded in HTML documents with the <applet> tag. When Java applet is compiled, a class
file (bytecode) will be generated. Applets have unique name and is used in applet tag.
Syntax:
codebase : Specifies a relative base URL for applets specified in the code attribute
Ex:
Step1: Open the Notepad and type the following Java code:
/*
Basic Java Applet Example
This Java example shows how to create a basic applet using Java Applet
class.
*/
import [Link];
import [Link];
public class BasicAppletExample extends Applet{
public void paint(Graphics g){
//write text using drawString method of Graphics class
[Link]("This is my First Applet",20,100);
}
}
Step 4: Open new file in Notepad and type the following code:
<html>
<head>
<title>A Simple Applet</title>
</head>
<body>
<p>Here is the Simple Applet</p>
<p align=”center”>
<applet code=” [Link]” width=”200”
height=”50”></applet>
</p>
</body>
</html>
Step 5: Save the above file as “[Link]”.
Step 6: Open the “[Link]” file in the Internet Explorer Browser or any
“We can also get the same thing using <object> tag instead of <applet> tag.”
<html>
<head>
<title>A Simple Applet</title>
</head>
<body>
<p>Here is the Simple Applet</p>
<p align=”center”>
<object code=” [Link]” width=”200”
height=”50”></object>
</p>
</body>
</html>
Output:
The <frame> tag defines one particular window (frame) within a <frameset>. Each
<frame> in a <frameset> can have different attributes, such as border, scrolling, the ability to
resize, etc.
Syntax:
<frameset [cols=”%,%] [rows=”%,%]>. . .</frameset>
[frameborder=”0”|”1”]>
<html>
<head>
<title>Frame A</title>
</head>
<body bgcolor=”blue”>
<h1 align=”center”>This is FRAME A</h1>
</body>
</html>
*** Save the above program as “[Link]”
<html>
<head>
<title>Frame B</title>
</head>
<body bgcolor=”pink”>
<h1 align=”center”>This is FRAME B</h1>
</body>
</html>
*** Save the above program as “[Link]”
<html>
<head>
<title>Frame C</title>
</head>
<body bgcolor=”red”>
<h1 align=”center”>This is FRAME C</h1>
</body>
</html>
*** Save the above program as “[Link]”
<html>
<frameset cols="25%,*,25%">
<frame src="[Link]">
<frame src="[Link]">
<frame src="[Link]">
</frameset>
</html>
Output:
FORMS in HTML.
“A form is an area that can contain form elements.”
Forms are used to add an element of interactivity to website. HTML forms are used to
collect different kinds of user input. Form elements are elements that allow the user to enter
information in a form (like text fields, text area fields, drop-down menus, radio buttons,
check boxes, and so on).
Ex: A Simple form
<form>
.
.
input elements
.
.
</form>
Syntax:
4. <form action=”URL” method=”post”|”get”>…</form>
The <form> tag is used to create an HTML form for user input.
Where action : Specifies where to send the form-data when a form is submitted
method : Specifies the HTTP method to use when sending form-data
GET - Requests data from a specified resource
POST - Submits data to be processed to a specified resource
The <input> tag specifies an input field where the user can enter data. <input>
elements are used within a <form> element to declare input controls that allow users to input
data. An input field can vary in many ways, depending on the type attribute.
The <option> tag defines an option in a select list. <option> elements go inside
a <select> or <datalist> element. The <option> tag can be used without any attributes, but we
usually need the value attribute, which indicates what is sent to the server. If we have a long
list of options, we can group related options with the <optgroup> tag.
Where value : Specifies the value to be sent to a server
The <textarea> tag defines a multi-line text input control. A text area can hold an
unlimited number of characters, and the text renders in a fixed-width font (usually Courier).
The size of a text area can be specified by the cols and rows attributes, or even better; through
CSS' height and width properties.
Where name : Specifies a name for a text area
rows : Specifies the visible width of a text area
cols : Specifies the visible number of lines in a text area
input Tag and Attributes:
The most used form tag is the <input> tag. The type of input is specified with the type
attribute. The following types are the most commonly used input types.
Text Fields
Text fields are used when we want the user to type letters, numbers, and so on in
a form.
Ex:
<html>
<body>
<form action="">
First name:
<input type="text" name="firstname" />
<br><br>
Last name:
<input type="text" name="lastname" />
</form>
</body>
</html>
Output:
CheckBox
The following example demonstrates how to create check boxes on an HTML
page.
Ex: <html>
<body>
<form action="">
I have a bike:
<input type="checkbox" name="vehicle"
value="Bike">
<br><br>
I have a car:
<input type="checkbox" name="vehicle" value="Car">
<br><br>
I have an airplane:
<input type="checkbox" name="vehicle"
value="Airplane">
</form>
</body>
</html>
Output:
Radio Buttons
When a user clicks a radio button, that button becomes selected, and all other
buttons in the same group become deselected. The following example demonstrates how to
create radio buttons on an HTML form.
Ex:
<html>
<body>
<form action="">
Male:
<input type="radio" checked="checked"
name="Sex" value="male">
<br><br>
Female:
<input type="radio" name="Sex" value="female">
</form>
</body>
</html>
Output:
Drop-Down List
The following example shows how to create a simple drop-down list on an
HTML page. A drop-down list is a selectable list.
Ex:
<html>
<body>
<form action="">
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
</form>
</body>
</html>
Output:
Text Area
Buttons
Buttons are common items on a form. The following example demonstrates
how to create a button. We can define our own text on the face of the button.
Ex:
<html>
<body>
<form action="">
<input type="button" value="Hello world!">
</form>
</body>
</html>
Output
:
<p>
If there is no border around the input form, our browser is
too old.
</p>
</body>
</html>
Output:
action Attribute:
When the user clicks the Submit button, the content of the form is sent to the
server. The form’s action attribute defines the name of the file to send the content to. The file
defined in the action attribute usually does something with the received input.
<form name="input" action="html_form_submit.asp" method="get">
Username:
<input type="text" name="user" />
<input type="submit" value="Submit" />
</form>
If we type some characters in the text field and click the Submit button, the
browser sends our input to a page called "html_form_submit.asp". The page will show us the
received input.
Ex: This example demonstrates how to add a form to a page. The form contains two input
fields and a Submit button.
<html>
<body>
<form name="input" action="html_form_action.asp" method="get">
:
Type our first name:
<input type="text" name="FirstName" value="Mickey"
size="20">
<br>Type our last name:
<input type="text" name="LastName" value="Mouse"
size="20">
<br>
<input type="submit" value="Submit">
</form>
<p>
If we click the "Submit" button, we will send our input to a new
page called html_form_action.asp.
</p>
</body>
Output
</html>
checked="checked" />
<br><br>
I have a car:
<input type="checkbox" name="vehicle" value="Car" />
<br><br>
I have an airplane:
<input type="checkbox" name="vehicle" value="Airplane" />
<br><br>
<input type="submit" value="Submit" />
</form>
<p>
If we click the "Submit" button, we send our input to a new page
called html_form_action.asp.
</p>
</body>
Output </html>
:
Male:
<input type="radio" name="Sex" value="Male"
checked="checked">
<br><br>
Female:
<input type="radio" name="Sex" value="Female">
<br><br>
<input type ="submit" value ="Submit">
</form>
<p>
If we click the "Submit" button, we will send our input to a new
page called html_form_action.asp.
</p>
</body>
</html>
Output
:
Markup Language). The DTD specifies the rules for the markup language, so that the
browsers render the content correctly.
Tip: Always add the <!DOCTYPE> declaration to our HTML documents, so that the
browser knows what type of document to expect.
Ex:1
<html>
<head>
<title>This is my Page</title>
</head>
<body>
<p>This text is displayed</p>
</body>
</html>
Output:
Ex:2
<html>
<head>
<base target="_blank">
</head>
<body>
<p>
<a href=[Link] target="_blank">This link</a>
will load in a new window because the target attribute is
set to "_blank".
</p>
<p>
<a href="[Link]
This link</a>
will also load in a new window even without a target attribute.
</p>
</body>
</html>
Output
:
Ex:3 The meta attributes in the following example identify the document’s author, editor, and
the software used to create the page.
<html>
<head>
<meta name="author" content="Jan Egil Refsnes">
<meta name="revised" content="Michael Woodward,3/14/2010">
<meta name="generator" content="Microsoft FrontPage 5.0">
</head>
<body>
<p>All meta information goes in the head section...</p>
</body>
</html>
Output:
XHTML in brief.
XHTML stands for eXtensable HyperText Markup Language and is a cross
between HTML and XML. XHTML was created for two main reasons:
1. To create a stricter standard for making web pages, reducing incompatibilities
between browsers.
2. To create a standard that can be used on a variety of different devices without
changes.
XHTML is same as HTML, although it is much more important that we create
our code correctly. XHTML is a web standard which has been agreed by the W3C.
Benefits of XHTML:
There are three very good reasons to update to XHTML:
➢ It will help we to create better formatted code on our site
➢ It will make our site more accessible (both in the future and now due to the fact that it
will also mean we have correct HTML and most browsers will show our page better)
➢ XHTML is planned to replace HTML 4 in the future
The Main Changes:
There are several main changes in XHTML from HTML:
• All tags must be in lower case
• All documents must have a doctype
• All documents must be properly formed
• All tags must be closed
• All attributes must be added properly
• The name attribute has changed
• Attributes cannot be shortened
• All tags must be properly nested
The Doctype:
The first change which will appear on the page is the Doctype. When using
HTML it is considered good practice to add a Doctype to the beginning of the page like this.
Although this was optional in HTML, XHTML requires adding a Doctype.
There are three available for use.
Strict - This is used mainly when the markup is very clean and there is no 'extra' markup to
aid the presentation of the document. This is best used if we are using Cascading Style Sheets
It is important that our document follows this basic pattern. This example uses
the transitional Doctype.
XHTML Tags:
One of the major changes to HTML which was introduced to XHTML is that
tags must always be properly formed. With the old HTML specification we could be very
poor in our coding, with missing tags and incorrect formation. These drawbacks we can
overcome in XHTML.
1. Tags and attributes have to be lowercase:
All of the tags and attributes have to be in lowercase. This is because XML is
case-sensitive — i.e. a tag in capitals is a different tag to one in small letters.
2. All tags must be closed:
Now all of those once-optional </p> and </li> tags are essential for our
XHTML documents to validate. Even empty elements like img, hr, and br must now be
closed. We can use a standard forward-slashed end tag, or just add in a forward slash to the
end of the tag.
<br /> or <br></br>
It's recommended that we use the former method here, and leave a space
before the slash so older browsers aren't confused. They'll just ignore the trailing slash as an
unrecognized attribute.
3. Documents must be well-formed:
'Well-formedness' is a dream that we were meant to try and make real from the
start, but many coders write badly-syntaxed code. We have to open and close tags correctly in
XHTML, and nest them properly.
Bad: <p>My coding is <b>bad</p></b> Good: <p>But
my coding is <b>good</b></p>
Remember the simple rule we should have been taught at the very start: The
first tag we open is the last tag we close.
4. Attribute values must be quoted:
Back in HTML we could leave out the quotes on a number value, like
HEIGHT=3, but now all values have to have quotation marks around them, so that would
become height="3".
5. Attribute Minimization:
Some HTML tags had one-word attributes, like HR's NOSHADE. We can't
use these anymore, and must add the attribute in as its own value, like so:
<hr noshade="noshade" />
Any browser compatible with HTML 4.01 shouldn't have a problem with
markup like this.
6. Internal Links:
Internal links in HTML were made using a combination of the <a> tag and the
name attribute. In XHTML, to go along with XML, we use the id attribute to make these
links instead of the name attribute. For a while we should probably include both so that our
links still work on older browsers, but this will be the method used in future. The name
attribute has been deprecated.
<a href="#section">link</a>
<p id="section" name="section"></p>
Since all tags can take the id attribute, we can now make links to any element
on our page. Most helpful if we add the link to a heading or specific paragraph.
7. Alternative text in image:
While it has always been good practice to add the alt="..." attribute to our
images, now we must add some alternate text to every image on our page. If our image is
purely decorative we can give it a null alt attribute with a space:
<img src="[Link]" alt=" " />
We could also try adding the title="..." attribute to as many elements as
possible. It's a good accessibility aid, especially on links.
8. Ampersands in URLs:
Ampersand characters are frequently used in page addresses to carry variables,
like in PHP. When coding these addresses into our XHTML, we must escape them using the
entity value &. They'll be displayed as ampersand characters (&) on screen, of course.
<a href="[Link]?page=27&style=blue">link</a> becomes
<a href="[Link]?page=27&style=blue">link</a>
9. Content must be wrapped in a block-level element:
In XHTML Strict, when we add text to our page, we can’t add it directly into
the body element. All text needs to be within a suitable containing block-level element, such
as p(Paragraph), ul(Unordered list) or a div(Generic block-level container).
Ex:
<xml version=”1.0” encoding=”UTF-8>
<!Doctype html
PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“DTD/[Link]”>
<html xmlns=[Link]
xml:lang=”en” lang=”en”>
<head>
<title>Sample XHTML Document</title>
</head>
<body>
<h1>Sample XHTML Document</h1>
<hr/>
<p>This is very Basic Document in XHTML</p>
<ul>
<li>It has an xml version identifier</li>
<li>It has a valid DTD</li>
<li>All tags are closed</li>
</ul>
<hr/>
</body>
</html>
Output:
*************************************
1.
2.