1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

what is XHTML?

Discussion in 'HTML & Website Design' started by heapseo, Oct 21, 2005.

  1. #1
    Hey, can someone give me a very brief run down of how XHTML is different to HTML? Is there a standard set of important rules that make the difference? How does XHTML make a difference to your web page or browser compared to HTML?

    I have searched for a simple explanation but am yet to find one!

    Any tips appreciated
     
    heapseo, Oct 21, 2005 IP
  2. Web Gazelle

    Web Gazelle Well-Known Member

    Messages:
    3,590
    Likes Received:
    259
    Best Answers:
    0
    Trophy Points:
    155
    #2
    XHTML is HTML that is written to specific standards that makes the code W3C compliant.
     
    Web Gazelle, Oct 21, 2005 IP
  3. heapseo

    heapseo Peon

    Messages:
    636
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #3
    is it mainly to do with ensuring HTML tags are closed properly?
     
    heapseo, Oct 21, 2005 IP
  4. Skeleton

    Skeleton Peon

    Messages:
    116
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Some basic XHTML rules:

    - You must close all of your tags (even the ones like img, br, hr,...)
    - You must use lowercase letters for tags, attributes
    - You must use double quotes for values like <a href="www.site.com">site</a> not <a href=www.site.com>site</a>

    And a quote from w3schools:
    Check this link for more information
     
    Skeleton, Oct 21, 2005 IP
  5. heapseo

    heapseo Peon

    Messages:
    636
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #5
    cool, thanks. So basically its xml rules for HTML... maybe thats where the name cme from... Jeez I astound myself with my own intelligence sometimes :D
     
    heapseo, Oct 21, 2005 IP
  6. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #6
    There's more to XHTML than just this.

    HTML is based on SGML and HTML-specific DOCTYPE points to an SGML DTD, which is different from an XML DTD. XHTML, on the other hand, is based on XML and its DOCTYPE points to an XML DTD. Believe you or not, the following tag is valid HTML strict (go ahead, check it out):

    <div/

    That is, this tag is valid SGML (HTML is SGML), but not XML (XHTML is XML). Here's the W3C document that outlines HTML/XHTML difefrences:

    http://www.w3.org/TR/xhtml1/#diffs

    J.D.
     
    J.D., Oct 21, 2005 IP
  7. Web Gazelle

    Web Gazelle Well-Known Member

    Messages:
    3,590
    Likes Received:
    259
    Best Answers:
    0
    Trophy Points:
    155
    #7
    Yeah, that stuff too. :cool:
     
    Web Gazelle, Oct 21, 2005 IP
  8. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #8
    Out of nine years of being a webmaster, the only one there that I've ever obeyed was having double quotes in links!!!! <PRE> and <A HREF are about the only tags I always closed! Lowercase??!!! Hardly ever!!!! Case in point!! :D:D Gah!! Last I checked, it's best to KISS!!!!!

    http://en.wikipedia.org/wiki/XHTML
     
    Nintendo, Oct 21, 2005 IP
  9. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #9
    KISS is about keeping it simple, not about keeping it broken. There's a downside of writing sloppy HTML:

    * Many browsers will switch to the quirks mode if there's no DOCTYPE. As a result, your style sheets will not work the same way in all browsers (e.g. centering divs on a page is much simpler if your document has proper DOCTYPE).

    * When the new version of browsers comes out and they (espesially MS) fix some of their quirks, your website will simply break for no apparent reason for you.

    Now, funny as it sounds, all the things you mention, they are actually valid HTML - HTML tags are case-insensitive, you don't have to quote attribute values and you don't have to close some tags (e.g. <p>, <tr>, <td>, etc).

    J.D.
     
    J.D., Oct 25, 2005 IP
  10. JamieC

    JamieC Well-Known Member

    Messages:
    226
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    138
    #10
    Absolutely J.D.

    When people refer to HTML, they are generally talking about the HTML 4.01 Transitional DTD (Document Type Definition). Code conforming to this is produced by a lot of WYSIWYG and templated by a lot of text editors.

    XHTML has an entirely different DTD. Most of the differences have been covered above. It is a different language, with some syntactic similarities with HTML.

    It's important that people begin to transition to XHTML, especially with IE7 on the horizon.

    One important point that hasn't been mentioned is that to ensure backwards compatibility with older browsers, self contained tags, such as <br>, should be espcaped with a 'space slash', to avoid confusing older parsers. So you should write it <br />, NOT <br/>.
     
    JamieC, Oct 31, 2005 IP
  11. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Current IE does not support XHTML and IE7 will not support it either. Sure, it is capable of parsing XHTML-style tags, such as <br />, but it simply ignores any of the XHTML features, such as XML stylesheets, CDATA sections, formatting, etc. Moreover, as soon as you stick XHTML into DOCTYPE, IE falls into a weird quirks mode and doesn't even follow CSS to the same extent it does when DOCTYPE is just HTML (e.g. centering block-level elements is one example of what gets screwed up).

    XHTML is sounds great and trendy, but you really need to ask yourself whether you gain anything if you take the XHTML road now. Personally, I'm sticking with HTML until MS finally kicks its clumsy IE development into gear and produces a browser that supports the XHTML/CSS combo.

    J.D.
     
    J.D., Oct 31, 2005 IP
  12. saintdw

    saintdw Peon

    Messages:
    453
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I exclusively code my sites in XHTML complient code :D
     
    saintdw, Oct 31, 2005 IP
  13. JamieC

    JamieC Well-Known Member

    Messages:
    226
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    138
    #13
    What you gain is the ability to work with XHTML, and a portfolio of sites that are written in XHTML. IE7, while it will not parse XHTML as XML, will put a stop to the quirks mode that IE6 employs currently when it sees an XHTML doctype, and will therefore render pages as they should be seen. Firefox supports XHTML, and we will hopefully see a gain in market share there anyway.

    What you really need to ask yourself is actually whether you lose anything by making this simple transition - and the answer is no. While being on the cutting edge is not necessarily by itself advantageous, being prepared in advance for a transition to XHTML will reduce your workload in the future.

    As an analogy consider the introduction of chip and pin credit cards in the UK. Credit cards with chips were being rolled out years before the first chip readers were being deployed in shops and cash machines were being modified to use them. This is because the cards were backwards compatible, and it was sensible for new cards to support future technology.

    Equally, it's just as sensible for new websites to support future technology when they will work just as well (or as well as possible) with old.
     
    JamieC, Nov 1, 2005 IP
  14. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Do a simple experiment and see this HTML in IE6 (use DOCTYPE HTML/strict) and in IE7 (use DOCTYPE XHTML). You will see that it's actually reverse - IE7 will parse XHTML as XML, but will fail to process some XHTML/CSS features.

    <div style="width: 50%; margin: auto; border: 1px solid red;" />

    Browsers that support CSS properly will render this element in the middle of the page. IE in the XHTML mode will render it left-aligned.

    But, hey, if you don't believe what I'm saying, read what MS folks are:

    http://blogs.msdn.com/ie/archive/2005/09.aspx

    You lose the ability to write minimum HTML/CSS for your website to look the same in most browsers. Take the example with div above. Show me how you center this element in IE when DOCTYPE is set to XHTML and compare the markup.

    It's a flawed analogy - imagine you had a credit card with a chip, but some credit card readers (IE) would round incorrectly in there's a chip (XHTML/CSS) and wouldn't send some of your purchase data at all (XHTML/CDATA/styles/etc).

    Now, can you name some technical advantages of using XHTML? I do mean technical - not just a bunch of buzzwords about cutting-edge technology and earlier transition.

    J.D.
     
    J.D., Nov 1, 2005 IP
  15. JamieC

    JamieC Well-Known Member

    Messages:
    226
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    138
    #15
    The way to center this element would be to include a text-align: center for 'body' and then a text-align: left for container. But yeah, I get your point. More markup is necessary to ensure backwards compatibility. It's the equivalent of keeping the magnetic strip ;).

    I read the IE7 blogs too. As I understand it, while they will not be implementing specific support for XHTML with a new parser, IE will no longer enter quirks mode when XHTML is specified as the doctype.

    To avoid this happening, they included both a chip and a strip. Following this, websites should include markup which allows each individual browser to parse them in the best way possible. If a system supports the chip, it gets to use it - if a browser supports XHTML, it gets to use it.

    Not advantages to you, no. However, users of clients that support XHTML will benefit from the decreased resources required by the application to parse a well-formed XML file rather than a messy (and potentially tag-souplike) HTML file. As more users start using clients that support XHTML, we will see a reduction in processor (and therefore power) usage. Maybe we'll save on fossil fuels ;).

    Seriously though, it is a better language. We both know that in the long term, there will be technical advantages such as being able to require well formed markup (why is it that when i'm working in C++, my code won't compile or throws exceptions if it's badly written, but if I write bad HTML the browser tries all sorts of resource-intensive activities to figure out what I wanted to do). XHTML will also provide better support for platforms other than the standard PC / Windows / Browser combo, such as mobile phones and screen readers.

    The main advantage though, is that it will simply result in more streamlined browsers that don't support all sorts of arbritary (and depreciated) tags and markup.

    For now, you're absolutely correct in that it requires less effort on your part to simply code HTML. However, with a little effort it IS possible to allow all platforms to access a website to the best of their ability. Dave Shea's website is a great example of this.

    Anyway, probably best if we agree to disagree :). I don't deny geeky version lust, and yes, it's not sensible from a business point of view to start on XHTML yet. However, it will always require a few evangelists to get things like this going, and in the future there will be very real benefits. I was recently involved in a discussion on this form about CSS layout vs table based, and the things I said there are as relevant here - I like progress, and I want to be at the front. Can't be a disadvantage to be there instead of in the middle :)
     
    JamieC, Nov 1, 2005 IP
    J.D. likes this.
  16. torunforever

    torunforever Peon

    Messages:
    414
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Does anyone know if any browser projects are on the horizon that would allow this? I wouldn't mind having a mozilla-based browser that didn't render sites with sloppy markup. (Sloppy being defined as not conforming to whatever doctype they declared, with the option to specify your own doctype).
     
    torunforever, Nov 1, 2005 IP
  17. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #17
    Not only this. Two things:

    1) By the book (CSS), text-align applies only to how inline content of a block box is aligned. Simply put, text-align may be used to align the text inside a <div>, but cannot be used to align the <div> itself (if it's shorter than the available width). IE applies this to block-level elements, like div's which is against the spec.

    2) text-align is inheritable and once you set it at the top level (e.g. body), you will have to override it all the way down to the last element in the document tree. Doing this is just asking for way, way more work in the future!

    There are many features XHTML offers that are great. For example, be able to mix up different types of XML (e.g. math XML, etc); to use CData sections if you want to quote some code; simpler parsers; etc. It's just happens so, though, that at the moment you don't get any of these benefits because the browser used by most simply can't handle XHTML properly.

    It is true, XML parser is simpler and, I imagine, cell phone manufacturers would love to use it instead of HTML.

    Well, tables vs. CSS is a webmaster's urban legend type of argument. CSS complements tables (there's whole chapter on tables in CSS), but many webmasters just can't understand this and keep thinking that getting rid of tables actually puts them on the cutting edge. Well, it doesn't. Same applies to XHTML - how is it a cutting edge, if you can't use any of XHTML features? I obviously don't consider writing tags in XML style as a cutting-edge-thing.

    ...just having fun :). Good discussion.

    J.D.
     
    J.D., Nov 1, 2005 IP
    JamieC likes this.
  18. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #18
    FF won't render the content if content-type is set to application/xhtml+xml (as it should be for all XHTML documents). However, this means that half the web running XHTML will be broken and most websites serve documents with DOCTYPE set to XHTML, but content-type returns text/html, which triggers the compatible mode in all browsers.

    J.D.
     
    J.D., Nov 1, 2005 IP
  19. torunforever

    torunforever Peon

    Messages:
    414
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #19
    J.D. and JamieC, I've read your comments, and although I tend to side with JamieC that xhtml is the way to go, you've both given me something to think about. I have to admit a major reason I prefer to use xhtml is because I think it's the trendy thing to do, but also because I like the structure.
     
    torunforever, Nov 1, 2005 IP
  20. JamieC

    JamieC Well-Known Member

    Messages:
    226
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    138
    #20
    I agree it's a hack... painful but necessary in my book ;)

    Yeah this is true. My workaround for this is typically to use a <div id="container"> around everything, and set text-align: left; for that div. Then all the children revert to inheriting left-align.

    Again this is true, however I would still suggest that through creating your documents in XHTML now, you permit the easy use of these advanced features in future.

    My take on this is that tables should be used for displaying tabular data. CSS does provide a rich set of tools for styling tables, but I enjoy the challenge of laying out my sites using pure CSS. These days I consider myself to be reasonably proficient and i'm confident that by forcing myself to transition to CSS layouts i'm now creating more daring and varied layouts faster than I did with traditional tables. Naturally, if I wanted to print some stats, or any kind of data, i'd use a table.

    Anyway, the irony of all this is that I'm currently attempting a trace of a layout that's been prepared for me in Photoshop - using XHTML, and surprise surprise, IE is having all sorts of trouble. Serve's me right I suppose. Still, i'm determined to soldier on :D
     
    JamieC, Nov 1, 2005 IP