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>
link|improve this question

Can you pastebin an example xhtml file? I did a test on my computer and google chrome opened up my xhtml file without issue. Perhaps you have the wrong DOCTYPE declared? – OmnipotentEntity Apr 17 '11 at 5:45
I've added the example, thanks. – Xie Jilei Apr 17 '11 at 5:56
feedback

1 Answer

up vote 5 down vote accepted

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>
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.