What is the difference between .html and .xhtml extension? XHTML is a markup language or it'a different extension also
Solution 1
If served over HTTP, the file extension has no meaning. The only information that matters it the Content-Type header field where the media type of the resource is specified.
But when served from a local filesystem, the media type is normally identified by the file extension.
Edit I think the reason for why the extension .html is used even if it’s XHTML is because XHTML is HTML just with XML syntax and everyone is used to .html for HTML documents. (Although most XHTML documents are actually served as HTML as the media type text/html denotes HTML no matter what the document type declaration says.)
But again: extensions are not necessary when requested over HTTP. In HTTP the Content-Type header field tells what media type the resource should be interpreted with. So in theory you could use whatever extension you want or even use no extension at all (useful when content negotiation is used).
Solution 2
Use the extension which matches the MIME type:
-
.xhtml
is forapplication/xhtml+xml
documents -
.html
is fortext/html
documents
For instance, ePub3 requires .xhtml
:
It is strongly suggested that you use the .xhtml extension for all EPUB content documents. Browsers will not interpret HTML content as application/xhtml+xml without that extension.
References
- HTML5 and HTML/XHTML
- Properly Using CSS and JavaScript in XHTML Documents
- Create rich-layout publications in ePub3 with HTML5, CSS3, and MathML
Solution 3
IE (including IE8) is the only (significant) browser that doesn't support XHTML served as application/xhtml+xml
(corresponds to the xht
or xhtml
extensions).
Will everyone move to XHTML when IE supports it? Probably not. XML isn't easy to get right, especially if you have to incorporate user-supplied data, such as blog comments. (Though that might be solved with (X)HTML5 <iframe sandbox>
before IE starts playing along.) However, I don't have a crystal ball, so we'll just have to wait and see what happens.
Solution 4
Nobody cares what the file is named, just what the MIME type it's been transferred with is.
Jitendra Vyas
Hi, I am Jitendra a front-end developer from India specializing in web standards, accessibility, and usability based development.
Updated on June 04, 2022Comments
-
Jitendra Vyas almost 2 years
What is the difference between the
.html
and.xhtml
file extensions?What is the benefit of using the
.xhtml
extension?Why we are not using the
.xhtml
extension, is it just because of IE?What about .xhtml extension with IE 8?
Is
.xhtml
supported in other browsers besides IE? If yes, then what benefit we will get when all browsers support the.xhtml
extension. Will we stop using.html
?Why do we use the XHTML doctype, but save those files using the
.html
extension? -
user3346601 over 14 yearsHowever, the extension usually has an effect on the Content-Type.
-
Gumbo over 14 years@ms2ger: No, the file extension has absolutely no effect on Content-Type.
-
Chris Hillery over 14 yearsIt "has an effect" in that servers often map extensions to Content-Types (e.g., via Apache's
AddType
directive or itsmime.types
file), but you're right that it doesn't change the file's content (that would indeed be quite odd). -
Gumbo over 14 years@Wevah: You’re right, but the server works on the filesystem. ;-)
-
mejdev about 10 yearsThis is a perfectly valid answer. Why has it been downvoted so much?