Color

CSS Gradient Generator Guide: Linear, Radial, Color Stops and Alpha

·

A CSS gradient generator creates a background image from color stops and their positions. ToolMellow builds linear gradients or a centered circular radial gradient, with 2–10 stops, transparency, presets and live preview. Edit the controls and copy the CSS background declaration or download a stylesheet.

The generated CSS reflects this tool’s supported geometry, color parsing, sorting and numeric formatting. This guide shows exact examples and explains why the editor’s list, reversed stops, transparent preview and rendered browser result are different parts of the workflow. Use the output in a real element and check the browsers and backgrounds you intend to support.

CSS gradient generator

Create a gradient and review its CSS

Open CSS gradient generator and choose Gradient type. It starts as Linear at 120 degrees, with #294C39 at 0% and #B9CE93 at 100%. Changes to type, angle, colors or stop positions recalculate the CSS and preview immediately. Radial uses a circle at the center; the angle control is shown for Linear.

Start from the existing pair or one of the four presets, then adjust the stops. Copy CSS copies a background declaration, while Download CSS saves a rule for a class selector. Before applying either, inspect the output and decide which element and background properties it should affect.

  • Test the gradient in an element with meaningful content or dimensions, rather than judging an empty zero-height box.
  • Use the real underlying surface when reviewing transparent regions.
  • Keep a separate copy of a useful CSS declaration before replacing the stops with a preset.

Linear direction, angle normalization and displayed precision

CSS linear-gradient angles are measured clockwise from an upward-pointing direction. The direction describes progression from the initial toward the final stop along the gradient line. The cardinal examples below make it easier to distinguish angle from color order; the default 120-degree direction lies between right and down.

The angle field displays 0–360 bounds, but this is not a JavaScript clamp. The helper accepts a finite angle, normalizes it modulo 360, then rounds its output to three decimal places. Thus -90 becomes 270 and 360 becomes 0; a value just below 360 can round to an emitted 360deg. Equivalent cyclic directions should not be confused with a promise to preserve every input digit.

Linear direction, angle normalization and displayed precision
AngleDirection toward the final stop
0degUp
90degRight
180degDown
270degLeft

W3C CSS Images 3: Linear/radial geometry and color stopsW3C CSS Values and Units 4: Angle units

Radial gradients: a centered circle

Selecting Radial produces radial-gradient(circle at center, ...). The circle’s center and default extent come from that emitted CSS geometry. This interface does not supply ellipse dimensions, radius, custom center coordinates, a conic type or repeating-gradient controls. Stop percentages apply to the radial gradient’s progression, rather than to horizontal positions on the page.

Switching type retains the stops and stored linear angle. Returning to Linear restores that angle control. The helper still checks that its stored angle is finite in Radial mode even though the radial CSS does not use it. Use the live preview as an example of the generated image in this box, then test the different dimensions of the actual element.

W3C CSS Images 3: Linear/radial geometry and color stopsW3C CSS Images 4: Gradient interpolation methods

Editor list order and stable numeric output order

Each editor row has a color field, a visual color picker, a position and Remove. Add color stop appends opaque white at 50%; it does not insert the row between the endpoints in the editor. The generated output uses a copied stop list sorted by the original numeric percentage, leaving the editor’s listed order intact.

Stops with exactly equal original positions retain their listed relative order in output. Positions are then rounded to three decimal places for serialization. Distinct nearby raw percentages can consequently produce the same emitted percentage, and their order still follows the earlier raw-position sort. Read the CSS when precision or coincident positions matter.

Editor list order and stable numeric output order
Editor exampleOutput order
Green 0%, light green 100%, newly added white 50%Green 0%, white 50%, light green 100%
White 100%, half-alpha black 0%, red 100%Half-alpha black 0%, white 100%, red 100%
Two different raw positions that round to the same percentageSorted by raw positions before their displayed coordinates are rounded

ECMAScript: Stable Array.prototype.sort

Create hard edges with coincident positions

