Quotes: one, two or none?

Discussion in 'CSS' started by Eva., Oct 27, 2012.

  1. #1
    hi guys, I'm a total beginner so for now this is going to be basic stuff......

    In the syntax below, should myimage.jpg be in single quotes, in double quotes or in no quotes?

    Body {background-image:url(myimage.jpg);}

    In W3Schools tutorials I'm seeing single quotes in the text, but in their Example it's double quotes. An online search is throwing up samples with no quotes.

    Also.....
    Is there a definitive CSS Reference somewhere online that lists not just CSS properties but also their corresponding values?

    Thanks for any assistance,
    Eva
     
    Eva., Oct 27, 2012 IP
  2. Host Volt

    Host Volt Greenhorn

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    15
    #2
    Hey, to answer your first question, you can use:

    CSS Code:

    body {
    background:url(myimage.jpg);
    }




    I don't think the quotes are necessary, because I don't use the quotes on any of our websites. The quotes are pretty much optional :)

    Online, W3Schools does give CSS properties and their values. You can go to http://www.w3schools.com/css/css_positioning.asp for an example, and just scroll down near the bottom of the page, and it lists the CSS properties, along with a description and their values. Not all CSS properties will have specific values though... Hope this helped :)

    - Jason
     
    Last edited: Oct 28, 2012
    Host Volt, Oct 28, 2012 IP
    Eva. likes this.
  3. Eva.

    Eva. Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hi Jason,
    Thanks for a really helpful reply. :)

    Cheers!
    Eva
     
    Eva., Oct 28, 2012 IP
  4. Host Volt

    Host Volt Greenhorn

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    15
    #4
    No problem, glad I can help! :)
     
    Host Volt, Oct 28, 2012 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #5
    The only time you need quotes in a CSS property is if it has SPACES in it or it's a string literal. Font-family is a great example of the former:

    font-family: "Courier New",courier,serif;

    courier and serif dont' need quotes, there's no spaces in them... courier new has spaces in it, so you're supposed to use quotes.

    background-image:url(images/myTest.png);
    no spaces needed.

    background-image:url("images/my Test.png");

    This is because CSS properties use spaces as delimiters... re:
    padding:4px 4px 8px 0;

    So it makes life easier on the parser.

    String literals are a bit rare, the only example I can think of is generated content.

    content:"any text on the content property must be in quotes";

    Though if you're looking around the web, most people never bother doing what you are doing when they should -- asking "WHY" and "WHEN" -- but again most people just sleaze out their HTML and CSS any old way without taking the time to bother learning how either technology works.

    Site after site you'll see people throwing them in for no reason, or omitting them when they should be there because they pretty much just copypasta bad code or bad habits.
     
    deathshadow, Oct 29, 2012 IP
  6. Eva.

    Eva. Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks deathshadow, this is very useful to know. I have added it to a "Working Manual" I'm compiling as I go.

    Also agree with your stance on learning code. I'm hoping time invested in learning the details now will pay dividends later in time and money saved. But best of all it will give creativity a free run.

    Cheers! :)
    Eva.
     
    Eva., Oct 30, 2012 IP
  7. GokuDBZ

    GokuDBZ Well-Known Member

    Messages:
    408
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    140
    Digital Goods:
    2
    #7
    @deathshadow,

    Thanks for this. I've been coding websites since 2 months and I didn't knew this (didn't bother to find out xD).
    I've posted it on my blog so that I can recall in future if anyone asks the same question. Thanks.
     
    GokuDBZ, Nov 15, 2012 IP
  8. wizardofx

    wizardofx Well-Known Member

    Messages:
    572
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    140
    #8
    Are double quotes equivalent to single quotes?


    wiz
     
    wizardofx, Nov 15, 2012 IP