CSS Gradient Generator
Generate beautiful CSS linear and radial gradients. Visual color picker, two color stops, copy-paste CSS code.
CSS Code
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
What is a CSS gradient generator?
A CSS gradient generator builds the background code for a smooth blend between colours, so you can create gradient backgrounds without image files. In MavexTech’s generator you pick two colours, choose a linear or radial gradient and a direction, see a live preview, and copy one line of CSS — by default background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);, a diagonal blue-to-purple blend. Gradients are resolution-independent, load instantly and can be changed in code at any time.
How to use the generator
- Pick Color 1 and Color 2 with the colour pickers (any hex colour).
- Choose the type — Linear for a straight blend, Radial for a blend that spreads out from the centre.
- Choose the angle or direction for linear gradients: 0deg, 45deg, 90deg, 135deg, 180deg, “to right” or “to bottom”.
- Check the preview and click Copy CSS. Paste the line into the rule for your hero section, button or card.
How CSS gradients work
A gradient is an image generated by the browser, so it is used with background or background-image, not background-color. The generator writes each colour with an explicit stop — 0% for the first colour and 100% for the second — so the blend runs across the full element.
- linear-gradient(angle, colour stops) blends along a straight line. In CSS,
0degpoints up and angles turn clockwise, so90degruns left to right and180degtop to bottom (the default if no angle is given). - radial-gradient(circle, colour stops) starts at the centre with the first colour and reaches the second colour at the farthest corner (the default
farthest-cornersize).
The length of a linear gradient line depends on the box and the angle: |width × sin(angle)| + |height × cos(angle)|. For a 300 × 200 px box that is 200 px at 0deg, 300 px at 90deg and about 353.55 px at 45deg or 135deg, so the corners get the pure start and end colours.
Angle and direction reference
| Value | Colour 1 starts at | Colour 2 ends at |
|---|---|---|
0deg / to top | Bottom | Top |
45deg | Bottom-left | Top-right |
90deg / to right | Left | Right |
135deg | Top-left | Bottom-right |
180deg / to bottom | Top | Bottom |
270deg / to left | Right | Left |
Corner keywords such as to top right are not always the same as 45deg: the keyword adjusts the angle so the colours meet exactly at the corners, which matches 45deg only on a square box.
Example gradients (code copied from the live tool)
| Look | Settings | CSS output |
|---|---|---|
| Default violet | #667eea → #764ba2, linear, 135deg | background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); |
| Saffron to green | #ff9933 → #138808, linear, 90deg | background: linear-gradient(90deg, #ff9933 0%, #138808 100%); |
| Sunset button | #f97316 → #ec4899, linear, 45deg | background: linear-gradient(45deg, #f97316 0%, #ec4899 100%); |
| Dark header | #0f172a → #334155, linear, 180deg | background: linear-gradient(180deg, #0f172a 0%, #334155 100%); |
| Soft spotlight | #ffffff → #e5e7eb, radial | background: radial-gradient(circle, #ffffff 0%, #e5e7eb 100%); |
Worked example: a tricolour banner
Generate the saffron-to-green gradient above, then add a middle stop by hand to make a three-colour blend: background: linear-gradient(180deg, #ff9933 0%, #ffffff 50%, #138808 100%);. For sharp bands instead of a blend, put two stops at the same position — a “hard stop”: linear-gradient(180deg, #ff9933 33.33%, #ffffff 33.33% 66.66%, #138808 66.66%). Each colour now fills exactly one third, a handy technique for Independence Day or Republic Day banners without any image.
Going further by hand
- More colours — add as many stops as you like:
linear-gradient(90deg, red 0%, yellow 50%, green 100%). - Text gradients — apply the gradient as a background, then add
background-clip: text; color: transparent;(with-webkit-background-clip: textfor older Safari). - Overlays on photos — layer a transparent gradient above an image to keep white text readable:
background: linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.6) 100%), url(hero.jpg);. - Conic gradients —
conic-gradient(from 0deg, #22c55e 0 70%, #e5e7eb 70% 100%)draws a 70% progress ring or pie slice. - Repeating gradients —
repeating-linear-gradient(45deg, #000 0 10px, #222 10px 20px)makes stripes.
Tips
- Two neighbouring hues (blue to violet, orange to pink) look smooth; opposite hues (red to green) can pass through a muddy grey in the middle — add a middle stop to steer it.
- Recent browsers also support interpolation in other colour spaces, e.g.
linear-gradient(in oklch, …), which avoids grey midpoints; keep a plain gradient as a fallback for older browsers. - Always set a solid
background-colortoo, so text stays readable if the gradient fails to load in an email client or old browser. - Check text contrast at both ends of the gradient, not just in the middle.
- Large, very subtle gradients can show visible banding on some screens; a little more colour difference or a small amount of noise helps.
Limitations & notes
The generator supports two colours with stops at 0% and 100%, seven preset directions for linear gradients and a centred circle for radial gradients. Angles such as 270deg, elliptical or off-centre radial gradients, transparency, extra stops and conic gradients are written by hand using the examples above. The colour pickers update the preview when you confirm a colour. Nothing is uploaded — the CSS is generated in your browser.
Frequently asked questions
What angle makes a vertical gradient?
Use 180deg or to bottom for top to bottom, and 0deg or to top for bottom to top. If you leave the angle out entirely, CSS uses to bottom.
Can a gradient have three or more colours?
Yes. Add more colour stops separated by commas, for example linear-gradient(135deg, red 0%, yellow 50%, green 100%). The generator makes two-colour gradients; add extra stops by hand.
Why does my gradient not show when I use background-color?
Gradients are images in CSS, so they only work with background or background-image. Put the gradient in background and a fallback solid colour in background-color.
What is the difference between linear and radial gradients?
A linear gradient blends along a straight line at a chosen angle. A radial gradient blends outward from a centre point, which suits spotlights, buttons and soft vignettes.
Is 45deg the same as to top right?
Only on a square element. The to top right keyword adjusts the angle to the element's shape so the colours meet exactly at the corners, while 45deg is a fixed angle.
Do CSS gradients work in all browsers?
Unprefixed linear and radial gradients work in all current browsers. Conic gradients are also widely supported in current browsers, while colour-space interpolation such as in oklch needs a recent browser version.
Are gradients better for performance than images?
Usually yes. A gradient is a few bytes of CSS, needs no extra download and stays sharp at any screen size, unlike a background image file.
Related tools
Box Shadow Generator · Color Picker · Hex to RGB Converter · Color Palette Extractor · CSS Beautifier
