GameParticles
Colors

CSS Gradients Guide: Linear, Radial and Conic Syntax

A CSS gradient guide with copyable examples: linear, radial and conic syntax, color stops, hard edges, and how to pick gradient colors that blend cleanly.

Updated

A CSS gradient is an image the browser draws from a list of colors, set with background or background-image. The three types are linear-gradient() for a straight-line blend, radial-gradient() for a blend that spreads from a center point, and conic-gradient() for a blend that sweeps around a center like a clock hand. The shortest working example is background: linear-gradient(#7c3aed, #22d3ee);.

Because a gradient is an image and not a color, it does not work in background-color or color. Everything below goes in background or background-image.

Linear gradient syntax

The pattern is linear-gradient(direction, color-stop, color-stop, ...).

  • linear-gradient(#7c3aed, #22d3ee): no direction, so it runs top to bottom.
  • linear-gradient(to right, #7c3aed, #22d3ee): left to right.
  • linear-gradient(to bottom right, #7c3aed, #22d3ee): corner to corner.
  • linear-gradient(135deg, #7c3aed, #22d3ee): an exact angle.

Angles start at 0deg pointing up and increase clockwise.

AngleKeywordRuns toward
0degto topTop
90degto rightRight
180degto bottomBottom (the default)
270degto leftLeft
45degnoneUp and to the right
135degnoneDown and to the right

A corner keyword and a 45 degree angle are only the same thing on a square. On a wide box, to bottom right aims at the actual corner, while 135deg keeps a fixed angle.

Color stops

Each color can carry a position, as a percentage or a length. Without positions, colors are spaced evenly.

  • Three evenly spaced colors: linear-gradient(90deg, #7c3aed, #ec4899, #f97316)
  • Explicit positions: linear-gradient(90deg, #7c3aed 0%, #ec4899 30%, #f97316 100%). The pink now arrives early, and the long stretch to orange takes up the rest.
  • A hard edge: linear-gradient(90deg, #7c3aed 50%, #22d3ee 50%). Two stops at the same position leave no room to blend, so you get two solid halves.
  • Two positions on one color: linear-gradient(90deg, #7c3aed 0% 50%, #22d3ee 50% 100%). Same result, written as a range per color.
  • A color hint: linear-gradient(90deg, #7c3aed, 30%, #22d3ee). The bare percentage moves the midpoint of the blend to 30 percent without adding a color.

Hard edges are how striped and segmented backgrounds are made without any image file.

Radial gradient syntax

The pattern is radial-gradient(shape size at position, color-stops). Every part before the colors is optional. The defaults are an ellipse that matches the box proportions, sized to reach the farthest corner, centered.

  • radial-gradient(#7c3aed, #22d3ee): an ellipse from the center.
  • radial-gradient(circle, #7c3aed, #22d3ee): a true circle.
  • radial-gradient(circle at top left, #7c3aed, #22d3ee): a circle that starts in the corner.
  • radial-gradient(circle closest-side at 30% 40%, #7c3aed, transparent): a spot that fades out when it reaches the nearest edge.

The size keywords are closest-side, farthest-side, closest-corner and farthest-corner. A radial gradient fading to transparent, layered over a dark background color, is the standard way to make a soft glow.

Conic gradient syntax

The pattern is conic-gradient(from angle at position, color-stops). Colors change as you go around the center, starting at the top and moving clockwise. Stop positions can be percentages or angles.

  • A color wheel: conic-gradient(red, yellow, lime, aqua, blue, magenta, red). Repeating the first color at the end hides the seam.
  • A pie chart: conic-gradient(#7c3aed 0% 40%, #22d3ee 40% 75%, #e5e7eb 75% 100%) with border-radius: 50% on the element.
  • A rotated start: conic-gradient(from 90deg, #7c3aed, #22d3ee).

Conic gradients work in all current browsers.

Repeating and layered gradients

Each type has a repeating version: repeating-linear-gradient(), repeating-radial-gradient() and repeating-conic-gradient(). The stop list tiles once it ends. Diagonal stripes are repeating-linear-gradient(45deg, #7c3aed 0 10px, #22d3ee 10px 20px).

background also accepts several gradients separated by commas. The first one listed sits on top, so the upper layers need transparency for the lower ones to show.

Choosing gradient colors

Not every pair of colors blends well. The browser interpolates in sRGB by default, which draws a straight line between the two colors. If they sit on opposite sides of the color wheel, that line passes through gray and the middle of the gradient looks washed out.

Three ways to avoid it:

  • Pick neighbors. Colors within roughly a quarter turn of each other on the wheel, such as blue to purple or orange to pink, blend cleanly.
  • Add a middle stop. Going from blue to yellow through a green or pink stop steers the blend around the gray.
  • Change the interpolation space. linear-gradient(in oklch, #7c3aed, #f97316) blends through vivid hues instead of gray. This syntax works in current versions of the major browsers but not in older ones, so put a plain gradient on the line before it as a fallback.

Some pairs that work as a starting point:

MoodFromTo
Violet to cyan#7c3aed#22d3ee
Sunset#f97316#ec4899
Ocean#0ea5e9#1e3a8a
Mint#34d399#06b6d4
Soft peach#fda4af#fde68a
Night#0f172a#4338ca

If you have one brand color and need a partner for it, the Color Palette Generator lists analogous colors, which are the neighbors that blend well, from a single HEX value.

Common uses

  • Gradient text: set background: linear-gradient(90deg, #7c3aed, #22d3ee), then background-clip: text (plus -webkit-background-clip: text) and color: transparent.
  • Image overlay: linear-gradient(to top, rgb(0 0 0 / 70%), transparent) layered above a photo keeps white captions readable. Check the result against the rules in WCAG color contrast explained.
  • Buttons: a shallow two-stop gradient with stops only 5 to 10 percent apart in lightness adds depth without looking dated.

Building one visually

Writing stops by hand is slow because you cannot see the result. The Gradient Generator shows a live preview while you edit. It builds linear and radial gradients with two to five color stops, each with its own color and position. Linear gradients take one of eight direction presets or a custom angle. The output is available as a CSS background line, as Tailwind classes, or as SVG markup with a matching gradient definition.

Two limits to know. The radial output is a centered circle, so for an off-center or elliptical gradient, edit the generated line using the syntax above. Conic and repeating gradients are not generated, so write those by hand. Tailwind's built-in gradient classes cover three stops and the eight standard directions, and the Tailwind tab notes when a design goes beyond that.

Other color tools, including contrast checking and format conversion, are in the colors category.

Try it

Open the Gradient Generator, set the direction to 135deg, and replace the two default stops with a pair from the table above. Add a third stop in the middle, drag its position, and copy the CSS line when the preview looks right.

Tools in this guide

Frequently asked questions

How do I make a linear gradient in CSS?

Set a background with the linear-gradient function, giving a direction and at least two colors, for example background: linear-gradient(90deg, #7c3aed, #22d3ee). The direction can be an angle or a keyword such as to right. Without one, the gradient runs top to bottom.

What is the difference between a linear and a radial gradient?

A linear gradient changes color along a straight line at a chosen angle. A radial gradient starts at a center point and changes color outward in a circle or ellipse. Both accept the same color stop list.

Which colors make a good gradient?

Colors that sit close together on the color wheel, such as blue to purple or orange to pink, blend smoothly. Opposite colors pass through a dull gray midpoint, so add a middle stop or use a color space such as OKLCH to keep the blend vivid.

Can I animate a CSS gradient?

A plain transition between two gradients does not interpolate, because gradients are images. Common workarounds are animating background-position on an oversized gradient, fading a second layer with opacity, or registering the colors as custom properties with @property.

More colors guides

JSON Formatter
Developer · Format, validate and minify JSON with syntax highlighting.
↵
Base64 Encode / Decode
Developer · Encode text to Base64 or decode Base64 back to plain text.
↵
URL Encoder / Decoder
Developer · Encode or decode URL components and query strings.
↵
Hash Generator
Developer · Generate MD5, SHA-1, SHA-256 and SHA-512 hashes.
↵
UUID Generator
Developer · Generate UUIDs v4 (random) in bulk with one click.
↵
Regex Tester
Developer · Test regular expressions against text with live match highlighting.
↵
Word Counter
Text · Count words, characters, sentences, paragraphs and reading time.
↵
Case Converter
Text · Convert text between UPPER, lower, Title, camelCase, snake_case and more.
↵
List Sorter
Text · Sort, reverse, deduplicate and shuffle lists of text.
↵
Markdown Preview
Text · Write Markdown and see a live rendered preview side by side.
↵
Percentage Calculator
Numbers · Calculate percentages, increases, decreases and what % one number is of another.
↵
Color Converter
Colors · Convert colors between HEX, RGB, HSL and HSV instantly.
↵
Snake
Arcade · Eat food, grow longer, don't hit the walls. A timeless classic.
↵
2048
Puzzle · Slide tiles and combine them to reach the legendary 2048 tile.
↵
Word Grid
Puzzle · Guess the hidden five letter word in six tries using color clues.
↵
Sudoku
Puzzle · Fill the 9x9 grid with logic. Four difficulties from easy to expert.
↵
Minesweeper
Strategy · Use number clues to clear the minefield. Classic logic, three levels.
↵
Breakout
Arcade · Smash every brick with paddle and ball. Power-ups, combos, endless levels.
↵
Typing Practice
Casual · Build your WPM and accuracy with timed drills from 30 seconds to 5 minutes. Find your weak keys.
↵
TypeRunner
Arcade · Multiplayer typing race. Race friends by link, beat computer runners, or chase your own ghost.
↵
Typing Blocks
Arcade · Type each word before its wooden block lands. Miss, and the pile climbs toward the line.
↵
Bubble Shooter
Arcade · Aim, bank shots off the walls, and pop groups of three or more bubbles.
↵
Road Rush
Arcade · Race seven rivals through traffic and punch your way to the front.
↵