Color and design guides

Turn a CSS Gradient into Exact-Size Image Pixels

·

Choose a raster file when a destination needs an image instead of a CSS background. Use a fixed pixel size, then check where the gradient stops land in the saved file.

Gradient to Image Converter

Measure a hard edge at the midpoint

Choose the Hard edge sample. Set Width to 120 px, Height to 64 px and Image format to PNG. Select Create image and save the file.

Open it at 100% zoom. The left half is #123456 and the right half is #D7A04C. Along a horizontal scanline, the color changes between columns 59 and 60 when counting from zero.

Measure a hard edge at the midpoint
Sample pointExpected pixel
Column 20, row 32#123456
Column 100, row 32#D7A04C

CSS Images Level 4 gradient syntax and color stops

Save the same alpha gradient in both formats

Paste linear-gradient(90deg in srgb, #FF000000 0% 50%, #FF0000 50% 100%). Export PNG. Its left half is fully transparent and its right half is opaque red.

Switch to JPEG and set JPEG background to #124B80. Create a new image. The left half now shows the blue background. Compare pixels well away from the edge because JPEG compression can soften the abrupt transition.

CSS Images Level 4 gradient syntax and color stopsCSS Color Level 4 alpha and interpolationHTML Canvas bitmap serialization

Common questions

Can I paste a single background-image declaration?

Yes. The reader accepts one supported gradient value or its single background or background-image declaration.

What if the browser reports invalid CSS?

Check for balanced parentheses, valid stop positions and literal colors. Replace any custom properties, URLs or page-dependent values before pasting.

Sources

Put it into practice.

Related guides