CSS image sprites are a single image that combines multiple images, used to reduce page loading time and bandwidth consumption.
Why Use Image Sprites?
Image sprites are used for two main reasons:
- Faster Page Loading: By using a single image, page loading time is significantly reduced.
- Reduced Bandwidth: Less data is consumed, resulting in faster loading and improved user experience.
Image sprites are generally used for designing a graphic social media bar or a navigation bar to make it more attractive and efficient at the same time. It is just a method in HTML and CSS to implement a more efficient way of putting images and designing web pages.
Used Image: ![]()
How Image Sprites Work
Image sprites are implemented using HTML and CSS, where a single image is defined and then styled using CSS to display the desired image segment.
Example: This example shows the use of image sprites in CSS.
<!DOCTYPE html>
<html>
<head>
<style>
#navlist {
position: relative;
}
#navlist li {
margin: 0;
padding: 0;
list-style: none;
position: absolute;
top: 0;
}
#navlist li,
#navlist a {
height: 100px;
display: block;
}
.gfg {
width: 100px;
left: 0px;
background: url('https://media.geeksforgeeks.org/wp-content/uploads/icon.png') -0px -0px;
}
.gfg1 {
width: 100px;
left: 120px;
background: url('https://media.geeksforgeeks.org/wp-content/uploads/icon.png') -0px -140px;
}
.gfg2 {
width: 100px;
left: 240px;
background: url('https://media.geeksforgeeks.org/wp-content/uploads/icon.png') -300px -140px;
}
</style>
</head>
<body>
<ul id="navlist">
<li class="gfg"><a href="#"></a></li>
<li class="gfg1"><a href="#"></a></li>
<li class="gfg2"><a href="#"></a></li>
</ul>
</body>
</html>
Output: 
Use Cases for Image Sprites
Image sprites are commonly used for:
- Graphic Social Media Bars
- Navigation Bars
- Icon Sets