Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Introduction to XHTML


May 02, 2021 HTML


Table of contents


HTML - XHTML


XHTML is HTML written in XML format.


What is XHTML?

  • XHTML refers to an extensable hyper-text tag language

  • XHTML is almost identical to HTML 4.01

  • XHTML is a stricter and purer version of HTML

  • XHTML is HTML defined as an XML app

  • XHTML is the W3C recommendation standard released in January 2001

  • XHTML is case sensitive, and standard XHTML tags should use small case.

  • XHTML is supported by all major browsers


Why use XHTML?

Many pages on the Internet contain "bad" HTML.

If viewed in a browser, the following HTML code works fine (even if it does not follow HTML rules):

<html>

<head>

<title>This is bad HTML</title>

<body>

<h1>Bad HTML

<p>This is a paragraph

</body>

XML is a well-formed markup language that must be properly marked.

If you want to learn XML, read our XML tutorial.

There are some different browser technologies in today's tech world. S ome of them run on your computer, while others may run on mobile phones or other small devices. Small devices often lack the resources and ability to interpret "bad" markup language.

So - XHTML was developed by combining the strengths of XML and HTML. XHTML is HTML that has been redesigned as XML.


The most important difference from HTML:

The document structure

  • XHTML DOCTYPE is mandatory

  • The XML namespace property in slt;html is mandatory

  • It is also mandatory

Element syntax

  • XHTML elements must be nested correctly

  • XHTML elements must always be turned off

  • XHTML elements must be in small case

  • The XHTML document must have a root element

Property syntax

  • XHTML properties must use small case

  • XHTML property values must be surrounded by quotation marks

  • Minimization of XHTML properties is also prohibited


<! D OCTYPE .... It is mandatory

XHTML documents must be declared as XHTML document types (XHTML DOCTYPE declaration).

You can find the full XHTML documentation type in W3Cschool's label reference manual.

The elements must also exist, and the xmlns property in the document must also exist, and the xmlns property in the .lt;html>, and the xmlns property in the document must also exist.

The following example shows an XHTML document with the fewest required labels:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Title of document</title>

</head>

<body>

......

</body>

</html>



XHTML elements must be reasonably nested

In HTML, some elements can not nest with each other, like this:

<b><i>This text is bold and italic</b></i>

In XHTML, all elements must be reasonably nested with each other, like this:

<b><i>This text is bold and italic</i></b>



XHTML elements must have a close label

Example of an error:

<p>This is a paragraph

<p>This is another paragraph

The correct example:

<p>This is a paragraph</p>

<p>This is another paragraph</p>



The empty element must contain a close label

Example of an error:

A break: <br>

A horizontal rule: <hr>

An image: <img src="happy.gif" alt="Happy face">

The correct example:

A break: <br />

A horizontal rule: <hr />

An image: <img src="happy.gif" alt="Happy face" />



XHTML elements must be small case

Example of an error:

<BODY>

<P>This is a paragraph</P>

</BODY>

The correct example:

<body>

<p>This is a paragraph</p>

</body>



The property name must be small

Example of an error:

<table WIDTH="100%">

The correct example:

<table width="100%">



Property values must be quoted

Example of an error:

<table width=100%>

The correct example:

<table width="100%">



Property shorting is not allowed

Example of an error:

<input checked>

<input readonly>

<input disabled>

<option selected>

The correct example:

<input checked="checked">

<input readonly="readonly">

<input disabled="disabled">

<option selected="selected">



How to convert HTML to XHTML

  1. Add an XHTML slt;! DOCTYPE; go to your web page

  2. Add the xmlns property to the html element of each page.

  3. Change all elements to small case

  4. Close all empty elements

  5. Modify all property names to be small

  6. All property values are quoted


Use the W3C authenticator to test your XHTML

Try it out . . .