SitePoint Sponsor

User Tag List

Results 1 to 20 of 20

Thread: xhtml vs html

  1. #1
    SitePoint Zealot Christiano's Avatar
    Join Date
    Apr 2005
    Location
    Belfast, North of Ireland
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    xhtml vs html

    Ahh right I get it, thanks

    -martin
    Last edited by martin.christian; Jul 7, 2005 at 06:59.

  2. #2
    SitePoint Wizard rbutler's Avatar
    Join Date
    Jul 2003
    Location
    Springfield, MO
    Posts
    1,867
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    xhtml is the new version of html. It's stricter code for markup. In html these tags:

    Code:
    <br>
    Have to be closed in xhtml:

    Code:
    <br />
    Also, all markup has to be lowercase and you can't leave width/height attributes off of image tags in xhtml like you can in html. Basically, just stricter code as I already said. Unless you specify a MIME handler, most browsers serve your xhtml as html.

    DIV's refer to structuring your page with CSS. Like:

    Code:
    <div id="wrapper">
    <div id="masthead">
    <img>
    </div>
    <div id="maincontent">
    <p>foo</p>
    </div>
    <div id="sidebar">
    <a href="links.html">links</a>
    </div>
    <div id="footer">
    <p>Thanks for visiting</p>
    </div>
    </div>
    With accompanying CSS of course.
    Ryan Butler

    Midwest Web Design

  3. #3
    SitePoint Evangelist sputza's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rbutler
    Also, all markup has to be lowercase and you can't leave width/height attributes off of image tags in xhtml like you can in html.
    Just adding to what Rbutler said, Image tags also need to have an alt attribute attached.
    HTML Code:
    <img src="images/yourImageXHTML.jpg" alt="This is my awesome image" class="image1" />
    I specify my width and height in a CSS class.
    CSS:
    Code:
    .image1 {
            width: 100px;
            height: 20px;
            border: 0px;
            }
    I will make one change to what was said before. the DOCTYPE needs to be all caps like this:
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
           		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    There are more changes in XHTML that I havent listed however, below is a link to one of the better resources for learning XHTML:
    http://www.w3schools.com/xhtml/xhtml_reference.asp

    For your learning pleasure, I have a basic blank XHTML 1.0 Strict doc layed out for you:

    HTML Code:
       <!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" lang="en" xml:lang="en">
       <head>
       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
       <title>XHTML Strict Page</title>
       <link href="css/layout.css" rel="stylesheet" type="text/css" />
       </head>
       <body>
       <!--Your site goes here-->
       </body>
       </html>
       
    Enjoy and if you need a hand you can always Message me.
    Steven Watkins
    Chief Web Ninja
    Code Monkey Interactive
    lowgravity.ca

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rbutler
    xhtml is the new version of html.
    Wrong. It's a reformulation of HTML as an application of XML.

    Quote Originally Posted by rbutler
    It's stricter code for markup.
    Wrong. It's only a reformulation. It contains exactly the same things. It's neither stricter nor more semantic. Only different.

    Quote Originally Posted by rbutler
    Code:
    <br />
    That space is unnecessary in real XHTML.

    Quote Originally Posted by rbutler
    you can't leave width/height attributes off of image tags in xhtml like you can in html.
    Wrong. There are no differences in what is required or allowed between XHTML 1.0 and HTML 4.01, with the corresponding DTD.

    Quote Originally Posted by rbutler
    Unless you specify a MIME handler, most browsers serve your xhtml as html.
    Browsers don't serve markup, web servers do. And any browser that doesn't parse and treat text/html as HTML is severely broken and non-conformant.

    Quote Originally Posted by sputza
    Image tags also need to have an alt attribute attached.
    That is no different from HTML 4.01 Strict, though.
    Birnam wood is come to Dunsinane

  5. #5
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, the BR element is closed in HTML aswell. It's an empty element type, which means that it must not have any content and no closing tag. Saying that "it has to be closed in XHTML" is no different from HTML; it has to be closed in HTML aswell, although it is closed implicity by the start tag.

    An SGML parser knows that <br> is an empty element, because it is declared in the DTD.
    Code:
    <!ELEMENT BR - O EMPTY                 -- forced line break -->
    Simon Pieters

  6. #6
    SitePoint Zealot
    Join Date
    Jun 2005
    Posts
    124
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It contains exactly the same things.
    Wrong, there are things in XHTML that are deprecated since HTML 4.01, and vice a versa, a few off the top of my head are applet, dir and strikethrough tags. They do differ in tags and properties.

    That space is unnecessary in real XHTML.
    Real XHTML 1.0 allows the use of text/html which means it is necessary in 'real XHTML'. XHTML 1.1 and Basic is another story however, as far as I'm aware anyway.

    It's good that you want to use XHTML (If you do, I can't see your orginal post), it allows for an easier transition in the future. For now, try and stick with XHTML 1.0, IE cannot parse XHTML as XML yet
    Equentity, LLC - Coming Soon

    Have a question? Ask here

  7. #7
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The DTDs for the Transitional variants of HTML 4.01 and XHTML 1.0 both cantain the <dir>, <strike>, and <applet> elements.

    It is true that XHTML 1.0 (second edition) does add a few attributes like xmlns, xml:lang and the ID attribute to a few of the elements that aren't allowed to have an ID in HTML 4.01.

    We are defining "Real XHTML" to mean non-HTML compatible XHTML served with a proper mime-type.

    I can easily convert my well formed HTML 4.01 documents to XHTML 1.x with a few regular expressions.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  8. #8
    SitePoint Evangelist sputza's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo
    That is no different from HTML 4.01 Strict, though.
    That is true.

    This is the way I look at it, XHTML is newer and itís the standard. Use it now or use it later... you will have to use it eventually.
    Steven Watkins
    Chief Web Ninja
    Code Monkey Interactive
    lowgravity.ca

  9. #9
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What about if Web Applications 1.0 becomes HTML 5?
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  10. #10
    SitePoint Zealot
    Join Date
    Jun 2005
    Posts
    124
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So theoretically you don't mean 'real XHTML', you mean ideal XHTML. It would be incorrect of me to even say 'proper' when the specification explicitly says that text/html is allowed in XHTML 1.0.

    I completely understand what you mean, and what you're getting at, but there are many that don't and we have to clarify for them, otherwise it can get confusing.
    Equentity, LLC - Coming Soon

    Have a question? Ask here

  11. #11
    SitePoint Wizard rbutler's Avatar
    Join Date
    Jul 2003
    Location
    Springfield, MO
    Posts
    1,867
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo
    It's only a reformulation. It contains exactly the same things. It's neither stricter nor more semantic. Only different.
    I wholeheartly disagree with that whole statement, but I'm not going into flame wars.


    Quote Originally Posted by AutisticCuckoo
    Wrong. There are no differences in what is required or allowed between XHTML 1.0 and HTML 4.01, with the corresponding DTD.
    I didn't mention anything regarding doctype.


    Quote Originally Posted by AutisticCuckoo
    Browsers don't serve markup, web servers do. And any browser that doesn't parse and treat text/html as HTML is severely broken and non-conformant.
    Sorry I missspoke, I meant web servers. I don't always say what I mean.
    Ryan Butler

    Midwest Web Design

  12. #12
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't want to start a flame war either, however, I would I appreciate it if you would explain why you think XHTML 1.x is more strict or more semantic and HTML 4.01.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  13. #13
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pauly
    Real XHTML 1.0 allows the use of text/html which means it is necessary in 'real XHTML'.
    As Kravvitz said, 'real XHTML' means XHTML served as an application of XML, i.e. with a media type of application/xhtml+xml, application/xml or text/xml.

    Anything served as text/html is HTML. <br&#160;/> in a document served as text/html is not XHTML; it's a <br> element followed by a greater-than sign (although virtually all browsers fail to parse it correctly).

    Quote Originally Posted by pauly
    IE cannot parse XHTML as XML yet
    It would be more correct to say that IE does not support XHTML at all yet. It can parse invalid HTML markup, which means you get away with using pretend-XHTML.

    Quote Originally Posted by pauly
    the specification explicitly says that text/html is allowed in XHTML 1.0.
    That's not entirely correct. The specification says that XHTML 1.0 that follows the guidelines in Appendix C of the specification may be served as text/html. They do not explicitly state that this means it is no longer XHTML, which I consider to be a major omission. The fact remains: anything served as text/html must be parsed and interpreted as HTML. Thus there is nothing 'wrong' with serving XHTML 1.0 as text/html, but you must realise that you are no longer using X(HT)ML and that you cannot use any of the features that XHTML offers over HTML (such as CDATA sections or elements from other XML namespaces).

    You are 'allowed' to serve XHTML 1.0 markup as HTML. I'm not saying that it's wrong, but please stop spreading the lie that such a practice is somehow an improvement over HTML. It cannot be, since it is HTML.

    And even when served as an application of XML, XHTML 1.x is not more strict and not more semantic than HTML 4.01 (with the corresponding DTD).
    Birnam wood is come to Dunsinane

  14. #14
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    (FWIW, CDATA sections are allowed in HTML aswell, but currently only Opera 8 is able to parse it as CDATA, as far as I know.)
    Simon Pieters

  15. #15
    SitePoint Zealot
    Join Date
    Jun 2005
    Posts
    124
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As Kravvitz said, 'real XHTML' means XHTML served as an application of XML, i.e. with a media type of application/xhtml+xml, application/xml or text/xml.
    Come on now, we can't go throwing made up phrases about. 'Real XHTML' 1.0 allows the use of text/html. Yes it's recommended in XHTML that application/xhtml+xml be used, and requires you follow guidelines, but it still allows its use.

    I'm not saying that it's wrong, but please stop spreading the lie that such a practice is somehow an improvement over HTML. It cannot be, since it is HTML.
    In my case it is an improvement over HTML, because I both prefer it, and know it makes sense when it comes round to updating to application/xhtml+xml and being used in the future and with a future product currently under construction.

    Developers have to learn sooner or later, and is currently not incorrect, so why not now? They'll have to update their documents eventually, might as well start some pre-planning - This includes using usual 'body style' property and attributes in the html style.

    You have to bare in mind, XHTML is the web standard, meaning it's a stable W3C recommendation. XHTML is going to slowly replace HTML, so why is it more sensible to use HTML when you can use the web standard now, and have some reassurance it's going to work in the future without (To the current standard) having to update doctypes?
    Equentity, LLC - Coming Soon

    Have a question? Ask here

  16. #16
    SitePoint Wizard rbutler's Avatar
    Join Date
    Jul 2003
    Location
    Springfield, MO
    Posts
    1,867
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kravvitz
    I don't want to start a flame war either, however, I would I appreciate it if you would explain why you think XHTML 1.x is more strict or more semantic and HTML 4.01.
    Because an html 4.01 doctype will allow you to get away with "things" that an xhtml strict doctype would not. Plus, you cannot tell me that this in html:

    Code:
    <img src="foo.jpg" WIDTH="400" HEIGHT="100">
    Compared to

    Code:
    <img src="foo.jpg" width="300" height="200" alt="title">
    The latter is not stricter by nature. XHTML doesn't allow the first, unless second unless seasoned developers have taught me completely wrong. To me, stating you have to use lowercase and supply all values is stricter than HTML 4.01. Can an individual still follow these rules in html 4.01? Yes, as they should but not everyone does. Again, this is it for me, this question was supposed to be a generic answer that got way out of hand and probably confused the original poster more than it helped, that's what I don't like about explaining myself in this way.
    Ryan Butler

    Midwest Web Design

  17. #17
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pauly
    'Real XHTML' 1.0 allows the use of text/html.
    Please, please, try to understand this: if you serve something as text/html it is HTML. You are no longer using XHTML. So it's completely absurd to say that 'XHTML allows the use of text/html.' What the XHTML 1.0 spec is saying is that until user agents support XHTML, you can pretend to use XHTML while serving it as HTML.

    Quote Originally Posted by pauly
    They'll have to update their documents eventually
    Something tells me that HTML support will not disappear within the foreseeable future, on account of there being a few billion HTML pages (and alleged XHTML pages that will fail miserably if served as an application of XHTML).

    Quote Originally Posted by pauly
    You have to bare in mind, XHTML is the web standard
    Last time I looked HTML 4.01 was also a valid recommendation. It's not deprecated, and it's the latest standard with any degree of user agent support worth mentioning, unless you're developing for niche markets where everyone uses Firefox or Opera (or possibly Safari).
    Birnam wood is come to Dunsinane

  18. #18
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rbutler
    Because an html 4.01 doctype will allow you to get away with "things" that an xhtml strict doctype would not.
    An HTML 4.01 Strict doctype doesn't allow you to 'get away with' anything more than an XHTML 1.0 Strict doctype does. Some rules are different, but they are equally unambiguous and well-defined.

    Quote Originally Posted by rbutler
    Plus, you cannot tell me that this in html:

    Code:
    <img src="foo.jpg" WIDTH="400" HEIGHT="100">
    Compared to

    Code:
    <img src="foo.jpg" width="300" height="200" alt="title">
    The first is not valid HTML 4.01, because the alt attribute is required. The second one is valid HTML 4.01 Strict.
    Neither one is valid XHTML 1.0, since the <img> element is unclosed.

    Quote Originally Posted by rbutler
    XHTML doesn't allow the first, unless second unless seasoned developers have taught me completely wrong.
    Neither does HTML 4.01. The 'alt' attribute is required, even in HTML 4.01 Transitional.

    Quote Originally Posted by rbutler
    To me, stating you have to use lowercase and supply all values is stricter than HTML 4.01.
    So lowercase is stricter than uppercase? Your definition of strict is different from mine, then.

    Quote Originally Posted by rbutler
    Can an individual still follow these rules in html 4.01? Yes, as they should but not everyone does.
    Are you seriously saying that everyone who uses an XHTML doctype declaration writes clean, semantic markup that will work if the document is served as an application of XML? Please.
    Birnam wood is come to Dunsinane

  19. #19
    SitePoint Zealot
    Join Date
    Jun 2005
    Posts
    124
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    unless you're developing for niche markets where everyone uses Firefox or Opera (or possibly Safari).
    Don't we all wish!
    Equentity, LLC - Coming Soon

    Have a question? Ask here

  20. #20
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know I do...
    Birnam wood is come to Dunsinane


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
  •