SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Location
    California
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .html or .xhtml?

    I've been using XHTML for a while and I've always saved files with the extension ".html", like "index.html". However, I just noticed the my code editor (Aptana Studio) saves its templates as ".xhtml". I've never seen a ".xhtml" extension for a web page. Are you supposed to use the ".xhtml" extension for XHTML pages, or is ".html" fine?

    Thanks!

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,263
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    An ".html" extension means the web server has been sending your page with the "text/html" mime type all this time, which also means that -- regardless of an XHTML doctype or self-closing slashes -- browsers have been parsing your code as if it were plain-old HTML. If you switch the extension to ".xhtml", then the web server might start sending your page with the "application/xhtml+xml" mime type, which is the mime type we're actually supposed to use for XHTML. The reason we don't is because IE <= 8 can't handle it. Also, if you make the switch to true XHTML, you may find that some markup, CSS, or JS is no longer compatible.
    "First make it work. Then make it better."

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Location
    California
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, I didn't know that the file extension could override the doctype. Even so, it still validates as XHTML, which makes this even more confusing.

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,263
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Yup. For example, check out these two pages:

    http://www.webdevout.net/articles/be...amples/6.xhtml
    http://www.webdevout.net/articles/be...xamples/6.html

    They have exactly the same source code, yet they render differently. The only difference between them is that one is served as application/xhtml+xml and the other as text/html. That mime type is the only factor that determines whether the browser will parse your page as XHTML or HTML.
    "First make it work. Then make it better."

  5. #5
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    There is no reason to use XHTML. Especially now that html5 is becoming standard. FYI - notice there is no option for (x)html5. Why code in a dead language?

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Location
    California
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm using it until I fully understand how to use new html5 markup elements. Even if XHTML is dead, it still works.

  7. #7
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,168
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by EricWatson View Post
    there is no option for (x)html5.
    XHTML5 is indeed being developed in parallel with HTML5.

    As I understand it, whether you use .html or .xhtml makes little or no difference online, but there may be a difference when running the files locally.

  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,807
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by ralph.m View Post
    As IE8 will be long dead by the time X()HTML 5 becomes a standard, when it does it will be the first version of XHTML that is actually usable.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  9. #9
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    XHTML is not dead, is normative (is backwards compatible) unlike HTML5. The future versions of XHTML will be reworked as XHTML5 most likely as HTML5 under MIME type: application/xhtml+xml.

    There are three known file extensions that are currently in use for XHTML 1.x; ".xht", ".xhtml", and ".html". So by 2020, when HTML5.xx might be first usable hopefully IE8 will be long extinct.

    The software is probably saving as: *.xht and *.xhtml because the files are based on pre-built templates and those extension are associated with XHTML documents not HTML 4.01 documents. I do save some files with the *.xht extension myself and have them online but like was mentioned; the MIME, the server sends matters more than if a hypertext-markup document has *.kangaroo , etc.

  10. #10
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Hmmm. My bad then.

  11. #11
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,276
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    Oh, I didn't know that the file extension could override the doctype
    On a *nix system, they can't, because they don't mean anything special. Like XHTMLcoder, you could have a foo.kangaroo file. Files are files, on *nix (though some applications may prefer to guess what a file type is based on extension). I could have HTML files on my server with no extension at all. So long as I set them to the correct MIME type and tell my server what to do with them, all's good.

    But the headers the server sends out with the pages... that matters, exactly as Jeff Mott showed. How the server serves the page will override the meta tag (the meta tag is more of a fallback... for those nasty times when someone did not set up their server properly and it's sending out pages without headers stating what the MIME type is).

    If your server does change which MIME type it associates your page with based on file extension, and you're not using a Windows server (I could be wrong, but I understand that on Windows, file extensions *do* mean something), then it's just a setting on your server to guess your intended MIME type. But that's a server setting, and not any kind of general rule about file extensions.

    Quote Originally Posted by eric
    Hmmm. My bad then.
    Nah, not really. I think when everyone realised what a pain XML was, the world moved on and XHTML will be used for those who actually have a use for XML and find using it also for their web stuff makes sense. Everyone else will have moved on to JSON I think :P

    So it's not dead, but it's not something most of us have any real reason to use, other than personal preference.

  12. #12
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,807
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Stomme poes View Post
    Everyone else will have moved on to JSON I think :P
    I disagree - I think most people will stick with HTML rather than convert to JSON - particularly since JSON can't be used marking up web page content.

    XML has millions more uses than either HTML or JSON and so will likely outlive both.

    XHTML will be used by anyone who is using XML where one of the possibly dozens of uses they are making of their content is as web page content and also by anyone with a programming background - since it is far more logical in its operation than HTML is.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •