Image to CSS Box-Shadow Converter
Convert any image to pure CSS box-shadow art. Upload a picture and get pixel-perfect CSS code with optimized HEX/RGBA colors, no libraries needed.
About
CSS box-shadow accepts an arbitrary number of shadow layers. Each layer maps to one pixel: horizontal offset x, vertical offset y, zero blur, a spread equal to the pixel size, and the pixel's color. An image of w Γ h pixels produces up to w β h shadow declarations. A 64 Γ 64 source generates up to 4096 entries. Output size grows quadratically with resolution. This tool reads raw RGBA data from a Canvas context, skips fully transparent pixels (Ξ± = 0), and selects HEX notation when Ξ± = 255 to minimize byte count. Processing runs inside a Web Worker so the interface stays responsive even on images exceeding 10 000 pixels.
Practical uses include pure-CSS sprites for email signatures, novelty portfolio pieces, and demonstrations of browser rendering limits. Note: most browsers degrade rendering performance above roughly 50 000 shadow layers. Keep source dimensions small. This tool approximates the original image under the assumption that each pixel maps to a uniform square of configurable size. Anti-aliased edges and sub-pixel detail are lost.
Formulas
Each opaque pixel at column c and row r with color channels R, G, B, A produces one shadow layer:
where s = pixel size in CSS pixels (default 1). The color function selects the shorter representation:
RGB to HEX conversion:
Total pixel count and output estimation:
where w = image width in pixels, h = image height in pixels, Ntransparent = count of fully transparent pixels skipped, s = pixel size multiplier (1 - 10 px), R, G, B = red, green, blue channels (0 - 255), A = alpha channel (0 - 255).
Reference Data
| Source Size (px) | Max Shadows | Approx. CSS Size | Browser Render | Recommended Use |
|---|---|---|---|---|
| 16 Γ 16 | 256 | 5 - 8 KB | Instant | Favicons, tiny icons |
| 32 Γ 32 | 1 024 | 20 - 35 KB | Instant | Pixel art, emojis |
| 48 Γ 48 | 2 304 | 45 - 75 KB | Fast | Avatars, badges |
| 64 Γ 64 | 4 096 | 80 - 130 KB | Fast | Thumbnails, sprites |
| 96 Γ 96 | 9 216 | 180 - 300 KB | Moderate lag | Portraits (simple) |
| 128 Γ 128 | 16 384 | 320 - 520 KB | Noticeable lag | Demos, experiments |
| 192 Γ 192 | 36 864 | 700 KB - 1.2 MB | Heavy lag | Stress tests only |
| 256 Γ 256 | 65 536 | 1.3 - 2 MB | May freeze tab | Not recommended |
| Color Format Comparison | ||||
| HEX (#RRGGBB) | 7 bytes/color | Opaque pixels only (Ξ± = 255) | ||
| RGBA (rgba(R,G,B,A)) | 18 - 24 bytes/color | Semi-transparent pixels | ||
| Transparent skip | 0 bytes | Pixels with Ξ± = 0 omitted entirely | ||
| box-shadow Syntax per Pixel | ||||
| Full form | Xpx Ypx 0 Spx color - 5 tokens | |||
| Zero-offset form | 0 0 0 Spx color - units omitted on 0 | |||
Frequently Asked Questions
box-shadow property is supported in all modern browsers including Chrome, Firefox, Safari, and Edge. However, rendering performance degrades with large shadow counts. Chrome typically handles up to 50 000 shadows before noticeable lag. Firefox tends to be slightly slower. Internet Explorer 9 supports box-shadow but will struggle with more than a few hundred layers.