Grow your CSS skills. Land your dream job.

quotes in css?

  • # November 20, 2011 at 1:44 am

    I see some css with quotes and some without. Is it optional? I don’t remember. Why put them if it works without? example


    background: url('images/myimage.png');

    or

    background: url(images/myimage.png);

    # November 20, 2011 at 2:25 am

    It is personal preference, double quotes are also acceptable. Keep in mind that if there is a space separating two individual values then you need to wrap them in quotes:

    class=banner ribbon

    Is not equal to:

    class="banner ribbon" or class='banner ribbon'

    # November 20, 2011 at 9:33 am

    @Joshuan, that is in HTML. In HTML5 it is valid to use no quotes, but I recommend to use them. Because of the space problem.

    @Cybershot, in CSS there is no need to use quotes. But it has the same problem as in HTML, if there is a space you need to use de quote. Examples:

    font-family: 'Trebuchet MS', Verdana, sans-serif;
    /* Trebuchet MS needs quotes, because there is a space in the name */
    background: url('images/my image.png');
    /* There is a space => quotes (but in this case, I should remove the space in the name */
    background: url(images/myimage.png);
    /* No spaces, so we don't need to use quotes */
    # November 20, 2011 at 5:29 pm

    @WouterJ Perhaps I should have been clearer, HTML and CSS have the same behaviour in regards to quotes.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".