Sobes.tech
Junior

What is the difference between HTML and XHTML?

sobes.tech AI

Answer from AI

HTML (HyperText Markup Language) is a markup language for creating web pages. XHTML (Extensible HyperText Markup Language) is a markup language that reformulates HTML in terms of XML.

Main differences:

  • Syntax: XHTML is stricter than HTML. All tags must be properly closed, use lowercase for tag and attribute names, and have a root element (usually <html>).
  • Parsing: HTML is parsed more flexibly, with browsers often trying to correct errors. XHTML requires parsing as XML, and parsing stops on errors.
  • XML compatibility: XHTML is fully compatible with XML tools and is extendable through namespaces. HTML is not XML.
  • Document types (DOCTYPE): In XHTML, DOCTYPE is mandatory and more strict, indicating the version used. In HTML5, DOCTYPE is significantly simplified.

Example syntax:

HTML:

<p>This is a paragraph.
<br>New line.

XHTML:

<p>This is a paragraph.<br />New line.</p>

Historically, XHTML was conceived as a replacement for HTML in the XML era, but with the advent of HTML5, its popularity decreased. HTML5 has become more flexible and maintains backward compatibility, whereas XHTML required migration.