To make a linear gradient in CSS, define its direction and color stops in a linear-gradient() background value.

A CSS linear gradient is a browser-generated image that blends colors along a gradient line. Each color stop anchors one color to a position on that line. The result fills the element’s background painting area, so the element’s width and height also shape how a diagonal appears.

The workflow below creates a precise three-color gradient, keeps every stop position easy to audit, and ends with the rendering checks needed before putting the declaration into production.

how to make linear gradient
How to Make Linear Gradient Backgrounds in CSS

Understand the parts of a linear gradient

The basic pattern is linear-gradient(angle, color position, ...). The first argument defines the gradient line, while the remaining arguments define colors and their positions along that line.

CSS component Purpose
linear-gradient() Creates a generated image from a direction and a series of color stops.
Angle Defines the direction of the gradient line.
Color Specifies the color placed at each stop.
Percentage position Anchors a color at a particular point on the gradient line.

Using percentage positions makes the transition structure visible and keeps the declaration easy to adjust after it moves into a stylesheet. In the focused three-color workflow, all three stops remain explicit rather than relying on implied defaults.

For syntax beyond this article, MDN’s gradient data type reference documents the wider gradient family, while CSS Images Level 3 provides the standards context.

Build a three-color gradient with validated controls

Use the following workflow to configure, inspect, and copy one complete declaration:

  1. Set the angle. Open the CSS Gradient Generator and choose an angle from 0 through 360 degrees. This establishes the direction of the gradient line before any colors are added.
  2. Choose three colors. Select three six-digit hexadecimal colors. The generator normalizes each color to the six-digit hex format so the preview and copied declaration use unambiguous values.
  3. Place the stops in ascending order. Assign each color a percentage between 0 and 100. Start with 0, 50, and 100 percent when you need a balanced baseline, then move the middle stop to change where the strongest blend occurs.
  4. Review the exact preview. The preview uses the same linear-gradient value returned in the CSS declaration. This keeps what you inspect connected to what you copy rather than maintaining separate visual and code versions.
  5. Copy and test the declaration. Copy the result only after checking real content across the full gradient. Include text, links, and controls, and repeat the check at the responsive sizes used by the component.

Everything in the generator runs locally in the current browser tab. Values are not uploaded or saved, no account is required, and using the tool does not add a library dependency to your project.

Choose an angle that fits the element

CSS linear-gradient angles follow a fixed directional convention:

Angle Gradient direction
0deg Upward
90deg Rightward
180deg Downward
270deg Leftward
360deg Boundary value equivalent to 0deg

Intermediate values create diagonal gradients. However, the gradient line is resolved against the gradient box, so the same angle can look different on a wide banner and a narrow card. Adjust the angle for the component’s aspect ratio rather than assuming that a desktop preview will transfer unchanged to mobile. Also test the full 360-degree boundary in the same way as any other accepted angle.

Place stops to shape the transition

Color stops determine where each selected color is anchored. A position of 0 percent anchors the first color at the start of the visible gradient line, while 100 percent anchors the final color at its end. Equal adjacent positions are permitted and produce a hard transition instead of a blended one.

  • Start predictably. Keep the three stops at 0, 50, and 100 percent before making visual adjustments. This gives each outer color a clear endpoint and the middle color a defined central role.
  • Move the middle stop deliberately. Shifting it changes where the blend changes most strongly. The exact visual effect still depends on the selected colors and the browser’s interpolation behavior.
  • Use equal stops for a hard edge. When two adjacent stops share a position, the browser changes directly from one color to the next without a gradual blend between them.
  • Keep the order explicit. Descending stops are rejected instead of being silently corrected, making the design intent visible while you work.

CSS can represent stops outside the visible 0-to-100-percent range, but this focused generator intentionally restricts positions to that range. It also omits alpha-transparency and custom interpolation-space controls, as well as radial, conic, and repeating gradient types. Browser interpolation and display characteristics can affect the perceived midpoint even when the declaration is unchanged.

Add the gradient to your stylesheet

A complete three-stop declaration can look like this:

.hero { background: linear-gradient(90deg, #0F172A 0%, #7C3AED 50%, #F8FAFC 100%); }

The generator’s copied output uses the background shorthand for convenient placement in a CSS rule. That shorthand is suitable when the element only needs the gradient, but it can reset other background subproperties if they are omitted. If a component also needs a background color, image layers, background position, or background size, integrate the gradient carefully or switch to background-image so the shorthand does not overwrite those settings.

  • Use the copied declaration directly when the gradient is the component’s only background layer.
  • Use a background-image declaration when separate background color or other background settings must remain in control.
  • Do not expect the tool to produce additional layers. Multiple gradients can be combined with commas in CSS, but this generator creates one linear layer.

Test the rendered result before shipping

The generator does not calculate text contrast or interpolate in a custom color space. A declaration can therefore be valid while still creating readability or hierarchy problems in the browser. Test the rendered component with its actual content, not just the empty preview.

  • Check the full text area. Contrast may pass at one point and fail elsewhere. Inspect every region occupied by text, links, form fields, icons, and controls.
  • Test responsive dimensions. A diagonal can change appearance as the gradient box changes shape. Recheck narrow screens and any layout where the container’s aspect ratio changes substantially.
  • Verify relevant browser conditions. Test the browsers, themes, forced-color modes, printing output, and screenshots required by your project. Brand colors that look correct on one display may not produce the same perceived midpoint on another.
  • Do not rely on color alone. If the gradient communicates status, pair color with text, an icon, or another non-color cue.
  • Watch the visual hierarchy. Strong multi-color backgrounds can distract from controls and reduce prominence. Consider a subtle two-color treatment, an overlay, or a solid fallback when the three-color effect competes with important content.

When something looks wrong, diagnose the cause before changing values. A diagonal that shifts between layouts usually reflects the gradient box rather than a bad angle. An abrupt edge may come from equal stops. Missing background styles can result from the shorthand resetting other subproperties. A midpoint that differs from a design specification may reflect browser interpolation or display behavior, particularly when perceptual uniformity is a strict brand requirement.

For a deeper look, see CSS Grid Generator Cheat Sheet: Syntax and Limits.

For a deeper look, see CSS Loader Generator Example: Build a Ring Spinner.