SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,621
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)

    id='word' vs id="word"

    Most of the time you can use single quotes for things. But I just noticed that you can use them for id's as well. Does this work everywhere and is it valid?

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,592
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Yes, it's valid, but personally, I'd stick with double quotes. It's clearer, and I'd say keep single quotes for other languages like JS and PHP. Consistency is the key.

  3. #3
    Mouse catcher silver trophy
    Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,822
    Mentioned
    110 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by EricWatson View Post
    Most of the time you can use single quotes for things. But I just noticed that you can use them for id's as well. Does this work everywhere and is it valid?
    According to a thread we had here 11 years ago (and no, I wasn't around then either!) – XHTML: single quotes or double quotes – it's perfectly valid to use single quotes when quoting attribute values. ID is no different to any other attribute, you can use single quotes there – the only time you are likely to run into trouble is if the attribute value contains a single quote/apostrophe character, and it will then be taken as the end of the attribute value, so you would need to use double quotes in those cases, or escape the single quote/apostrophe using a NCR/entity.

  4. #4
    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)
    Like mentioned; if double quotes appear in an attribute value, you should use single quotes to quote the value; if single quotes appear in an attribute value, you should use double quotes to quote the value. For example: <img src="example.png" alt="Robert's picture" /> Basically be constant: http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2 Obviously within XHTML all attribute values must be quoted.

  5. #5
    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)
    In examples like Robert's, I tend to like to use character entities, so's I can keepses mah preferred quoteses.

    Code:
    alt="Robert’s picture"
    huh and the forums eatses mah entities. &#8217 + ;

  6. #6
    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)
    Use NCR and Hex cat... &#x2019; and it won't get eaten by vBulletin. >;-)

  7. #7
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,592
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by xhtmlcoder View Post
    Use NCR and Hex cat... &#x2019; and it won't get eaten by vBulletin. >;-)
    You can also just wrap part of the entity in black color tags to avoid it ... &#8217;

  8. #8
    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)
    Using hex NCR is still better though regardless. NCR is the preferable choice over the entities, entities are limited to a subset of Unicode characters, NCR can specify any character and theoretically Hexadecimal has less ambiguity. >;-)

  9. #9
    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)
    I only use ncr's.


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
  •