Treehouse: Grow your CSS skills. Land your dream job.

Add alt and title attribute to an images using CSS sprite

  • # August 21, 2010 at 4:19 am


    I have number of images on my website and to make the page load time faster, i have combined all images into one image using sprite method and placing individual images as a background-position in the CSS file where ever required.

    I want to add keywords in the alt and title attribute for images.

    I want to know how to can i add alt and title attribute for images using the CSS Sprite technique??
    Is it possible??

    # August 21, 2010 at 6:12 pm

    Hi meherbala
    alt and tittle attributes are for images in your html markup. There is no need for them in a css sprite.

    # August 22, 2010 at 8:04 am

    @rch is correct – you don’t need to alt/title your CSS images, they are not classed as “content” :)

    # August 22, 2010 at 8:39 am

    Typically images that are “sprited” replaced an entire element on the page, kicking the text that was in that element away or otherwise hiding it. So that text that it’s removing basically is the ALT text.

    # June 6, 2012 at 8:29 pm

    I agree that background images don’t need alt tags.
    But in my case i’m using

    Do I need an alt tag for the 1X1 transparent image???

    # June 13, 2012 at 4:26 pm

    “Do I need an alt tag for the 1X1 transparent image??? “
    no you do not.

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

You must be logged in to reply to this topic.