---
id: css-image-sprites
title: "CSS Image Sprites"
category: "Frontend"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["image sprite", "sprite image", "CSS sprites", "background-position sprite", "navigation sprite"]
duplicate_of: ""
source_trust_level: "B"
confidence_score: 0.89
created_at: 2026-06-23
updated_at: 2026-06-23
review_reason: ""
merge_history: []
tags: ["css", "web", "frontend", "w3schools", "sprites", "background-position", "performance"]
raw_sources: ["https://www.w3schools.com/css/css_image_sprites.asp"]
applied_in: []
github_commit: ""
---
# [[CSS Image Sprites]]
## π― ν μ€ ν΅μ°° (One-line insight)
An image sprite packs many small images into one file, then uses `background-image` plus `background-position` offsets to display just the needed slice β cutting server requests and eliminating hover-load delay. [S1]
## π§ ν΅μ¬ κ°λ
(Core concepts)
- **Image sprite** β a collection of various small images put into one larger image file, called a "sprite image." [S1]
- **Why sprites** β using a single sprite reduces the number of server requests and saves bandwidth versus loading many separate images. [S1]
- **Two key properties** β sprites are implemented with `background-image` (the sprite file) and `background-position` (which slice to show). [S1]
- **Transparent placeholder** β a tiny transparent image (`img_trans.gif`, `1Γ1`) can act as the element while CSS controls which part of the sprite is visible. [S1]
- **Hover without extra loads** β hover effects shift `background-position` (e.g. `45px` down) to a different region of the sprite, so no additional image needs to load. [S1]
## π§© μΆμΆλ ν¨ν΄ (Extracted patterns)
- **Slice selection** β fix an element's `width`/`height` to one icon's size and use a negative `background-position` to scroll the sprite so only that icon shows. [S1]
- **Shorthand background** β combine file and position in one `background: url('sprite.gif') -47px 0;` declaration. [S1]
- **Hover row swap** β keep horizontal offset, change the vertical offset on `:hover` to reveal a second row of the sprite for interactive feedback. [S1]
## π μΈλΆ λ΄μ© (Details)
**What is an image sprite?**
An image sprite is a collection of various small images put into one larger image file, called a "sprite image." This approach reduces the number of server requests and saves bandwidth. Sprites are implemented with the `background-image` and `background-position` properties. [S1]
**Example 1 β Basic Image Sprites**
Three elements (`#home`, `#prev`, `#next`) each set their own `width`/`height` and reference the same `img_navsprites.gif`, differing only by `background-position` so each shows a different icon. Transparent `1Γ1` images serve as the element bodies: [S1]
```html
```
**Example 2 β Navigation List**
The sprite is applied to a navigation list (``/`- `). The list uses relative/absolute positioning to lay items out horizontally, with each item's `left` offset and `background` shorthand isolating its icon from the sprite: [S1]
```css
#navlist {
position: relative;
}
#navlist li {
margin: 0;
padding: 0;
list-style: none;
position: absolute;
top: 0;
}
#navlist li, #navlist a {
height: 44px;
display: block;
}
#home {
left: 0px;
width: 46px;
background: url('img_navsprites.gif') 0 0;
}
#prev {
left: 60px;
width: 43px;
background: url('img_navsprites.gif') -47px 0;
}
#next {
left: 120px;
width: 43px;
background: url('img_navsprites.gif') -91px 0;
}
```
**Example 3 β Hover Effect**
Adds interactivity by shifting `background-position` 45px down (to a hover row of `img_navsprites_hover.gif`) on `:hover`. Because all images preload in one file, there is no loading delay on hover: [S1]
```css
#home a:hover {
background: url('img_navsprites_hover.gif') 0 -45px;
}
#prev a:hover {
background: url('img_navsprites_hover.gif') -47px -45px;
}
#next a:hover {
background: url('img_navsprites_hover.gif') -91px -45px;
}
```
**Advantages highlighted:** a single server request instead of multiple image downloads; reduced bandwidth consumption; and no loading delay on hover effects since all images preload in one file. [S1]
## π οΈ μ μ© μ¬λ‘ (Applied in summary)
The page's three examples β basic sprite slices, a positioned navigation list, and a hover row swap β are the applied demonstrations. No external project/commit applications found in the source.
## π» μ½λ ν¨ν΄ (Code patterns)
Display one slice of a sprite (language: CSS):
```css
#prev {
width: 43px;
height: 44px;
background-image: url('img_navsprites.gif');
background-position: -47px 0;
}
```
Hover row swap with the background shorthand (language: CSS):
```css
#prev a:hover {
background: url('img_navsprites_hover.gif') -47px -45px;
}
```
## βοΈ λͺ¨μ λ° μ
λ°μ΄νΈ (Contradictions & updates)
No contradictions found in the source.
## β
κ²μ¦ μν λ° μ λ’°λ
- **μν:** draft
- **κ²μ¦ λ¨κ³:** conceptual (μ€μ μ μ© μ¬λ‘ λ°κ²¬ μ applied/validatedλ‘ μΉκ²© κ°λ₯)
- **μΆμ² μ λ’°λ:** B (W3Schools β widely used educational reference, not a primary standards body)
- **μ λ’° μ μ:** 0.89
- **μ€λ³΅ κ²μ¬ κ²°κ³Ό:** μ κ· μμ± (New discovery)
## π μ§μ κ·Έλν (Knowledge Graph)
- **μμ/루νΈ:** [[CSS Tutorial]]
- **κ΄λ ¨ κ°λ
:** [[CSS Backgrounds]], [[CSS Position]], [[CSS Image Gallery]]
- **μ°Έμ‘° λ§₯λ½:** Referenced when optimizing icon/asset delivery by consolidating many images into one file with positioned background slices.
## π μΆμ² (Sources)
- [S1] W3Schools β CSS Image Sprites β https://www.w3schools.com/css/css_image_sprites.asp
## π λ³κ²½ μ΄λ ₯ (Change history)
- 2026-06-23: Initial draft synthesized from the W3Schools "CSS Image Sprites" page (Astra wiki-curation, P-Reinforce v3.1 format).