SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 35
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Location
    Kolkata, India
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question HTML and XHTML - Some Basic Question

    I'm a website developer. I've developed number of websites, but believe me, I'm not aware of some basic definitions of HTML and XHTML. I realize, many coder on date are doing good job in website development, but they also don't know this basic differences, as these are not greatly associated with practical aspects.

    Folks, can you please help me (and those coders) to find out the answers to these basic questions?


    1. What is the difference between HTML and XHTML?

    2. What is used, HTML or XHTML, when we're designing basic webpages?

    3. What is the difference between XHTML 1.0 Transitional and XHTML 1.0 Strict?

    4. We used to write this piece of code on top of every webpage. Can you please explain word by word, what this 2 lines of code mean?

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    $0.50/Mo for 500MB Web hosting Kolkata
    Web design in Kolkata
    Website development company in Kolkata

    Hostgator 25% Discount Coupon wow25percent

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1, The basic differences are listed here: html & xhtml
    2, XHTML is recommended

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    3, Strict and Transitional specifies the CSS support type, strict is formally the browser independent support of basic CSS 1.0 properties, but in real life ...

    4. doctype spec: http://help.dottoro.com/lhlsvbgj.php
    Gumape

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by techbongo View Post
    1. What is the difference between HTML and XHTML?
    XHTML 1.0 is nothing but a reformulation of HTML 4.01 as an application of XML 1.0.
    See the XHTML vs HTML FAQ for more details.

    Quote Originally Posted by techbongo View Post
    2. What is used, HTML or XHTML, when we're designing basic webpages?
    HTML, usually. Microsoft Internet Explorer doesn't support XHTML, which makes XHTML rather unusable for public sites.

    Note that many (probably a majority by now) believe that they use XHTML, but they don't. Merely writing XHTML-style markup doesn't make it XHTML, as explained in the aforementioned FAQ.

    The recommended markup language is HTML 4.01 Strict (not XHTML, as gumape claims).

    Quote Originally Posted by techbongo View Post
    3. What is the difference between XHTML 1.0 Transitional and XHTML 1.0 Strict?
    The Transitional DTD allows the use of a number of element types and attributes that are deprecated in the Strict DTD. Those are mainly presentational and should be handled via CSS, or affect behaviour and should be done with JavaScript.

    XHTML 1.0 Transitional is a curious abomination whose raison d'Ítre eludes me.

    Quote Originally Posted by techbongo View Post
    4. We used to write this piece of code on top of every webpage. Can you please explain word by word, what this 2 lines of code mean?
    The first line is the document type declaration, which tells interested parties to which document type definition (DTD) the document claims conformance. Browsers normally don't care, since they use non-validating parsers. Nowadays they do look at the doctype declaration, but only to decide whether it's a reasonably 'modern' or 'old-school' document, which affects the rendering mode.

    The doctype declaration is mainly meant for markup validators.

    The second line is the start tag for the root element of the document. It must always be <html> in HTML and XHTML (although HTML is not case-sensitive). The xmlns attribute is for XHTML only and tells the user agent that this is an XHTML document, as opposed to any other flavour of XML. One might think that the doctype declaration does that, but that's not the case. The doctype declaration is optional; the xmlns attribute is required for XHTML and must have the exact value you quoted.
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gumape View Post
    1, The basic differences are listed here: html & xhtml
    Those are merely the superficial differences. You don't even mention the whole MIME type thing!

    Quote Originally Posted by gumape View Post
    2, XHTML is recommended
    How can you recommend a markup language that isn't supported by the browsers that 60-90&#37; of the population is using?

    Quote Originally Posted by gumape View Post
    3, Strict and Transitional specifies the CSS support type, strict is formally the browser independent support of basic CSS 1.0 properties, but in real life ...
    Pardon? The DTDs have nothing to do with 'the CSS support type' (whatever that is). Transitional DTDs are meant to be used in a transitional (duh!) phase when modernising pre-HTML4 documents. It's not intended to be used for creating new documents.

    Quote Originally Posted by gumape View Post
    The DTD specifies the syntax of the document and affects the visual appearance of the page.
    I'd be interested to know how you think that the DTD affects the visual appearance of the page.

    It specifies the markup grammar, that's true. And that's all.

    The presence and format of a doctype declaration in an HTML document (including pretend-XHTML) does affect the rendering mode in modern browsers.

    XHTML, being an application of XML, is always rendered in standards mode. Provided it's served with a MIME type that is recognised as being an XML document, of course. Otherwise it isn't XHTML at all.
    Birnam wood is come to Dunsinane

  5. #5
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    I'd be interested to know how you think that the DTD affects the visual appearance of the page.
    I think he means that the switch from quirks to standard can affect the visual appearence in terms of the bugs and problems that can occur in quirks mode as per how Internet Explorer seems to soil itself every now and again when we try and suprise it

  6. #6
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AlexDawson View Post
    I think he means that the switch from quirks to standard can affect the visual appearence in terms of the bugs and problems that can occur in quirks mode as per how Internet Explorer seems to soil itself every now and again when we try and suprise it
    The DTD has nothing to do with that. That's the doctype declaration (or the lack thereof) in the document itself. Browsers don't read DTDs, as a rule.
    Birnam wood is come to Dunsinane

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Location
    Kolkata, India
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh!!! The thread has become interesting.
    This is why I mentioned, that many of us are good coders even with this misconceptions. I'll like to know the fact of DTD.

    Quote Originally Posted by AutisticCuckoo View Post
    XHTML 1.0 is nothing but a reformulation of HTML 4.01 as an application of XML 1.0.
    See the XHTML vs HTML FAQ for more details.


    HTML, usually. Microsoft Internet Explorer doesn't support XHTML, which makes XHTML rather unusable for public sites.

    Note that many (probably a majority by now) believe that they use XHTML, but they don't. Merely writing XHTML-style markup doesn't make it XHTML, as explained in the aforementioned FAQ.

    The recommended markup language is HTML 4.01 Strict (not XHTML, as gumape claims).


    The Transitional DTD allows the use of a number of element types and attributes that are deprecated in the Strict DTD. Those are mainly presentational and should be handled via CSS, or affect behaviour and should be done with JavaScript.

    XHTML 1.0 Transitional is a curious abomination whose raison d'Ítre eludes me.


    The first line is the document type declaration, which tells interested parties to which document type definition (DTD) the document claims conformance. Browsers normally don't care, since they use non-validating parsers. Nowadays they do look at the doctype declaration, but only to decide whether it's a reasonably 'modern' or 'old-school' document, which affects the rendering mode.

    The doctype declaration is mainly meant for markup validators.

    The second line is the start tag for the root element of the document. It must always be <html> in HTML and XHTML (although HTML is not case-sensitive). The xmlns attribute is for XHTML only and tells the user agent that this is an XHTML document, as opposed to any other flavour of XML. One might think that the doctype declaration does that, but that's not the case. The doctype declaration is optional; the xmlns attribute is required for XHTML and must have the exact value you quoted.
    Thank you AutisticCuckoo and all other poster for your replies. Let me read these pages carefully. I'm sure, I'll have more questions on the way.
    $0.50/Mo for 500MB Web hosting Kolkata
    Web design in Kolkata
    Website development company in Kolkata

    Hostgator 25% Discount Coupon wow25percent

  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,604
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by techbongo View Post
    I'll like to know the fact of DTD.
    Web browsers ignore DTDs. Except if you are validating the page using a validator that uses the DTD reference to determine which version of HTML or XHTML to validate the page as you can leave that part out. The SGML standard states that those parts of the doctype are optional. The only part that is required (to stop all browsers displaying the page differently from one another) is <!DOCTYPE html> (that is valid for HTML 2+ and all versions of XHTML).
    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
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    www.w3schools.com/html/
    Try this one
    This site is really helpful.

  10. #10
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,604
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by virtualmisc View Post
    www.w3schools.com/html/
    Try this one
    This site is really helpful.
    Really out of date since the two guys who built it have moved on to other things.

    http://webdesign.about.com is a far better site for learning about HTML and XHTML and it (unlike w3schools) is being constantly updated with more information.
    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="^$">

  11. #11
    om nom nom nom Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,233
    Mentioned
    47 Post(s)
    Tagged
    1 Thread(s)
    Off Topic:

    someone seems to be keeping w3schools' javascript pages more up to date... or, they just seem newer and seem to have more recent stuff in them than the markup area...

  12. #12
    SitePoint Addict SilentBobSC's Avatar
    Join Date
    Mar 2005
    Location
    South Carolina
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, first you want to declare your doctype if for no other reason than making your life troubleshooting those annoying cross-browser inconsistencies a little easier.

    I personally have to use a XHTML 1.0 Transitional doctype for many of my projects because I work with a Content Managment System (Dotnetnuke) and because of all the variations between third-party modules, I find it much easier to validate and correct visual issues.

    As many have stated though, most of the differences are in your tag formatting and attributes, for instance: XHTML does not allow for your tags to be capitalized, the browsers don't care but the validator does. There are also limitations placed on which tags can use which attributes, the most popular being the EMBED/OBJECT tags used for embedding flash elements. ( I use this method myself.)

    Basically, my understanding is HTML is your basic markup, whereas XHTML represents more of an 'Application' that includes more XML-like elements and markup.

    I am open for correction, however.

  13. #13
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,604
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by SilentBobSC View Post
    Basically, my understanding is HTML is your basic markup, whereas XHTML represents more of an 'Application' that includes more XML-like elements and markup.
    I'll supply the correction.

    HTML and XHTML are two completely different web languages. XHTML requires everything to pass validation or the page will not display at all and so you have to make sure your page is completely valid if you use XHTML. Also Internet Explorer can't process XHTML and so if you want to allow your visitors to use Internet Explorer then you can't use XHTML.

    You can use either an HTML or XHTML doctype with HTML (provided you limit yourself to the subset of XHTML that is just slightly badly formed HTML so that the browsers can still process it as HTML. You must use an XHTML doctype if you are going to use XHTML.

    You can usually tell what language is really being used by looking at an image tag.

    <img src=picture.gif> is HTML
    <img src="picture.gif" /> is usually HTML (with an XHTML doctype)
    <img src="picture.gif"/> is XHTML (the lack of a space before the slash would make the preceding attribute invalid as HTML but the space isn't needed in XHTML).

    Another example of the difference

    <script type="text/javascript" src="script.js"></script> is usually HTML (regardless of the doctype used)
    <script type="text/javascript" src="script.js"/> is the XHTML equivalent.

    Unless you have a specific reason for using an XHTML doctype when writiing HTML you should use an HTML doctype. Unless you have a reason for needing to support obsolete tags you should use a strict doctype.
    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="^$">

  14. #14
    SitePoint Addict SilentBobSC's Avatar
    Join Date
    Mar 2005
    Location
    South Carolina
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    I'll supply the correction.

    HTML and XHTML are two completely different web languages. XHTML requires everything to pass validation or the page will not display at all and so you have to make sure your page is completely valid if you use XHTML. Also Internet Explorer can't process XHTML and so if you want to allow your visitors to use Internet Explorer then you can't use XHTML.
    I'm a bit perplexed here, maybe it's caused by the fact I'm accustomed to XHTML 1.0 Transitional which is a bit more lenient. However, all the skins I design for DNN are based on the XHTML 1.0 Trans doctype and I usually aim for 0 Errors in validation (not easy with CMS's), however I've never had any issues pulling these up in IE or when the pages toss errors in validation (common for pages with 3rd party modules).

  15. #15
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SilentBobSC View Post
    XHTML does not allow for your tags to be capitalized, the browsers don't care but the validator does.
    Browsers care if you're actually using XHTML (i.e. an XML MIME type rather than text/html). Example:
    Code:
    data:text/xml,<html xmlns='http://www.w3.org/1999/xhtml'><script>alert("Worky")</script><SCRIPT>alert("Not worky")</SCRIPT></html>
    Quote Originally Posted by SilentBobSC View Post
    There are also limitations placed on which tags can use which attributes, the most popular being the EMBED/OBJECT tags used for embedding flash elements.
    HTML has the same limitations.
    Simon Pieters

  16. #16
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML - Hyper Text Mark-up language
    XHTML - Extensible Hyper Text Mark-up language
    We use HTML in designing simple webpages.
    XHTML 1.0 Transitional is an improved version.

    I too am not an experienced person and i knew this much only.

  17. #17
    #titanic {float:none} silver trophy
    molona's Avatar
    Join Date
    Feb 2005
    Location
    from Madrid to Heaven
    Posts
    8,025
    Mentioned
    211 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by mithu143 View Post
    HTML - Hyper Text Mark-up language
    XHTML - Extensible Hyper Text Mark-up language
    We use HTML in designing simple webpages.
    XHTML 1.0 Transitional is an improved version.

    I too am not an experienced person and i knew this much only.
    This is not correct, I am afraid.

    HTML HyperText Markup Language
    XML - Extensible Markup Language

    XHTML doesn't stand for anything in particular as far as I know (or at least, the W3C don't say that each letter is a reference to a particular word)

    XHTML 1.0 Transitional is not a improved version of HTML. It is, to make it simple, HTML as XML. But if you don't serve it as an application, it is exactly the same as HTML.

    Transional simply tells the browser that it may be an old document and that may be old tags and presentational tags (such as <center>, <b> or <i>), or maybe old attributes that are obsolete. Using a Strict DTD, these tags and attributes would not be allowed and the document would not validate if they were used.

  18. #18
    #titanic {float:none} silver trophy
    molona's Avatar
    Join Date
    Feb 2005
    Location
    from Madrid to Heaven
    Posts
    8,025
    Mentioned
    211 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    The DTD has nothing to do with that. That's the doctype declaration (or the lack thereof) in the document itself. Browsers don't read DTDs, as a rule.
    I would go a bit further here... it is the DOCTYPE declaration, the lack of it or if the declaration is incomplete.

  19. #19
    #titanic {float:none} silver trophy
    molona's Avatar
    Join Date
    Feb 2005
    Location
    from Madrid to Heaven
    Posts
    8,025
    Mentioned
    211 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by SilentBobSC View Post
    I'm a bit perplexed here, maybe it's caused by the fact I'm accustomed to XHTML 1.0 Transitional which is a bit more lenient. However, all the skins I design for DNN are based on the XHTML 1.0 Trans doctype and I usually aim for 0 Errors in validation (not easy with CMS's), however I've never had any issues pulling these up in IE or when the pages toss errors in validation (common for pages with 3rd party modules).
    But how do you serve it? As text/html or as an application? Only XHTML 1.0 can be served as text and then it is like regular HTML (although with few differences such as not using capital letters for the tags, and so on).

  20. #20
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SilentBobSC View Post
    XHTML does not allow for your tags to be capitalized, the browsers don't care but the validator does.
    Browsers do care, if you actually use XHTML, i.e., if you serve it as an application of XML. If you serve it as HTML you are only pretending to use XHTML and as far as browsers are concerned they receive invalid HTML.

    Quote Originally Posted by SilentBobSC View Post
    There are also limitations placed on which tags can use which attributes, the most popular being the EMBED/OBJECT tags used for embedding flash elements.
    EMBED has never been part of any version of HTML or XHTML. It will, incomprehensibly, be introduced in HTML5 and XHTML5, though.

    Quote Originally Posted by SilentBobSC View Post
    Basically, my understanding is HTML is your basic markup, whereas XHTML represents more of an 'Application' that includes more XML-like elements and markup.
    XHTML 1.0 is nothing more than a reformulation of HTML 4.01 as an application of XML 1.0. The only purpose for its existence was so that you could parse it with an XML parser and include elements from other XML namespaces. Since Internet Explorer doesn't support it and most markup authors don't know what they are doing, XHTML markup is almost always served as HTML. That means none of the alleged benefits apply; rather the opposite: you depend on (non-standardised) browser error handling since all you are really using is invalid HTML.

    Quote Originally Posted by SilentBobSC View Post
    However, all the skins I design for DNN are based on the XHTML 1.0 Trans doctype and I usually aim for 0 Errors in validation (not easy with CMS's), however I've never had any issues pulling these up in IE or when the pages toss errors in validation (common for pages with 3rd party modules).
    That's most likely because you are serving your 'XHTML' as HTML and because you are using a limited subset of XHTML syntax. IE supports most of HTML and its error handling lets you get away with the invalid markup.

    If you were to try to include elements from other XML namespaces you'd see that they wouldn't work. Or if you were to use self-closing tags for empty elements other than those that are declared as EMPTY in the DTD. For instance,
    Code XML:
    <script type="text/javascript" src="foo.js"/>

    Quote Originally Posted by mithu143 View Post
    HTML - Hyper Text Mark-up language
    XHTML - Extensible Hyper Text Mark-up language
    We use HTML in designing simple webpages.
    XHTML 1.0 Transitional is an improved version.
    XHTML 1.0 is not an 'improved' version of HTML, any more than sign language is an improved version of English. XHTML 1.0 is an application of XML that mimics the same element types and attributes as HTML 4.01.

    And a Transitional DTD can never be said to be an improvement over anything. In fact, the mere existence of the XHTML 1.0 Transitional DTD is quite inexplicable.

    Quote Originally Posted by molona View Post
    I would go a bit further here... it is the DOCTYPE declaration, the lack of it or if the declaration is incomplete.
    You're right – almost. 'Incomplete' is not the correct word, but I understand what you mean. It's a question of whether the doctype declaration contains both a public identifier and a system identifier, or just a public identifier.

    The declaration is complete even without the system identifier. In fact, the SI is really redundant, since the PI unambiguously identifies the DTD. It's just that old-school documents rarely included the SI, if they had a doctype declaration at all, so it was chosen as an appropriate sentinel value for doctype sniffing.
    Birnam wood is come to Dunsinane

  21. #21
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Location
    Kolkata, India
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you all for contributing here, I'm confused, but I've learnt enough from all these posts. Thank you all again. We'll be glad to know more definitions.

    Quote Originally Posted by felgall View Post
    You can usually tell what language is really being used by looking at an image tag.

    <img src=picture.gif> is HTML
    <img src="picture.gif" /> is usually HTML (with an XHTML doctype)
    <img src="picture.gif"/> is XHTML (the lack of a space before the slash would make the preceding attribute invalid as HTML but the space isn't needed in XHTML).

    Another example of the difference

    <script type="text/javascript" src="script.js"></script> is usually HTML (regardless of the doctype used)
    <script type="text/javascript" src="script.js"/> is the XHTML equivalent.

    Excellent example felgall. Thank you a lot for this easy example to distinguish these 2.
    Last edited by techbongo; Oct 10, 2009 at 11:53. Reason: typo :)
    $0.50/Mo for 500MB Web hosting Kolkata
    Web design in Kolkata
    Website development company in Kolkata

    Hostgator 25% Discount Coupon wow25percent

  22. #22
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,604
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    The way to really tell whether it is HTML or XHTML is to examine the MIME type.

    If the MIME type is "text/html" then it is HTML.
    If the MIME type is "application/xml+xhtml" then it is XHTML.

    An easy way to tell the difference between these is to try to load the page using Internet Explorer 8 or earlier. Those browsers do not understand the XHTML MIME type and so will offer the file for download instead of loading the page into the browser window.

    If you try to access http://www.felgall.com/realxhtml.php with Internet Explorer you will see exactly what happens with IE and XHTML.
    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="^$">

  23. #23
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    <img src="picture.gif"/> is XHTML (the lack of a space before the slash would make the preceding attribute invalid as HTML but the space isn't needed in XHTML).
    No, HTML doesn't require the space either. It's just some old HTML-only browsers that do (allegedly; I don't know which ones).

    But the '/>' syntax means something very different in HTML than in X(HT)ML. In HTML the sample above (with or without the extra space) is equivalent to <img src="picture.gif">&gt;. (Which is invalid HTML since it lacks the required alt attribute.)

    It's only due to HTML parser bugs that pretend-XHTML pages aren't littered with '>' characters.
    Birnam wood is come to Dunsinane

  24. #24
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    No, HTML doesn't require the space either. It's just some old HTML-only browsers that do (allegedly; I don't know which ones).
    Netscape 4 treats <br/> as an element named "br/". I think there was never a problem with <img src="foo"/> (I think it would create an attribute named "/").

    Today's browsers treat slash in tags as "end the current attribute" when it appears just after an attribute name, or as part of an attribute's value when it appears after the equals sign or inside an unquoted value, and as whitespace elsewhere. For pretend-XHTML purposes, it means that it's just ignored.
    Simon Pieters

  25. #25
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,604
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    No, HTML doesn't require the space either. It's just some old HTML-only browsers that do
    I know that. You are looking at it backwards. I was trying to point out that when you see the space there it generally means that it is XHTML pretending to be HTML as XHTML never requires the space but people using it in their HTML have got used to using the space since Netscape 4 didn't always work properly without it and more recent users have copied those earlier users. The space there therefore generally indicates that it is HTML with extra / rather than XHTML.
    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="^$">


Tags for this Thread

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
  •