XHTML – Overview
What is XHTML?
· XHTML stands for EXtensible Hyper Text Markup Language.
· XHTML is HTML defined as an XML application.
· XHTML is a W3C Recommendation.
· XHTML is a combination of HTML and XML (EXtensible Markup Language), XML is designed to describe data, and HTML is designed to display data.
· XHTML elements must be properly nested.
· XHTML elements must always be closed.
· XHTML elements must be in lowercase.
· XHTML documents must have one root element.
XHTML Syntax Rules
· Attribute names must be in lower case.
· Attribute values must be quoted.
· Attribute minimization is forbidden.
· The XHTML DTD defines mandatory elements.
· An XHTML document must have a DOCTYPE declaration.
· The html, head, title, and body elements must also be present.
The Lang Attribute
The lang attribute applies to almost every XHTML element. It specifies the language of the content within an element.
If you use the lang attribute in an element, you must also add the xml:lang attribute, like this:
<div lang=”it” xml:lang=”it”>Ciao bella!</div>
XHTML Different Doctypes
The <!DOCTYPE> declaration is the very first thing in an XHTML document, before the <html> tag.
The <!DOCTYPE> declaration is not an XHTML tag; it is an instruction to the web browser about what version of the markup language the page is written in.
The <!DOCTYPE> declaration refers to a Document Type Definition (DTD). The DTD specifies the rules for the markup language, so that the browsers render the content correctly.
· XHTML 1.0 Strict
This DTD contains all HTML elements and attributes, but does NOT INCLUDE presentational or deprecated elements (like font). Framesets are not allowed. The markup must also be written as well-formed XML.
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
· XHTML 1.0 Transitional
This DTD contains all HTML elements and attributes, INCLUDING presentational and deprecated elements (like font). Framesets are not allowed. The markup must also be written as well-formed XML.
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
· XHTML 1.0 Frameset
This DTD is equal to XHTML 1.0 Transitional, but allows the use of frameset content.
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Frameset//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd”>
· XHTML 1.1
This DTD is equal to XHTML 1.0 Strict, but allows you to add modules (for example to provide ruby support for East-Asian languages).
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN” “http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>