What is XHTML
XHTML stands for Extensible Hypertext Markup Language. It is a cross between HTML and
XML language.
XHTML is almost identical to HTML but it is stricter than HTML. XHTML is HTML defined as an
XML application. It is supported by all major browsers.
Although XHTML is almost the same as HTML but It is more important to create your code
correctly, because XHTML is stricter than HTML in syntax and case sensitivity. XHTML documents
are well-formed and parsed using standard XML parsers, unlike HTML, which requires a lenient
HTML-specific parser.
History
XHTML 1.0 became a World Wide Web Consortium (W3C) Recommendation on January 26, 2000.
XHTML 1.1 became a W3C Recommendation on May 31, 2001. The standard known as XHTML5
is being developed as an XML adaptation of the HTML5 specification.
Why use XHTML
XHTML was developed to make HTML more extensible and increase interoperability with other
data formats. There are two main reasons behind the creation of XHTML:
o It creates a stricter standard for making web pages, reducing incompatibilities between browsers.
So it is compatible for all major browsers.
o It creates a standard that can be used on a variety of different devices without changes.
Let's take an example to understand it.
HTML is mainly used to create web pages but we can see that many pages on the internet contain
"bad" HTML (not follow the HTML rule).
This HTML code works fine in most browsers (even if it does not follow the HTML rules).
For example:
<html>
<head>
<title>This is an example of bad HTML</title>
<body>
<h1>Bad HTML
<p>This is a paragraph
</body>
The above HTML code doesn't follow the HTML rule although it runs. Now a day, there are
different browser technologies. Some browsers run on computers, and some browsers run on mobile
phones or other small devices. The main issue with the bad HTML is that it can't be interpreted by
smaller devices.
So, XHTML is introduced to combine the strengths of HTML and XML.
XHTML is HTML redesigned as XML. It helps you to create better formatted code on your site.
XHTML doesn't facilitate you to make badly formed code to be XHTML compatible. Unlike with
HTML (where simple errors (like missing out a closing tag) are ignored by the browser), XHTML
code must be exactly how it is specified to be.
What is 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.
XHTML is easy to use with other data formats, and it creates more neat code as it is stricter than
HTML. Therefore, it is more compatible with most browsers, and it maintains a standard of code that
can be used for various devices.
Example
Below is an example of XHTML,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title> XHTML document </title>
</head>
<body>
Wrong XHTML rule<br>
Correct XHTML rule<br />
Wrong XHTML rule <hr>
Correct XHTML rule <hr />
Wrong XHTML rule <img src=" pic/ document / mypic.gif" alt=" picture of a boy playing in a field
">
Correct XHTML rule <img src="pic/ document / mypic.gif" alt="picture of a boy playing in a field "
/>
</body>
</html>
Output
The above code gives the following output.
Correct XHTML rule
Correct XHTML rule
Correct XHTML rule
Advantages of XHTML
Here are the following advantages of XHTML, such as:
o While using XHTML, the code of web applications becomes more stylish and easy to reuse.
o 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).
o XHTML code can easily be converted to PDFs, RSS, and RFT, which allows the developer to
work with a vast range of files.
o 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
o It contains closing tags which is an advantage for beginners, and this also makes the code look
clean and easy to reuse.
Disadvantages of XHTML
XHTML also has some disadvantages, such as:
o Very few browsers use XHTML.
o Case sensitive as every part of code should be in lowercase.
o It is mandatory to write < DOCTYPE > declaration.
o And all the tags must be closed in the necessary order.
AD
What is HTML?
Hypertext Mark-up Language (HTML) is a programming language that shows information and
depicts a site page's design. Hypertext works with perusing the web by referring to an HTML page's
hyperlinks. The hyperlink empowers one to go to any put on the web by clicking it. There is no set
request to do as such.
Mark-up language calls attention to how labels characterize the page design and the components
inside the page. It comprises different HTML components containing labels and their substance.
HTML language empowers the formation of connections of reports, is static, and can overlook little
mistakes. In HTML, shutting labels are excessive. It tends to be characterized as a markup language
that makes the content unique and intelligent.
HTML is a programming language used to make sites that anybody with web access can see. The
labels are the words between the < angle brackets > and separate standard content from HTML code.
These are shown on website pages as pictures, tables, outlines, etc.
The labels are not shown on the pages however influence the presence of information on site pages.
Various sorts of tags perform various capacities.
o < body >
o < li >
o < br >
o < strong >
o < em >
Example
Below is an basic example of HTML.
<! DOCTYPE html >
< html >
< head >
< title > Title < /title >
< /head >
< body >
< h1 > Hello World < /h1 >
< p > welcome this is your first HTML program < /p >
< /body >
< /html >
Output
The above code gives the following output.
Hello World
Welcome this is your first HTML program
Advantages of HTML
Some advantages of HTML are given below:
o HTML helps assemble a site's design and different benefits, like Easy to learn and utilize.
o Upheld by all programs.
o It being explicit content, it is easy to alter.
o Simple to coordinate with different dialects.
o Lightweight
o HTML is the premise of all programming dialects.
o The content being compressible, it is quick to download.
Disadvantages of HTML
HTML also has some disadvantages, such as:
o HTML can make only plain and static pages.
o A great deal of code is needed to be composed to make a basic website page.
o HTML security highlights aren't awesome.
o Complex to compose long code for making website pages.
o Sets aside a great deal of effort to make a website page.
o All website pages should be altered independently, not concentrated.
Difference between HTML and XHTML
HTML and XHTML are both markup languages used to create web pages and applications. HTML
and XHTML have some key differences that set them apart. Here are the following major differences
between HTML and XHTML:
S.No HTML XHTML
.
1. Hypertext mark-up language - - > HTML Extensible Hypertext Mark-up
Language - - > XHTML.
2. Tim Berners created in 1991 World wide web consortium or W3C
created in 2000
4. It is an extension of standard generalized markup It is a combination of extensible
language or SGML markup language XML and hypertext
markup language HTML
5. It stored in a document file format It stored as a markup language format
6. It is not case sensitive as there is no mandatory rule It is case-sensitive, and every tag and
to write the entire mark up in uppercase or lower attribute used inside must be in
case. It can also be a combination of both. lowercase.
7. It is not mandatory to add document label < It is mandatory to add a document label
DOCTYPE >at the top of every page. We can even < DOCTYPE > at the beginning of the
skip it. page.
8. We can close any tag anytime and anywhere as per It is mandatory to close all the tags in
our needs strict residing order as they were
declared.
9. We can add attributes without any quotes. It is mandatory to add quotes on every
attribute we declare
10. ,html and .htm are the extensions used by HTML .xhtml, .xml and .xht are the file
extensions used by XHTML
11 Lewd structure is used It contains a very strict structure, and
the developer cannot go out of the
bounds of these structures.
HTML syntax is very similar to HTML syntax and all the valid HTML elements are also valid in
XHTML. But XHTML is case sensitive so you have to pay a bit extra attention while writing an
XHTML document to make your HTML document compliant to XHTML.
You must remember the following important points while writing a new XHTML document or
converting existing HTML document into XHTML document:
o All documents must have a DOCTYPE.
o All tags must be in lower case.
o All documents must be properly formed.
o All tags must be closed.
o All attributes must be added properly.
o The name attribute has changed.
o Attributes cannot be shortened.
o All tags must be properly nested.
DOCTYPE Declaration
All XHTML documents must contain a DOCTYPE declaration at the start. There are three types of
DOCTYPE declarations:
o Strict
o Transitional
o Frameset
Here is an example of using DOCTYPE.
1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
Tags must be in lower case
XHTML is case-sensitive markup language. So, all the XHTML tags and attributes must be written
in lower case.
1. <!-- Invalid in XHTML -->
2. <A Href="/xhtml/xhtml_tutorial.html">XHTML Tutorial</A>
3. <!-- Valid in XHTML -->
4. <a href="/xhtml/xhtml_tutorial.html">XHTML Tutorial</a>
Closing Tags are mandatory
An XHTML must have an equivalent closing tag. Even empty elements should also have closing
tags. Let's see an example:
1. <!-- Invalid in XHTML -->
2. <p>This paragraph is not written according to XHTML syntax.
3. <!-- Invalid in XHTML -->
4. <img src="/images/xhtml.gif" >
5. <!-- Valid in XHTML -->
6. <p>This paragraph is not written according to XHTML syntax.</p>
7. <!-- Valid in XHTML-->
8. <img src="/images/xhtml.gif" />
Attribute Quotes
All the XHTML attribute's values must be quoted. Otherwise, your XHTML document is assumed as
an invalid document.
See this example:
1. <!-- Invalid in XHTML -->
2. <img src="/images/xhtml.gif" width=250 height=50 />
3. <!-- Valid in XHTML -->
4. <img src="/images/xhtml.gif" width="250" height="50" />
Attribute Minimization
XHTML doesn't allow you to minimize attributes. You have to explicitly state the attribute and its
value.
See this example:
1. <!--Invalid in XHTML -->
2. <option selected>
3. <!-- valid in XHTML-->
4. <option selected="selected">
A list of minimized attributes in HTML and the way you need to write them in XHTML.
HTML Style XHTML Style
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"
The id Attribute
The id attribute is used to replace the name attribute. Instead of using name = "name", XHTML
prefers to use id = "id".
See this example:
1. <!-- Invalid in XHTML -->
2. <img src="/images/xhtml.gif" name="xhtml_logo" />
3. <!-- Valid in XHTML -->
4. <img src="/images/xhtml.gif" id="xhtml_logo" />
The language attribute
In XHTML, the language attribute of script tag is deprecated so you have to use type attribute instead
of this.
See this example:
1. <!-- Invalid in XHTML -->
2. <script language="JavaScript" type="text/JavaScript">
3. document.write("Hello XHTML!");
4. </script>
5. <!-- Valid in XHTML -->
6. <script type="text/JavaScript">
7. document.write("Hello XHTML!");
8. </script>
Nested Tags
XHTML tags must be nested properly. Otherwise your document is assumed as an incorrect XHTML
document.
See this example:
AD
1. <!-- Invalid in XHTML -->
2. <b><i> This text is bold and italic</b></i>
3. <!-- Valid in XHTML -->
4. <b><i> This text is bold and italic</i></b>
Element Prohibitions
The following elements are not allowed to have any other element inside them. This is applicable for
all the descending elements.
Elemen Prohibition
t
<a> It must not contain other <a> elements.
<pre> It must not contain the <img>, <object>, <big>, <small>, <sub>, or <sup> elements.
<button> It must not contain the <input>, <select>, <textarea>, <label>, <button>, <form>,
<fieldset>, <iframe> or <isindex> elements.
<label> It must not contain other <label> elements.
<form> It must not contain other <form> elements.