CSS Gradient Generator

JJ Ben-Joseph headshot JJ Ben-Joseph

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:

C ( t ) = ( 1 t ) C 0 + t C 1

Here:

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 gradients

A linear gradient in CSS usually looks like this:

background: linear-gradient(45deg, #ff0000, #0000ff);

Key points:

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:

How to Use This CSS Gradient Generator

  1. Choose a gradient type. Use the dropdown to select Linear or Radial.
  2. Set the angle or size.
    • For a linear gradient, enter an angle in degrees (for example 90 for left-to-right, 180 for top-to-bottom).
    • For a radial gradient, enter a percentage size. Values like 50 or 75 are treated as relative radii, such as 50%.
  3. 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.
  4. Generate the gradient. Activate the generate button. The preview updates to show how the gradient will look, and the tool outputs a CSS background line.
  5. Copy the CSS. Copy the generated background declaration into your stylesheet, or paste it directly into an element’s style attribute.

Formulas and Parameters Used by the Tool

Internally, the generator converts your inputs into one of two CSS functions:

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:

C ( r ) = ( 1 r ) C 0 + r C 1

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:

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:

  1. Set the gradient type to Linear.
  2. Enter 135 in the angle field. This creates a diagonal gradient that roughly runs from top-left toward bottom-right.
  3. Choose #ff0000 (pure red) as the start color.
  4. Choose #0000ff (pure blue) as the end color.
  5. 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:

  1. Select Radial as the type.
  2. Enter a size such as 70 (interpreted as 70%).
  3. 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:

Practical Usage Tips

A few guidelines to get nicer results from your gradients:

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.

Embed this calculator

Copy and paste the HTML below to add the CSS Gradient Generator - Linear and Radial to your website.