Accepting selected projects for Q2 2024 Check availability →
SERVER 02SYSTEM ONLINELAST SYNC: 03:17:44RSS 2.0 — ONLINE
HALF ASSEDTECHNICAL NOTES_
EST. 1999ISSUE 04.2BEST VIEWED AT 1024 × 768
TECHNICAL NOTES / TECHNICAL NOTES / FRONT-END / RECORD fef779
[FRONT-END]NOTE

CSS sprites: maintenance notes

POSTED: 17.03.2009AUTHOR: ADMIN5 MIN READCOMMENTS: 0

Combining interface images into a single file and displaying portions with background-position reduces the number of HTTP requests, which matters when browsers open only two connections per host. The saving is lost if nobody can safely alter the sprite afterwards.

Sprite only suitable images

Combine icons, button states and decorative interface graphics of fixed size. Leave content images, photographs and anything requiring alternative text as img elements; a background image conveys nothing to a screen reader or with stylesheets disabled.

Arrange for change

Lay images out on a regular grid with spare space between them so text resizing does not reveal a neighbouring image. Keep the layered source file under version control with the stylesheet, and add new images at the end so existing offsets remain valid.

Account for repeats and old browsers

Repeating backgrounds need a separate sprite arranged along the opposite axis. Check the result in Internet Explorer 6, where alpha-transparent PNG sprites do not behave as elsewhere, and confirm that the combined file is in fact smaller than its parts.

MAINTENANCE

Document the offsets beside the rules that use them. A sprite whose coordinates exist only in the memory of the person who built it will be replaced by individual images at the first amendment.