Unit 2 Notes
Unit 2 Notes
Unit 2: HTML
2.1 <img> Tag
Example: To insert images from another folder or from another web site
<img src="/images/stickman.gif" alt="Stickman" width="24" height="39">
<img src="https://www.w3schools.com/images/lamp.jpg" alt="Lamp" width="32"
height="32">
Example: To create an image map, with clickable regions. Each region is a hyperlink
<!DOCTYPE html>
<html>
<body>
<h1>The map and area elements</h1>
<p>Click on the computer, the phone, or the cup of coffee to go to a new page and read
moreabout the topic:</p>
<map name="workmap">
<area shape="rect" coords="34,44,270,350" alt="Computer" href="computer.htm">
<area shape="rect" coords="290,172,333,250" alt="Phone" href="phone.htm">
<area shape="circle" coords="337,300,44" alt="Cup of coffee" href="coffee.htm">
</map>
</body>
</html>
The image file formats that are most commonly used on the web are:
APNG (Animated Portable Network Graphics) — Good choice for lossless animation
sequences (GIF is less performant)
AVIF (AV1 Image File Format) — Good choice for both images and animated images
due to high performance.
GIF (Graphics Interchange Format) — Good choice for simple images and animations.
JPEG (Joint Photographic Expert Group image) — Good choice for lossy compression
of still images (currently the most popular).
PNG (Portable Network Graphics) — Good choice for lossless compression of still
images (slightly better quality than JPEG).
SVG (Scalable Vector Graphics) — Vector image format. Use for images that must be
drawn accurately at different sizes.
WebP (Web Picture format) — Excellent choice for both images and animated images
• Formats like WebP and AVIF are recommended as they perform much better than PNG,
JPEG,GIF for both still and animated images. WebP is widely supported while AVIF
lacks support in Safari.
• SVG remains the recommended format for images that must be drawn accurately at
different sizes.
2.2 a Element
• The <a> tag defines a hyperlink, which is used to link from one page to another.
• The most important attribute of the <a> element is the href attribute, which indicates the
link'sdestination.
• Example: To create a link to W3Schools.com
<a href="https://www.w3schools.com">Visit W3Schools.com!</a>
<td>Tobias</td>
<td>Linus</td>
</tr>
<tr>
<td>16</td>
<td>14</td>
<td>10</td>
</tr>
</table>
Output:
Person 1 Person 2 Person 3
Emil Tobias Linus
16 14 10
Example:
<!DOCTYPE html>
<html>
<body>
<h1>The thead, tbody, and tfoot elements</h1>
<table>
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tbody>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Sum</td>
<td>$180</td>
</tr>
</tfoot>
</table>
</body>
</html>
Output:
The thead, tbody, and tfoot elements
Month Savings
January $100
February $80
Sum $180
Example:
<table>
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
</table>
• To make a cell span over multiple columns, use the colspan attribute.
• The value of the colspan attribute represents the number of columns to span.
Example
<table>
<tr>
<th colspan="2">Name</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>43</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>57</td>
</tr>
</table>
Output:
Name Age
Jill Smith 43
Eve Jackson 57
• To make a cell span over multiple rows, use the rowspan attribute.
• The value of the rowspan attribute represents the number of rows to span.
Example
<table>
<tr>
<th>Name</th>
<td>Jill</td>
</tr>
<tr>
<th rowspan="2">Phone</th>
<td>555-1234</td>
</tr>
<tr>
<td>555-8745</td>
</tr>
</table>
Output:
Name Jill
555-1234
Phone
555-8745
Other Attributes of Table Tag
Border Attribute
The HTML <table> border Attribute is used to specify the border of a table. It sets the
border around the table cells.
Syntax:
<table border="1|0">
Attribute Values:
• 1: It sets the border around the table cells.
• 0: It removes (not set) the border around the table cells.
pixels: It holds the space between the cell content and cell wall in terms of pixels.
The HTML <table> cellspacing Attribute is used to specify the space between the cells. The
cellspacing attribute is set in terms of pixels.
Attribute Values:
• pixels: It sets the space between the cells in terms of pixels.
(Note:
Cellpadding: Cellpadding specifies the space between the border of a table cell and its contents
(i.e) it defines the whitespace between the cell edge and the content of the cell.
Cellspacing: Cellspacing specifies the space between cells (i.e) it defines the whitespace between
the edges of the adjacent cells.)
Bgcolor Attribute
The HTML <table> bgcolor Attribute is use to specify the background color of a table.
Attribute Values:
• color_name: It sets the text color by using the color name. For example “red”.
• hex_number: It sets the text color by using the color hex code.
For example “#0000ff”.
• rgb_number: It sets the text color by using the rgb code.
For example: “RGB(0, 153, 0)” .
Note: The <table> bgcolor Attribute is not supported by HTML 5 instead of using this we can
use CSS background-color property.
Width Attribute
The HTML <table> width Attribute is used to specify the width of a table. If width attribute
is not set then it takes default width according to content.
Attribute Values:
• pixels: It sets the width of table in terms of pixels.
• %: It sets the width of table in terms of percentage (%).
Note: The <table> width Attribute is not supported by HTML 5.
Example Program 1:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Output:
Example Program 2:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Output:
Example Program 3:
<!DOCTYPE html>
<html>
<body>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr height="200px">
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
Output:
Alignment Attribute
The HTML <table> align Attribute is used to specify the alignment of the table and its
content.
Attribute Values:
• left: It sets the left align to the table. It is a default value.
• right: It sets the right align to the table.
• center: It sets the center align to the table.
The HTML <td> valign Attribute is used to specify the vertical alignment of text content in a
cell.
Attribute Value:
• top: It sets the content to top-align.
• middle: It sets the content to middle-align.
• bottom: It sets the content to bottom-align.
• baseline: It sets the content to baseline. The baseline is the line where most of the
characters sit. It is a default value.
The HTML <tr> align Attribute is used to set the horizontal alignment of text content inside
the table row. It is not supported by HTML 5.
Attribute Values:
• left: It sets the text left-align.
• right: It sets the text right-align.
• center: It sets the text center-align. It is a default value.
• justify: It stretches the text of paragraph to set the width of all lines equal.
• char: It sets the text-align to a specific character.
Sample Program
<!DOCTYPE html>
<html>
<head>
<title>HTML tr align Attribute</title>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>HTML tr align Attribute</h2>
<table width="500" border="1">
<tr align="right">
<th>Name</th>
<th>Expenses</th>
</tr>
<tr align="center">
<td>BITTU</td>
<td>2500.00</td>
</tr>
<tr>
<td align="right">RAKESH</td>
<td>1400.00</td>
</tr>
</table>
</body>
</html>
Nested tables are referred as tables inside another table. This makes HTML tables visually more
interesting and leads to complex table layout.
Example:
<table>
<caption>Nested Tables</caption>
<tr>
<th>Header of Table 1</th>
<th>Header of Table 2</th>
</tr>
<tr>
<td>
<table>
<tr>
<th>1st Header of nested table 1</th>
<th>2st Header of nested table 1</th>
</tr>
<tr>
<td>1st cell of nested table</td>
<td>2st cell of nested table</td>
</tr>
<td>3rd cell of nested table</td>
<td>4th cell of nested table</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<th>1st Header of nested table 2</th>
<th>2st Header of nested table 2</th>
</tr>
<tr>
<td>1st cell of nested table</td>
<td>2st cell of nested table</td>
</tr>
<td>3rd cell of nested table</td>
<td>4th cell of nested table</td>
</tr>
</table>
</td>
</tr>
</table>
Output:
• The <form> element is a container for different types of input elements, such as: text
fields,checkboxes, radio buttons, submit buttons, etc.
• The <input type="text"> defines a single-line input field for text input.
• The default width of an input field is 20 characters.
Example:
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname">
</form>
Output
First name:
Last name:
Output
Choose your favorite Web language:
HTML
CSS
JavaScript
2.4.2.3 Checkboxes
• The <input type="checkbox"> defines a checkbox.
• Checkboxes let a user select ZERO or MORE options of a limited number of choices.
Example: A form with checkboxes
<form>
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label>
</form>
Output:
I have a bike
I have a car
I have a boat
• The form-handler is typically a file on the server with a script for processing input
data.
• The form-handler is specified in the form's action attribute.
Last name:
Value Description
URL Where to send the form-data when the form is
submitted.Possible values:
• An absolute URL - points to another web site
(likeaction="http://www.example.com/example.htm")
• A relative URL - points to a file within a web site (like
action="example.htm")
Example
• On submit, send the form-data to a file named "action_page.php" (to process the input):
• In the example below, the form data is sent to a file called "action_page.php". This file
containsa server-side script that handles the form data:
<!DOCTYPE html>
<html>
<body>
<h1>The form action attribute</h1>
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
</form>
<p>Click the "Submit" button and the form-data will be sent to a page on the
server called "action_page.php".</p>
</body>
</html>
Output:
The form action attribute
First name:
Last name:
• Click the "Submit" button and the form-data will be sent to a page on the server
called"action_page.php"
2.4.4 The Method Attribute
• The method attribute specifies the HTTP method to be used when submitting the form
data.
• The form-data can be sent as URL variables (with method="get") or as HTTP post
transaction(with method="post").
• The default HTTP method when submitting form data is GET.
<form action="/action_page.php" method="get">
Example
<!DOCTYPE html>
<html>
<body>
<h2>The method Attribute</h2>
<p>This form will be submitted using the GET method:</p>
<form action="/action_page.php" target="_blank" method="get">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
<p>After you submit, notice that the form values is visible in the address bar
of the newbrowser tab.</p>
</body>
</html>
Output:
This form will be submitted using the GET method:
First name:
Last name:
• After you submit, notice that the form values are visible in the address bar of the new
browsertab.
• The default HTTP method when submitting form data is GET.
Notes on GET:
• Appends the form data to the URL, in name/value pairs
• NEVER use GET to send sensitive data! (the submitted form data is visible in the
URL!)
• The length of a URL is limited (2048 characters)
• Useful for form submissions where a user wants to bookmark the result
• GET is good for non-secure data, like query strings in Google
Notes on POST:
• Appends the form data inside the body of the HTTP request (the submitted form data
is not shown in the URL)
• POST has no size limitations, and can be used to send large amounts of data.
• Form submissions with POST cannot be bookmarked
Tip: Always use POST if the form data contains sensitive or personal information!
Example:
<!DOCTYPE>
<html>
<body>
<div style="border:1px solid black; padding:20px; background-color:lightblue; text-
align:center; font-size:20px">
<p>Welcome to web classes.</p>
<p>This is second paragraph</p>
</div>
</body>
</html>
Output:
Output:
into multimedia web pages. HTML describes the structure of a web page semantically and
originally included cues for the appearance of the document.
CSS
Formal language, which is used as a description zone, formatting the appearance of a web page,
written by the help of markup languages HTML and XHTML, but it can be applied to any
XML-document, for example, to SVG or XUL.
• The div element has no special meaning. It is often used as a block of children elements.
• The section element introduced in HTML5 standard is used to group related elements,
such as a subsection of a long article.
• In short, the section element provides more semantic syntax than the div element.
Attributes
Examples:
• Define keywords for search engines:
<meta name="keywords" content="HTML, CSS, JavaScript">
• Define a description of your web page:
<meta name="description" content="Free Web tutorials for HTML and CSS">
• Define the author of a page:
<meta name="author" content="John Doe">
• Refresh document every 30 seconds:
<meta http-equiv="refresh" content="30">
• Setting the Viewport to make your website look good on all devices:
o The viewport is the user's visible area of a web page. It varies with the device - it
will be smaller on a mobile phone than on a computer screen.
o You should include the following <meta> element in all your web pages:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
o This gives the browser instructions on how to control the page's dimensions and
scaling.
o The width=device-width part sets the width of the page to follow the screen-width
of the device (which will vary depending on the device).
o The initial-scale=1.0 part sets the initial zoom level when the page is first loaded
by the browser.
o Here is an example of a web page without the viewport meta tag, and the same web
page with the viewport meta tag:
Without the viewport meta tag With the viewport meta tag
Example program:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="keywords" content="HTML, CSS, JavaScript, Tutorials">
<meta name="description" content="Free Online tutorials">
<meta name="author" content="thisauthor">
<meta http-equiv="refresh" content="5; url=https://www.javatpoint.com/html-tags-
list">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h2>Example of Meta tag</h2>
<p>This example shows the use of meta tag within an HTML document</p>
</body>
</html>
Output:
• The <title> tag defines the title of the document. The title must be text-only, and it is shown
in the browser's title bar or in the page's tab.
• The contents of a page title is very important for search engine optimization (SEO).
• The page title is used by search engine algorithms to decide the order when listing pages
in search results.
o Don't use "keyword blobs." If your title is just a list of words, algorithms often
reduce your page's position in the search results.
o Try to make sure your titles are as unique as possible within your own site.
Duplicate—or near-duplicate—titles can contribute to inaccurate search results.
• Note: You can NOT have more than one <title> element in an HTML document.
• The <style> HTML element contains style information for a document, or part of a
document. It contains CSS, which is applied to the contents of the document containing
the <style> element.
• Inside the <style> element you can specify how HTML elements should render in a
browser.
• The <style> element must be included inside the <head> of the document. In general, it is
better to put styles in external stylesheets and apply them using <link> elements.
• Note: When a browser reads a style sheet, it will format the HTML document according
to the information in the style sheet. If some properties have been defined for the same
selector (element) in different style sheets, the value from the last read style sheet will be
used.
• If you include multiple <style> and <link> elements in your document, they will be
applied to the DOM in the order they are included in the document - make sure you include
them in the correct order, to avoid unexpected cascade issues.
• In the same manner as <link> elements, <style> elements can include media attributes that
contain media queries, allowing to selectively apply internal stylesheets to document
depending on media features such as viewport width.
• Attributes
• Example:
<html>
<head>
<style>
h1 {color:red;}
p {color:blue;}
</style>
<style>
h1 {color:green;}
p {color:pink;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
(Note: The Document Object Model (DOM) is a programming API for HTML and XML
documents. It defines the logical structure of documents and the way a document is accessed and
manipulated.)
Element Attribute
• Example
Use of the style attribute in an HTML document:
• The HTML <script> tag declares client-side script (JavaScript) in an HTML document.
When defining a client-side script the script tag is used for image manipulation, form
validation, and dynamic changes of content.
• The tag can include either the script itself or a link to an external file containing scripts.
The path to the external file is specified with src attribute. If you connect an external file
with scripts, don’t embed script into the same <script> tag.
• The HTML <script> tag can be placed in the <head> element, as well as within
the <body> element.
• The script execution doesn’t depend on its location in an HTML document, but the scripts,
that must be executed first, must be placed in the heading of the document.
• Attributes
Attribute Value Description
Defines, that the script must be executed after the loading of the
defer defer
page. (For external scripts only).
<script type="text/javascript">
document.write("JavaScript is a simple language for javatpoint learners")
</script>
Output:
JavaScript is a simple language for javatpoint learners
• The <link> tag defines the relationship between the current document and an external
resource.
• The <link> tag is most often used to link to external style sheets or to add a favicon to your
website.
• All <link> elements should be placed in the <head> section of the document (commonly
before the closing </head> tag), and they can be used many times.
• The <link> tag can be used to link different versions of a page. This is useful if there are
several translations of content.
• An HTML document can have several <link> elements for loading different types of script
or page.
• Example
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
(Note: A favicon is a small, 16x16 pixel icon used on web browsers to represent a website or a
web page. Short for “favorite icon,”’ favicons are commonly displayed on tabs at the top of a web
browser, - but they’re also found on your browser’s bookmark bar, history and in search results,
alongside the page url.
When favicon is created, it serves as website’s icon, or a visual identifier for users to spot website
around the web.
A favicon may also be referred to as a shortcut icon, tab icon, URL icon or bookmark icon.)
• Attributes
Attribute Value Description
media media_query Defines the device, for which the styles will be applied.
alternate
archives
author
bookmark
external
first
help
icon
last
license
Defines the relationship between the current document and the
rel next
linked file.
nofollow
noreferrer
pingback
prefetch
prev
search
sidebar
stylesheet
tag
up
sizes HeightxWeight Sets the size of associated icons. Used only with rel = "icon".
Before we proceed to XHTML, let us have a quick view on what are HTML, XML, and
SGML.
• What is SGML?
This is Standard Generalized Markup Language (SGML) application conforming to
International Standard ISO 8879.
This is a language for describing markup languages, particularly those used in electronic
document exchange, document management, and document publishing. HTML is an
example of a language defined in SGML. HTML is widely regarded as the standard
publishing language of the World Wide Web.
• What is XML?
XML stands for EXtensible Markup Language. XML is a markup language much like
HTML and it was designed to describe data. XML tags are not predefined. You must define
your own tags according to your needs.
• What is HTML?
HTML is an acronym which stands for Hyper Text Markup Language which is used for
creating web pages and web applications. It describes the structure of a Web page and
consists of series of elements (the building blocks of a web page) such as tags and
attributes. These elements tell the browser how to display the content. HTML elements
label pieces of content such as "this is a heading", "this is a paragraph", "this is a link", etc.
• Let's see what is meant by Hypertext Markup Language, and Web page.
Hyper Text: HyperText simply means "Text within Text." A text has a link within it, is a
hypertext. Whenever you click on a link which brings you to a new webpage, you have
clicked on a hypertext. HyperText is a way to link two or more web pages (HTML
documents) with each other.
Markup language: A markup language is a computer language that is used to apply layout
and formatting conventions to a text document. Markup language makes text more
interactive and dynamic. It can turn text into images, tables, links, etc.
Web Page: A web page is a document which is commonly written in HTML and translated
by a web browser. A web page can be identified by entering an URL. A Web page can be
of the static or dynamic type. With the help of HTML only, we can create static web pages.
XHTML
• XHTML stands for extensible hypertext markup language which is a connection between
HTML (hypertext mark-up language) and XML (extensible markup language) also at most
of the places XHTML is considered superior than HTML.
• It is the next step in the evolution of the internet. The XHTML 1.0 is the first document
type in the XHTML family.
• XHTML is almost identical to HTML 4.01 with only few differences. This is a cleaner and
stricter version of HTML 4.01. Therefore, it is more compatible with most browsers, and
it maintains a standard of code that can be used for various devices.
• XHTML was developed by World Wide Web Consortium (W3C) to help web developers
make the transition from HTML to XML.
• XHTML is easy to use with other data formats, and it creates more neat code as it is stricter
than HTML.
• XHTML syntax is very similar to HTML syntax and almost all the valid HTML elements
are valid in XHTML as well. But when writing an XHTML document, need to pay extra
attention to make HTML document compliant to XHTML.
• Here are the important points to remember while writing a new XHTML document or
converting existing HTML document into XHTML document −
o Write a DOCTYPE declaration at the start of the XHTML document.
o Write all XHTML tags and attributes in lower case only.
o Close all XHTML tags properly.
o Nest all the tags properly.
o Quote all the attribute values.
o Forbid Attribute minimization.
o Replace the name attribute with the id attribute.
o Deprecate the language attribute of the script tag.
http://www.tutorialspoint.com/xhtml/index.htm
Validate Page
• This validator checks the markup_validity of web documents with various formats
especially in HTML, XHTML, SMIL, MathML, etc.
• There are other tools to perform different other validations.
o RSS/Atom feeds Validator
o CSS stylesheets Validator
o Find Broken Links
o Other validators and tools
Advantages of XHTML
• While using XHTML, the code of web applications becomes more stylish and easier to
reuse.
• It can help the developer create more advanced web projects due to the compatibility with
various devices, and it also supports self-created markups like SVG (scalable vector
graphics).
• XHTML code can easily be converted to PDFs, RSS, and RFT, which allows the developer
to work with a vast range of files.
• XHTML reduce the loading time required by the browser to load an event which can result
in overall speedy development, thus reducing time and energy
• It contains closing tags which is an advantage for beginners, and this also makes the code
look clean and easy to reuse.
• Since XHTML is an official standard of the W3C, your website becomes more compatible
with many browsers and it is rendered more accurately.
• XHTML combines strength of HTML and XML. Also, XHTML pages can be rendered by
all XML enabled browsers.
• XHTML defines quality standard for your webpages and if you follow that, then your web
pages are counted as quality web pages. The W3C certifies those pages with their quality
stamp.
• Client-side Image Map Module − It provides elements for client-side image maps − area
and map.
• Server-side Image Map Module − It provides support for image-selection and
transmission of selection coordinates. The Server-side Image Map Module supports −
attribute ismap on img.
• Intrinsic Events Module − It supports all the events discussed in XHTML Events.
• Meta information Module − The Meta information Module defines an element that
describes information within the declarative portion of a document. It includes element
meta.
• Scripting Module − It defines the elements used to contain information pertaining to
executable scripts or the lack of support for executable scripts. Elements and attributes
included in this module are − noscript and script.
• Style Sheet Module − It defines an element to be used when declaring internal style
sheets. The element and attribute defined by this module is − style.
• Style Attribute Module (Deprecated) − It defines the style attribute.
• Link Module − It defines an element that can be used to define links to external resources.
It supports link element.
• Base Module − It defines an element that can be used to define a base URI against which
relative URIs in the document are resolved. The element and attribute included in this
module is − base.
• Ruby Annotation Module − XHTML also uses the Ruby Annotation module as defined
in RUBY and supports − ruby, rbc, rtc, rb, rt, and rp
All XHTML documents must contain a DOCTYPE declaration at the start. There are three
types of DOCTYPE declarations:
o Strict
o Transitional
o Frameset
XHTML 1.0 Strict
o If you are planning to use Cascading Style Sheet (CSS) strictly and avoiding to write most
of the XHTML attributes, then it is recommended to use this DTD. A document
conforming to this DTD is of the best quality.
o If you want to use XHTML 1.0 Strict DTD then you need to include the following line at
the top of your XHTML document.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
XHTML 1.0 Transitional
o If you are planning to use many XHTML attributes as well as few Cascading Style Sheet
properties, then you should adopt this DTD and you should write your XHTML document
accordingly.
o If you want to use XHTML 1.0 Transitional DTD, then you need to include the following
line at the top of your XHTML document.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
o You can use this when you want to use HTML Frames to partition the browser window
into two or more frames.
o If you want to use XHTML 1.0 Frameset DTD, then you need to include following line at
the top of your XHTML document.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset
• Case sensitivity:
In HTML, tag and attribute names are case insensitive, meaning that <FORM>, <form>,
and <Form> are equivalent. In XHTML, tag and attribute names must be all lowercase.
• Closing tags:
In HTML, closing tags may be omitted if the processing agent (usually a browser) can infer
their presence. For example, in HTML, paragraph elements often do not have closing tags.
The appearance of another opening paragraph tag is used to infer the closing tag on the
previous paragraph. Thus, in HTML we could have
<p>
During Spring, flowers are born. ...
<p>
During Fall, flowers die. ...
In XHTML, all elements must have closing tags. For elements that do not include content, in
which the closing tag appears to serve no purpose, a slash can be included at the end of the
opening tag as an abbreviation for the closing tag. For example, the following two lines are
equivalent in XHTML:
<input type = ”text” name = ”address”> < / input>
and
<input type = ”text” name = ”address” / >
Some browsers can become confused if the slash at the end is not preceded by a space.
In HTML, attribute values must be quoted only if there are embedded special characters or
white-space characters. Numeric attribute values are rarely quoted in HTML. In XHTML, all
attribute values must be double quoted, regardless of what characters are included in the
value.
<!-- This is invalid in XHTML -->
<img src="/images/xhtml.gif" width=250 height=50 />
In HTML, some attribute values are implicit; that is, they need not be explicitly stated. For
example, if the multiple attribute appears in a select tag without a value, it specifies that
multiple items can be selected. The following is valid in HTML:
Here is a list of the minimized attributes in HTML and the way to write them in XHTML.
compact compact="compact"
checked checked="checked"
declare declare="declare"
readonly readonly="readonly"
disabled disabled="disabled"
selected selected="selected"
defer defer="defer"
ismap ismap="ismap"
nohref nohref="nohref"
noshade noshade="noshade"
nowrap nowrap="nowrap"
multiple multiple="multiple"
noresize noresize="noresize"
• Element nesting:
Although HTML has rules against improper nesting of elements, they are not enforced.
Examples of nesting rules are:
(1) an anchor element cannot contain another anchor element, and a form element cannot
<script type="text/JavaScript">
document.write("Hello XHTML!");
</script>
Example Program 1:
Strict DTD: It is used when XHTML page contains only markup language. Strict DTD is used
together with cascading style sheets, because this attribute does not allow CSS property in body
tag.
margin-bottom:-25px;">GeeksforGeeks</div>
<p style="text-align:center;font-size:20px;">
A computer science portal</p>
<p style="text-align:center;font-size:20px;">
Option to choose month:
<select name="month">
<option selected="selected">January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>Augusy</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
</p>
</body>
</html>
Output:
Example Program 2:
Transitional DTD: It is supported by the older browsers which does not have inbuilt cascading
style sheets supports. There are several attributes enclosing the body tag which are not allowed
in strict DTD.
<p style="text-align:center;font-size:20px;">
A computer science portal</p>
<p style="text-align:center;font-size:20px;">
Option to choose month:
<select name="month">
<option selected="selected">January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>Augusy</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
</p>
</body>
</html>
Output:
Example Program 3:
Frameset DTD: The frameset DTD is used when XHTML page contains frames.
Output: