w1coding.comAll tutorials

CSS Image Sprites

CSS lessons
  1. Environment Setup
  2. Introduction
  3. Tdisplay
  4. Basics
  5. Editors
  6. Syntax
  7. Colors
  8. Background
  9. Borders
  10. Margins
  11. Padding
  12. Width And Height
  13. Outline
  14. Texts
  15. Fonts
  16. Icons
  17. Links
  18. Lists
  19. Display
  20. Tables
  21. Max And With
  22. Positon
  23. Z Index
  24. Dropdown
  25. Overflow
  26. Float
  27. Navigation
  28. Image Sprites

Introduction to CSS Image Sprites

Image sprites are a way to reduce the number of HTTP requests by combining multiple images into one file and displaying parts of it as needed.

Using Image Sprites

  • Use the background-position property to display specific parts of the sprite image.
  • Useful for icons or button images.

Example


.icon {
    background-image: url('sprite.png');
    width: 50px;
    height: 50px;
}
.icon-home {
    background-position: 0 0;
}
.icon-search {
    background-position: -50px 0;
}
        

Browser Support

Supported by all major browsers.