Spiegato, Home

Technology and Gadgets

How do I Convert HTML to XHTML?

  • Published by Spiegato
  • 2 min read

The eXtensible HyperText Markup Language (XHTML) has replaced the similar HyperText Markup Language (HTML) as the markup language of choice for creating webpages, but old webpages are relatively easy to convert from HTML to XHTML. First, choose the appropriate version of XHTML to convert to because different versions support different features. Then make changes to the code by hand to better understand the new language’s syntax rules or use a software tool to convert pages for you. In either case, it is a good idea to check that the document was converted properly with an XHTML validator, which can detect any errors in the code.

Keep in mind that just like HTML, XHTML has several different versions, and not all of them support the same features. XHTML 1.0 Transitional allows certain presentational tags, elements, and attributes present in earlier HTML standards including the tag and “center” attributes. If you’re moving from HTML to XHTML 1.0 Strict or XHTML 1.1, remove any any presentational tags or elements and recreate the desired look using Cascading Style Sheets because these versions of XHTML do not support any presentational elements.

For a simple web document, it’s possible to perform an HTML to XHTML conversion by hand. If you’re new to XHTML, this may also help you become more familiar with the stricter syntax rules of the language. To conform to these stricter requirements, make sure that all tags are in lower case, properly nested, and closed with a forward slash. In addition, all values must be inside quotation marks. The “find and replace all” option available in most text editors and web development programs can help you make these changes.

Software can also convert your code from HTML to XHTML with just a few clicks. Most professional web design programs have this option, often under the “File” or “Tools” menu. A popular tool called HTML Tidy, originally released by members of the World Wide Web Consortium (W3C), can be downloaded for free and will both clean up and convert between popular web formats. You might also be able to find a few tools online that can change documents from one markup language to another.

Whether you choose to edit your documents by hand or use software to perform the HTML to XHTML conversion, there are a few things you should check before publishing your pages to the web. To be valid XHTML, a page should have both a Document Type Definition (DOCTYPE or DTD) and an XML namespace declaration. Each of these will depend on what version of XHTML you use, so do a little research to figure out what these elements should look like. An XHTML validator, available within most web development software as well as on the W3C’s website, will inform you of any errors or omissions in your code.

Key terms in this article

Related articles

  • What Is an HTML to PDF Converter?

    A hypertext markup language (HTML) to portable document format (PDF) converter is a software program that takes a finished document of HTML code and…

  • How Do I Convert MHTML to HTML?

    While a MHTML-encoded file contains portions that are pure HTML code, complications can occur when attempting to convert MHTML to HTML. Several programs…

  • What Are the Best Tips for HTML to PSD Conversion?

    Many website designers used Adobe® Photoshop® to create fast mockups of a website before committing the design to a HyperText Markup Language (HTML) file…

  • What is XHTML?

    The extensible hypertext markup language (XHTML) is a quick way to refer to several language recommendations that are widely used on Internet-enabled…

  • What are the Differences Between XHTML and CSS?

    The eXtensible HyperText Markup Language (XHTML) and Cascading Style Sheets (CSS) are both computer programming languages commonly used in web…