--- 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 (`