Google-chrome – Chrome doesn’t render xhtml

google-chrome

Open local xhtml files in chrome, however, chrome treats it as XML files, and won't render it as HTML.

I don't want to change all my *.xhtml file extension to .html, so is there any workaround?

EXAMPLE

a.xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <title>Example</title>
    </head>
    <body>
        <b>Hello</b>, 
        <i>World</i>!
    </body>
</html>

Best Answer

Because you declared XHTML-1.0 strict your html tag needs an xml namespace:

<html xmlns="http://www.w3.org/1999/xhtml">

A few other validation issues: you need a character set declaration and your text needs a <p> around it.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Example</title>
    </head>
    <body>
      <p>
        <b>Hello</b>, 
        <i>World</i>!
      </p>
    </body>
</html>
Related Question