What is XHTML?


 

What is XHTML?

Understand XHTML and create simple XHTML file.

Understand XHTML and create simple XHTML file.

What is XHTML

XHTML (eXtensible HyperText Markup Language) is extended, stricter and cleaner version of HTML 4 and is designed to work with XML.

Rules for creating XHTML document

In html, if you omit an end-tag or leave a quote etc, the page still displays its content and nothing too serious happens with the page. But as XHTML is a combination of html and xml, writing code is much harder and stricter than html but it makes the code cleaner and more self explanatory. XHTML document should follow some rules as given below:

  1. Tags and attributes names must be in lowercase
  2. "Empty" tags must be properly ended with closing slash
  3. Tags with opening tag must have an end tag
  4. Attributes must always have a value
  5. Attributes values must be quoted
  6. Must have a DOCTYPE declaration.
  7. html, head, title, and body elements must be present.

Valid XHTML documents:

  1. The XHTML document must have html as root element, and must contain an xmlns attribute to link it with the XHTML namespace.

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

  2. A Document Type Declaration, or DOCTYPE, may be used to validate an XHTML document.
  3. XHTML document may have XML declaration at the beginning.

    <?xml version="1.0" encoding="UTF-8"?>

Why XHTML

  1. The code is cleaner and more self-explanatory.
  2.  Web browsers are able to parse, process and display the page more easily than one with errors and unformatted code.
  3. Easy to maintain, edit, convert and format the code.
  4. Render more correctly in more browsers because of following W3C standard rules.
  5. Increased interoperability
  6. Greater accessibility

Sample XHTML document: 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title> Sample XHTML</title>
</head>
<body>
<p>Sample XHTML</p>
</body>
</html>

Ads