Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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>
share|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. – Xiè Jìléi Apr 17 '11 at 5:56
    
The DOCTYPE is actually pretty irrelevant for browsers nowadays, one could just as well use <!DOCTYPE html> in an XML file and thus use XHTML5. It's the namespace that's important. The DOCTYPE can still be interesting for validation, especially for offline validation with XHTML 1.1 Second Edition when mixing modular XHTML it with other namespaces. – Christian Hujer Sep 4 '15 at 19:15
up vote 8 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>
share|improve this answer
1  
While the solution is correct, the reason is slightly different. Browsers usually do not load external entities. The DTD would default the xmlns attribute to the XHTML namespace, but the external entity of the DTD is not loaded. The xmlns is required for XHTML in general, not because of the XHTML 1.0 Strict doctype. Unless you use that namespace, the browser will simply have no idea that your XML elements are actually HTML. – Christian Hujer Sep 4 '15 at 19:13
    
Thanks for the clarification. – OmnipotentEntity Sep 4 '15 at 19:14
    
And the encoding declaration isn't needed. XML has a detection mechanism and explicitly says that on the XML declaration, the encoding is optional. – Christian Hujer Sep 4 '15 at 20:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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