Measure the Repeat in a Native CSS Gradient
Admin ·
A repeating gradient uses the distance between its first and last stops. Start with two solid bands and measure them in the downloaded stylesheet before adjusting the orientation or turning the gradient into a square tile.
Measure the two bands in the first 24 px period
Load Stripes. Keep Linear, a 90° angle, Pixels and a repeat period of 24. The two inside stops share a position at 50% of the period, so the dark stripe and the gold stripe each occupy 12 px.
Download the CSS and apply repeating-pattern to a rectangle. Along a center row there is dark near x = 5 px, gold near x = 17 px, then dark again near x = 29 px.
CSS Images Level 3 repeating linear and radial gradientsCSS Images Level 4 conic gradients and stop interpolation
Move the hard edge without changing the period
Set the period to 36 px and change Stop 2 and Stop 3 to 25%. Both middle stops map to 9 px along the line. The dark stripe is 9 px wide, the gold stripe is 27 px wide, and the next cycle begins at 36 px.
Add a color stop if you need a gradual transition. Keep the stops in order and change the added position. Unequal colors at the same position give a hard boundary, while unequal positions allow an sRGB blend between them.
CSS Images Level 3 repeating linear and radial gradientsCSS Images Level 4 conic gradients and stop interpolation
Compare circular sectors with offset square tiles
Choose Conic and set the period to 90°. The gradient repeats every quarter turn. Use Angle to rotate the sectors and Center x and Center y to reposition the point they turn around.
For a repeated square instead, load Checkerboard, set Tile side to 48 px and Tile gap to 4 px, and apply a 6 px horizontal offset. Check background-size and background-position in the export. The new position moves the complete tile including the gap.
CSS Images Level 4 conic gradients and stop interpolationCSS Backgrounds and Borders Level 3 background sizing and positioning
Common questions
Why do the stops read as percentages with a pixel period?
Stop inputs use percentages of one period. The exporter multiplies each fraction by the chosen period and writes the resulting pixel, percent or degree value.
How do I use alpha in a color stop?
Use a CSS color with alpha, such as rgba(38, 73, 99, .5). In the preview and exported rule the gradient blends over the background color.
Sources
Put it into practice.
- Repeating Gradient Generator
- CSS gradient generator
- CSS Pattern Library
- CSS Box Shadow Gradient Playground