SitePoint Sponsor

User Tag List

View Poll Results: What syntax do you use for CSS's URL() attribute

Voters
12. You may not vote on this poll
  • always double quotes

    2 16.67%
  • always single quotes

    3 25.00%
  • always no quotes

    5 41.67%
  • a mix

    2 16.67%
  • whatever pattern has already been established

    0 0%
  • other

    0 0%
Results 1 to 13 of 13
  1. #1
    Barefoot on the Moon! silver trophy
    Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,521
    Mentioned
    51 Post(s)
    Tagged
    1 Thread(s)

    URL("file.ext") vs URL('file.ext') vs URL(file.ext)

    I've noticed that when an outside file is needed in CSS (such as a background image), people use slightly different syntax. Some use double quotes on the file/path, some use single quotes, some don't use anything, and some are inconsistant.

    What do you use, and which do you see as the "correct" way?

    Note that all three ways are technically valid under the W3C spec: http://www.w3.org/TR/CSS21/syndata.html#uri
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  2. #2
    Non-Member thewebhostingdir's Avatar
    Join Date
    Oct 2005
    Posts
    703
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not using quotes. However, not exactly sure if it is correct or not.

  3. #3
    SitePoint Evangelist Karpie's Avatar
    Join Date
    Jul 2007
    Location
    Perth, Australia
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've always used single quotes.

  4. #4
    Resident curmudgeon bronze trophy gary.turner's Avatar
    Join Date
    Jan 2009
    Location
    Dallas
    Posts
    990
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The quotes are optional, but if used, must not be mixed. See Syntax and basic data types.

    cheers,

    gary
    Anyone can build a usable website. It takes a graphic
    designer to make it slow, confusing, and painful to use.

    Simple minded html & css demos and tutorials

  5. #5
    Barefoot on the Moon! silver trophy
    Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,521
    Mentioned
    51 Post(s)
    Tagged
    1 Thread(s)
    Sorry, I rephrase that...I probably should have said "varies between statements", rather than "mixed". As in, somewhere use URL("file1.jpg") and then somewhere else use URL(file2.jpg)
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  6. #6
    Resident curmudgeon bronze trophy gary.turner's Avatar
    Join Date
    Jan 2009
    Location
    Dallas
    Posts
    990
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was referring to any given uri. That is, this, url("some.html') is invalid.

    cheers,

    gary
    Anyone can build a usable website. It takes a graphic
    designer to make it slow, confusing, and painful to use.

    Simple minded html & css demos and tutorials

  7. #7
    Barefoot on the Moon! silver trophy
    Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,521
    Mentioned
    51 Post(s)
    Tagged
    1 Thread(s)
    Right, that's what I thought you were implying
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  8. #8
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    39,803
    Mentioned
    158 Post(s)
    Tagged
    4 Thread(s)
    I never use any quotes as they are not required so why use them as they just waste space. It's also less typing and less chance of error

    (As an aside (and of no real importance today) single quotes don't work in IE5 mac and you get no image.)

  9. #9
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,564
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    As said above it doesn't matter
    Off Topic:

    Paul!! I saw this thread title and was gonna mention the IE5 mac thing GRR @ UUUUU


    I just don't use quotes at all-why bother worrying if you closed the ' or " off?
    Twitter-@Ryan_Reese09
    http://www.ryanreese.us -Always looking for web design/development work

  10. #10
    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)
    It depends on the website, sometimes I use double, sometimes single and sometimes none, I have never really seen it as a convention worth much consideration so I just go with what I feel like at the time, but whatever I do I make sure it's consistant throughout the design

  11. #11
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    39,803
    Mentioned
    158 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by AlexDawson View Post
    , but whatever I do I make sure it's consistant throughout the design
    Yes it must be consistent and I see many many examples in the forums where all three versions are used (and then it usually follows that the rest of the code is a mess as well ).

    Off Topic:

    As an aside it makes it hard to debug as I usually copy the page locally and do a search and replace for url( or - url(" - and then add the absolute path name to get a local working copy of the page. However this fails or is very awkward if the page isn't consistent.

  12. #12
    <!-- Insert thoughts here --> pitcher17's Avatar
    Join Date
    Apr 2004
    Location
    The great white north
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I try to stick with no-quotes purely for its efficiency and the fact that I'll do anything to avoid carpal tunnel.

    However, I will add single quotes when I am stuck using image names that others have created which include spaces in the names.
    The more time I save by not planning and documenting,
    the more time I have left to debug.


  13. #13
    Barefoot on the Moon! silver trophy
    Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,521
    Mentioned
    51 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by pitcher17 View Post
    However, I will add single quotes when I am stuck using image names that others have created which include spaces in the names.
    Interesting...that hadn't occurred to me. Quotes are required for filenames or filepaths with spaces? (when %20 isn't being used)
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain


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
  •