Putting adjacent sorted stops at the same percentage can create a sharp color change. For example, linear-gradient(90deg, #FF0000 0%, #FF0000 50%, #0000FF 50%, #0000FF 100%) holds red up to the midpoint and blue after it. This is different from distributing two endpoint colors over the whole gradient line.

The tool’s stable ordering matters at a tie: changing the listed order of colors at an equal raw position can change which color lies on each side. Reversing stops intentionally changes that order. Rounded output can also place nearby raw positions together, so inspect both the original values and emitted CSS rather than assuming every hard edge was entered as an exact tie.

W3C CSS Images 3: Linear/radial geometry and color stopsW3C CSS Images 4: Gradient interpolation methodsECMAScript: Stable Array.prototype.sort

Reverse stops mirrors coordinates and reverses the list

Reverse stops first reverses the editor list, then maps every percentage p to 100 minus p. It keeps Gradient type and angle. Reversing the list alone would often leave the sorted output unchanged, so the coordinate mapping is an essential part of what this action does.

For original editor rows white at 100%, half-alpha black at 0% and red at 100%, reversing gives red at 0%, half-alpha black at 100% and white at 0%. The emitted sorted order is red 0%, white 0%, then half-alpha black 100%. The original white/red tie is reversed at the mirrored endpoint; the action is not a change to the numeric angle.

Exact default, radial and reordered output examples

The table shows bare gradient functions. The CSS background editor and Copy CSS add background: before the function and a semicolon after it. Technical color syntax, degree units and decimal points remain CSS syntax across interface languages.

The unsorted and reversed examples use the editor rows described in the preceding sections and a linear angle of -90. The helper normalizes that angle to 270 degrees. These examples establish formatting and order; they do not force a particular rendering or color-interpolation method in every browser.

Exact default, radial and reordered output examples
SettingsGenerated gradient function
Defaultlinear-gradient(120deg, #294C39 0%, #B9CE93 100%)
Radial with the default stopsradial-gradient(circle at center, #294C39 0%, #B9CE93 100%)
White 100%, rgba(0,0,0,0.5) 0%, red 100%; angle -90linear-gradient(270deg, rgba(0, 0, 0, 0.5) 0%, #FFFFFF 100%, #FF0000 100%)
Reverse that editor list and retain angle -90linear-gradient(270deg, #FF0000 0%, #FFFFFF 0%, rgba(0, 0, 0, 0.5) 100%)

Transparency and the preview checkerboard

Enter alpha in the stop’s text value using four/eight-digit HEX or an accepted RGBA/HSLA form. The Fade to clear preset goes from #294C39 to #294C3900, preserving the green RGB channels at zero alpha. The preview checkerboard belongs to the surrounding interface; it is not included in the gradient function, copied declaration or downloaded rule.

Transparent regions reveal whatever lies below the gradient in your own page. A visual color picker changes the RGB part and preserves the alpha of the existing valid color text. If that previous text is invalid, its alpha fallback is 1. The picker is an opaque RGB picker, so set or change alpha in the text field rather than expecting an alpha slider.

W3C CSS Color 4: Named colors, sRGB, alpha and interpolationW3C Compositing and Blending 1: Transparency over a backdrop

Color syntax, 8-bit channels and decimal alpha

The shared parser accepts 148 standard CSS named-color spellings plus transparent, HEX with 3/4/6/8 digits and optional #, and supported numeric RGB/RGBA or HSL/HSLA forms. HSL saturation and lightness need percentages. RGB or converted HSL channels are rounded to integer 8-bit sRGB values; decimal alpha is retained.

Opaque values are emitted in the parser’s uppercase HEX form, which can retain an explicitly supplied eight-digit HEX value ending in FF. Values with alpha below 1 are emitted as RGBA with the retained alpha. HEX alpha itself has 8-bit precision: #0008 represents 136/255, whereas rgba(0,0,0,0.5) contains decimal alpha 0.5. Unsupported variables, calculations, context-dependent colors, relative forms and wider color-space functions are rejected.

Color syntax, 8-bit channels and decimal alpha
Stop inputRelevant output behavior
redOpaque #FF0000
#FFFFFFFFOpaque eight-digit HEX can remain #FFFFFFFF
rgba(0,0,0,0.5)RGBA retains decimal alpha 0.5
#0008RGBA alpha comes from 136/255 rather than exactly 0.5

W3C CSS Color 4: Named colors, sRGB, alpha and interpolation

Presets replace stops while retaining type and angle

Meadow uses two green colors, Sunset and Ocean use three colors, and Fade to clear uses two green entries ending at zero alpha. A preset replaces the current stop list and spaces its entries evenly from 0% to 100%. It does not reset Gradient type or the stored angle, and there is no automatic history to restore a discarded custom list.

Keep between 2 and 10 stops. Add color stop is disabled at ten, and Remove is disabled at two. Each color field has a 200 UTF-16-unit limit. Positions must be finite from 0 to 100%; the control’s 0.1 step does not replace the helper’s range checks or three-decimal output formatting. Invalid colors or positions clear the generated CSS/preview and disable copying and downloading until corrected.

Presets replace stops while retaining type and angle
PresetListed colors
Meadow#294C39, #B9CE93
Sunset#F7CE68, #DC6656, #6E4574
Ocean#14385D, #249FAD, #D3F4D7
Fade to clear#294C39, #294C3900

Endpoint storage does not select every browser’s interpolation

The emitted function uses HEX/RGBA endpoints and positions without an explicit color-interpolation clause such as in srgb or in oklab. Current CSS Color 4 specifies gamma-encoded sRGB interpolation for legacy color formats, including the formats emitted here. That compatibility rule qualifies the general default-interpolation language in newer gradient specifications. The generator does not add an interpolation-space control; check the target browser when comparing rendered output.

If a gradient looks different in a target browser, compare the actual generated CSS, endpoint values, transparency, element dimensions and that browser’s applicable rendering behavior. This interface does not offer a color-space selector or guarantee perceptually uniform steps. Validate a production design in the browsers you support rather than inferring the interpolation method solely from the endpoint notation.

W3C CSS Images 3: Linear/radial geometry and color stopsW3C CSS Images 4: Gradient interpolation methodsW3C CSS Color 4: Named colors, sRGB, alpha and interpolation

Copy a declaration or apply the downloaded stylesheet

Copy CSS writes background: <gradient>; when clipboard access succeeds. If copying is unavailable, select the readonly CSS background text manually or use Download CSS. The download is text/css named toolmellow-gradient.css, containing a .gradient rule with the same background declaration. Add the class to the intended element or change the selector to match your stylesheet.

The background shorthand can reset other background subproperties that you did not specify. Review existing layers, background color, sizing and positioning before replacing a declaration. Give the element content or dimensions so its background has an area to paint. Copy/download again after edits: an older clipboard entry or saved stylesheet does not update when the preview changes.

W3C CSS Backgrounds and Borders 3: Background shorthandW3C CSS Images 3: Linear/radial geometry and color stops

Local state, privacy and reviewing readable content

Gradient calculation runs immediately in page memory. Refreshing or leaving the page discards this workspace state; copied CSS and downloaded stylesheets remain outside it. The calculation does not upload your color stops to a generation service. Ordinary hosting and public-site analytics requests still occur, so local generation does not imply anonymity or zero infrastructure logging.

Review the actual design after integration. Text over a gradient may meet different backgrounds across its area; a visually pleasing preview does not calculate contrast or prove accessibility. Use the contrast checker for relevant solid pairs and inspect the whole context separately. This tool exports CSS, rather than a raster image, print-color conversion or animation.

Embed the generator with the ToolMellow backlink

Use the integration section beneath the workspace to copy or download its localized HTML snippet. Paste it into a platform that permits the iframe and sizing script, and retain the visible backlink to the matching ToolMellow CSS gradient generator page. The supplied link uses nofollow and noopener.

Check the embedded layout on a narrow screen and verify clipboard behavior in the host context. Embedding makes the same interactive generator available with its existing limits; it does not turn the sizing messages into a background-image generation API or automatically style the host webpage.

Common questions

How do I create a CSS gradient?

Choose Linear or Radial, edit color stops and percentages, and review the immediately updated preview and CSS. Copy CSS for a background declaration or Download CSS for a .gradient stylesheet rule.

What does the linear angle mean?

CSS angles progress clockwise from up: 0deg up, 90deg right, 180deg down and 270deg left. The tool wraps finite angles modulo 360 before rounding their emitted value to three decimals.

Can I control the radial shape and center?

This tool emits a circle at the center with the CSS default extent. It does not provide ellipse sizes, radius or custom-center controls. The same stops are retained when switching types.

Why does the output order differ from the editor?

The CSS sorts a copied list by raw numeric position while retaining equal-position order. The editor itself stays in its listed order. New white stops are appended at 50%.

How do I create a hard edge?

Give adjacent colors the same position, or inspect emitted positions that round together. Stable ties retain listed order; reversing changes both the list and its mapped coordinates.

What exactly does Reverse stops do?

It reverses the editor list and maps each percentage to 100 minus its original value. Type and angle are retained. This also reverses the color order of genuine equal-position ties.

Can I fade a color into transparency?

Yes. Use an accepted alpha-bearing color or Fade to clear. The checkerboard shows transparent regions only in the tool preview; your actual background shows through after integration.

Does the color picker edit alpha directly?

No. It picks opaque RGB channels while retaining alpha from the previous valid stop text. Invalid prior text falls back to alpha 1. Edit alpha in the textual HEX/RGBA/HSLA value.

Does selecting a preset reset the angle?

No. A preset replaces the stops with evenly spaced entries but keeps the selected type and stored angle. Save useful custom CSS before replacing the list.

Are arbitrary stop-position digits preserved?

No. The helper sorts the original finite positions but rounds emitted percentages and normalized angles to three decimals. Close positions can serialize identically; near-360 angles can round to 360deg.

Why do browser previews differ?

Check generated CSS, endpoint quantization, alpha, dimensions and the browser’s rendering behavior. No explicit interpolation method is emitted; sRGB endpoint storage alone does not promise identical interpolation everywhere.

Is the downloaded file an image?

No. It is toolmellow-gradient.css with a .gradient background rule. Apply its selector to a real element and check the other background properties and dimensions.

What happens to invalid colors or positions?

An error appears, CSS and the gradient preview clear, and copy/download are disabled. Correct supported color syntax and finite positions from 0 to 100%. The workspace requires 2–10 stops.

Can I embed this CSS gradient generator?

Use the localized iframe/sizing snippet below the workspace and retain its visible ToolMellow backlink. It remains an interactive CSS tool, rather than a host-page styling or raster-export API.

Sources and further reading

Put it into practice.

Related guides