SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    Don't eat yellow snow spaceman's Avatar
    Join Date
    Mar 2001
    Location
    Melbourne, Australia
    Posts
    1,039
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XHTML: single quotes or double quotes?

    I always use double quotes in my (XHTML) code. An associate of mine uses single quotes, and his documents validate 100% for XHTML (transitional) correctness.

    I've searched online, and there are indeed a few _articles_ that specifically state that one must use double quotes around attributes. BUT I can't find any _official XHTML specs_ that say that you must use double and not single quotes.

    For example, look here:

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

    Search for 'quotes'. It says...

    'All attribute values must be quoted, even those which appear to be numeric.'

    ...and the example _does_ use double quotes. BUT it does not explicitly state that single quotes are disallowed.

    Can anyone point me to any official XHTML documentation (as opposed to article) that explicitly states that single quotes are disallowed, or even just discouraged?

    Thanks.

    P.S. I originally posed this question in amongst another thread, but got no response.
    http://www.sitepointforums.com/showt...threadid=49710
    Web Design Perth Melbourne .:. Itomic Business Website Solutions
    Drupal Experts .:. Drupalise

  2. #2
    SitePoint Wizard
    Join Date
    Oct 2001
    Location
    Tucson, Arizona
    Posts
    1,858
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Either single or double quotes will work fine, and both are acceptable/valid.

  3. #3
    Don't eat yellow snow spaceman's Avatar
    Join Date
    Mar 2001
    Location
    Melbourne, Australia
    Posts
    1,039
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by colon//
    Either single or double quotes will work fine, and both are acceptable/valid.
    Thanks for your comments.

    So you disagree with the online articles about XHTML that state that double quotes _are_ necessary? If so, where are you getting your information from?

    Sorry to labour the point - I'm just keen to get an authoritative result.

    Thanks
    Web Design Perth Melbourne .:. Itomic Business Website Solutions
    Drupal Experts .:. Drupalise

  4. #4
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well spaceman. I think your authoratitive report comes right from the horses mouth. It validates. However does it validate in strict. If not than you have your answer ...

    Articles are like newpapers. They aren't always right or perfect. Since the W3C are essentially in charge of the standards they would know better then bob.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  5. #5
    SitePoint Wizard
    Join Date
    Oct 2001
    Location
    Tucson, Arizona
    Posts
    1,858
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes; they're perfectly valid, therefore they validate in XHTML 1.0 strict.

  6. #6
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look at the XML spec http://www.w3.org/TR/REC-xml#sec-common-syn :

    Code:
    [9]    EntityValue    ::=    '"' ([^%&"] | PEReference | Reference)* '"'  
       |  "'" ([^%&'] | PEReference | Reference)* "'" 
    [10]    AttValue    ::=    '"' ([^<&"] | Reference)* '"'  
       |  "'" ([^<&'] | Reference)* "'" 
    [11]    SystemLiteral    ::=    ('"' [^"]* '"') | ("'" [^']* "'")  
    [12]    PubidLiteral    ::=    '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
    If you know the meaning of regular expressions you can see that it accepts both " and ' delimiters for string literals.
    ck :: bringing chris to the masses.

  7. #7
    Don't eat yellow snow spaceman's Avatar
    Join Date
    Mar 2001
    Location
    Melbourne, Australia
    Posts
    1,039
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wise words, Maelstrom.

    I just used the w3c validation service at http://validator.w3.org/ to validate a test page for strict XHTML.

    The simple page contained the following:

    <td valign='top'>test</td>

    And guess what - it validated 100%.

    So there you have it. Just because it's written down, doesn't mean it's true (in reference to the articles that state that only double quotes are XHTML compliant).

    OK, so I've satisfied myself that single quotes are just fine according to XHTML standards... I wonder if there are any other considerations left to persuade me not to 'relax' and start using single quotes in preference to double quotes?

    In case anyone is wondering why I prefer to use single quotes: it's just because they're easier to use in PHP when I don't have to keep 'escaping' double quotes.
    Web Design Perth Melbourne .:. Itomic Business Website Solutions
    Drupal Experts .:. Drupalise

  8. #8
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats as good a reason as any. I program a lot in javascript at times and it tends to be picky. Things are also easier (for me) to read when quoted 'correctly'. But I think quotation is a personal thing not a professional one.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  9. #9
    SitePoint Addict Caterwomtious's Avatar
    Join Date
    Dec 2001
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just found this old topic and thought I'd add my test. I wanted to know whether you could mix and match the two styles in the same document. I put together this test page:

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     
     <html>
     <head>
     	<title>Untitled</title>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     </head>
     
     <body>
     <p><a href="http://example.com" class='mixandmatch'>test</a></p>
     
     
     </body>
     </html>
    I went to the W3C validator and it said it's valid as strict XHTML 1.0.


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
  •