In an interview I was asked a question that I'd never thought about, which was "We already have HTML which fulfills all the requirements of writing a web page, so what's the need for XHTML?"
I Googled a lot and also read many articles, but I'm not able to get properly why XHTML has been introduced. Please explain to me.
XHTML was developed to make HTML more extensible and flexible to work with other data formats (such as XML). In addition, browsers ignore errors in HTML pages, and try to display the website even if it has some errors in the markup. So XHTML comes with a much stricter error handling.
XHTML documents can utilize applications such as scripts and applets that rely upon either the HTML Document Object Model or the XML Document Object Model. XHTML gives you a more consistent, well-structured format so that your webpages can be easily parsed and processed by present and future web browsers.
When you use XHTML instead of HTML, it makes any future conversions easier. Besides, XHTML has extensibility and it can be supplemented with other markup languages also. Besides, XML processing programs can convert any document in the XHTML to other formats very easily.
Features of XHTML: Unlike HTML, which is standard generalized markup language based, XHTML is XML-based. Compared to the rules of HTML, XHTML is stricter and does not allow any lapses in coding or structure. It prohibits the omission of any tags or usage of attribute minimization.
Because it is valid XML. That helps a lot since you can use a lot of tools originally designed for XML, such as XML parsers, XSLT, XPath, XQuery, ...
Normal HTML is a SGML dialect and that is not parsable without knowledge of the schema.
<ul> <li>one <li>two <li>three </ul>
is correct HTML but not correct XML. If you want to parse that, you have to know that ul
-elements have to be closed but li
s don't.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With