Internet
Fact-checked

At EasyTechJunkie, we're committed to delivering accurate, trustworthy information. Our expert-authored content is rigorously fact-checked and sourced from credible authorities. Discover how we uphold the highest standards in providing you with reliable knowledge.

Learn more...

How do I Convert HTML to XHTML?

Robert Grimmick
Robert Grimmick

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 <font> 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.

Older web pages are relatively easy to convert from HTML to the newer XHTML.
Older web pages are relatively easy to convert from HTML to the newer XHTML.

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.

Discuss this Article

Post your comments
Login:
Forgot password?
Register:
    • Older web pages are relatively easy to convert from HTML to the newer XHTML.
      By: Stephen VanHorn
      Older web pages are relatively easy to convert from HTML to the newer XHTML.