CSS Gradient Generator
Introduction: What This CSS Gradient Generator Does
This CSS Gradient Generator lets you build simple background gradients for web pages and UI components. You can choose between a linear gradient (which blends colors along a straight line) and a radial gradient (which blends colors outward from a center point). The tool focuses on the most common use case: smooth transitions between two colors, with an adjustable angle or size.
All calculations run in your browser. After choosing a gradient type, angle or size, and start/end colors, the tool shows a live preview and provides a ready-to-copy CSS background declaration you can paste into a stylesheet or inline style attribute.
How CSS Gradients Work
A CSS gradient is a function that tells the browser how to transition between two or more colors across space. You can think of every pixel in the element as having a position parameter that determines how much of each color is mixed in.
For a basic two-color linear gradient, the color at any point along the gradient axis can be modeled as a weighted average of the start and end colors:
Here:
C(t)is the resulting color at positiontalong the gradient axis.tranges from 0 to 1, where 0 is the start of the gradient and 1 is the end.C0is the start color in RGB space.C1is the end color in RGB space.
The browser interpolates each RGB channel independently, so red, green, and blue components each change linearly with t. A similar idea applies to radial gradients, except the parameter is distance from the center rather than distance along a straight line.
Linear vs. Radial Gradients in CSS
CSS provides two primary gradient functions that this tool focuses on:
linear-gradient()for gradients that flow along a straight line defined by an angle.radial-gradient()for gradients that radiate outward from a center point.
Linear gradients
A linear gradient in CSS usually looks like this:
background: linear-gradient(45deg, #ff0000, #0000ff);
Key points:
- The first argument is the angle (for example
45degor180deg). - Following the angle are two or more color stops (for this tool, just two: start and end).
- Angles in CSS increase clockwise, with
0degpointing up.90degruns left-to-right,180degruns top-to-bottom, and so on.
Radial gradients
A radial gradient uses a circular or elliptical shape and blends colors from the center out toward the edges:
background: radial-gradient(circle 50%, #ff0000, #0000ff);
Important aspects:
- The keyword
circleorellipsedefines the shape. - The size (such as
50%) indicates how far the gradient extends relative to the element’s box. - Colors are defined from the center (start color) to the outer edge (end color).
How to Use This CSS Gradient Generator
- Choose a gradient type. Use the dropdown to select Linear or Radial.
- Set the angle or size.
- For a linear gradient, enter an angle in degrees (for example
90for left-to-right,180for top-to-bottom). - For a radial gradient, enter a percentage size. Values like
50or75are treated as relative radii, such as50%.
- For a linear gradient, enter an angle in degrees (for example
- Pick your colors. Use the two color inputs to select a start color and an end color. These correspond to the first and second color stops in the generated CSS.
- Generate the gradient. Activate the generate button. The preview updates to show how the gradient will look, and the tool outputs a CSS
backgroundline. - Copy the CSS. Copy the generated
backgrounddeclaration into your stylesheet, or paste it directly into an element’sstyleattribute.
Formulas and Parameters Used by the Tool
Internally, the generator converts your inputs into one of two CSS functions:
- For linear gradients:
linear-gradient(<angle>deg, <start-color>, <end-color>). - For radial gradients:
radial-gradient(circle <size>%, <start-color>, <end-color>)(or a simplified variation of this form).
The angle field accepts any numeric value. When converted to CSS, values greater than 360 degrees are effectively taken modulo 360, because CSS interprets them cyclically. For radial gradients, the numeric value is treated as a percentage size relative to the container, which in practice controls how tight or expansive the gradient appears.
The underlying interpolation for both types uses the linear blending idea described earlier. For a radial gradient, we conceptually replace the linear position parameter t with a normalized radius parameter r, which varies from 0 at the center to 1 at the outer edge:
Again, r runs from 0 at the center to 1 at the defined radius, and C0 / C1 are your chosen start and end colors.
Interpreting the Generated Results
After you generate a gradient, you will typically see two things:
- A visual preview box that displays the gradient applied as a background.
- A CSS code snippet that defines the gradient using standard syntax.
The browser where you paste this code will calculate the same gradient at render time. The key part to look at is the background value, which may look like:
background: linear-gradient(120deg, #34d399, #1d4ed8);
or:
background: radial-gradient(circle 60%, #f97316, #9333ea);
You can freely change colors, angles, or sizes later without returning to the tool; just edit the values in your CSS. However, the generator provides an easy visual way to experiment, especially when you are trying out unfamiliar color combinations.
Worked Example
Suppose you want a header background that fades from bright red to deep blue diagonally. Here is one way to do it with this generator:
- Set the gradient type to Linear.
- Enter
135in the angle field. This creates a diagonal gradient that roughly runs from top-left toward bottom-right. - Choose
#ff0000(pure red) as the start color. - Choose
#0000ff(pure blue) as the end color. - Generate the gradient and copy the CSS line.
The generated snippet might look like this:
background: linear-gradient(135deg, #ff0000, #0000ff);
You can then apply it to a header element as follows:
.site-header {
background: linear-gradient(135deg, #ff0000, #0000ff);
color: #ffffff;
padding: 2rem;
}
If you prefer a softer effect, you could switch the generator to a radial gradient with the same colors:
- Select Radial as the type.
- Enter a size such as
70(interpreted as70%). - Keep the same start and end colors.
The resulting CSS could be:
background: radial-gradient(circle 70%, #ff0000, #0000ff);
This configuration concentrates your start color toward the center and lets the end color dominate near the edges, which can be useful for spotlight or vignette-style backgrounds.
Comparison: Linear vs. Radial Gradients
| Aspect | Linear Gradient | Radial Gradient |
|---|---|---|
| Direction control | Controlled with an angle in degrees (0–360). | Controlled by center point and shape; this tool simplifies it to a circular radius percentage. |
| Visual appearance | Color transition along a straight line, often used for stripes or directional lighting. | Color transition from the center outward, good for spotlight and radial glow effects. |
| Typical use cases | Section backgrounds, buttons, navigation bars, and banners. | Highlights behind icons, avatars, callouts, or hero sections. |
| Control in this tool | Pick type Linear, set an angle (degrees), and two colors. | Pick type Radial, set a relative size (percentage), and two colors. |
| CSS function used | linear-gradient() |
radial-gradient() |
Limitations and Assumptions of This Generator
This tool is intentionally streamlined for fast experimentation. It does not aim to cover the full CSS gradient specification. When you use it, keep the following constraints and assumptions in mind:
- Two color stops only. The interface supports exactly two colors: a start color and an end color. More complex gradients with three or more stops (for example, red to yellow to blue) are not generated automatically.
- No alpha channel controls. The color inputs work with opaque hex colors such as
#ff0000. While CSS gradients can includergba()values with transparency, those are not exposed directly through this UI. - Simplified radial sizing. Radial gradients in full CSS can specify shapes, extents, and focal points. This tool simplifies that down to a single numeric size that maps to a percentage radius, with a centered circular gradient.
- Standard syntax only. The generated code uses modern, unprefixed
linear-gradient()andradial-gradient()functions. Older vendor-prefixed forms (such as-webkit-linear-gradient) are not included. - Browser interpretation of angles. Angles are passed directly to CSS. As per the spec,
0degpoints upward and increases clockwise. If you are accustomed to a different convention (for example, mathematical angles where 0 degrees points to the right), be aware of this difference. - Center and orientation defaults. The generator assumes default positioning (centered gradients) and does not expose controls for custom centers or aspect ratios.
- Client-side only. All logic runs in your browser and is based on the current CSS Level 3 gradient syntax. No server-side rendering, saving, or sharing of gradients is performed.
Practical Usage Tips
A few guidelines to get nicer results from your gradients:
- Use subtle contrast for large areas. For full-page backgrounds or large sections, pick colors closer together in brightness and saturation to avoid visual banding or distraction.
- Reserve strong contrast for accents. High-contrast gradients work well for buttons, call-to-action elements, and hero headers, where you want to draw attention.
- Test text legibility. If you place text over a gradient background, check contrast and readability in both light and dark areas. Often, adding a semi-transparent overlay on top of the gradient improves legibility.
- Reuse generated snippets. Once you like a gradient, store the generated CSS in a design system or utilities file so you can reapply it consistently across components.
Where to Go From Here
The generator is best used as a quick visual lab for simple two-color gradients. You can start with the generated CSS, then expand it by hand if you need more advanced effects: additional color stops, custom positions, or alpha transparency. Because the output follows standard linear-gradient() and radial-gradient() syntax, it should integrate cleanly into modern front-end workflows, CSS frameworks, and component libraries.
As you explore gradients, combine this tool with other CSS resources—such as color palettes or box-shadow utilities—to create cohesive, layered designs without relying on heavy image assets.
Arcade Mini-Game: CSS Gradient Generator Calibration Run
Use this quick arcade run to practice separating useful scenario inputs from common planning mistakes before you rely on the calculator output.
Start the game, then use your pointer or arrow keys to catch useful inputs and avoid bad assumptions.
