Toolstia / CSS gradient generator
CSS gradient generator
This tool builds a CSS gradient you can see while you edit it. Choose linear or radial, set up to five colors, drag each color to the position you want and, for linear gradients, turn the angle from 0 to 360 degrees. The preview and the code change together, and the finished line is ready to paste into a stylesheet.
It suits backgrounds for hero sections, buttons, cards and banners, and it is also a quick way to learn how color stops and angles behave. Five starting presets are included, and Random gives you a fresh combination when you want inspiration. Colors are chosen with the browser color picker, so values are solid six-digit hex colors.
- 0%
- 100%
CSS
background: linear-gradient(135deg, #ff7e5f 0%, #feb47b 100%);
How it works
- Choose linear or radial and pick your colours.
- Drag each colour to the position you want and set the angle.
- Press Copy CSS and paste it into your stylesheet.
Linear and radial
A linear gradient blends colours along a straight line at an angle you choose: 0 degrees goes upward, 90 degrees goes to the right. A radial gradient spreads outward from the centre in a circle.
Colour stops
Each colour has a position from 0% to 100%. Put two colours at nearby positions for a sharp edge, or far apart for a soft blend. You can use two to five colours.
Using the code
The output is a standard background declaration that works in every modern browser. Put it on any element, for example a section, a button or the body.
Readable text
Check that text on top of your gradient is still easy to read at its lightest and darkest points. The colour converter can check the contrast ratio.
What the generated line looks like
For the Sunset preset the tool writes background: linear-gradient(135deg, #ff7e5f 0%, #feb47b 100%); and for the Spotlight preset it writes background: radial-gradient(circle at center, #ffffff 0%, #4b6cb7 100%);. The stops are always sorted by position before they are written, so the order in which you added the colors does not matter.
Radial output is always a circle centered in the box. There are no controls here for ellipse shapes, off-center origins or size keywords, so if you need those, edit the copied line by hand.
How the angle is measured
In CSS the angle describes the direction the gradient travels. 0 degrees runs from bottom to top, 90 degrees from left to right, 180 degrees from top to bottom, and 270 degrees from right to left. The common 135 degrees runs from top-left toward bottom-right, which is why it is a popular diagonal. A value of 360 is the same as 0.
The angle slider disappears when you pick radial, because a circle spreading from the center has no direction.
Hard edges and stripes
Give two neighboring colors the same position and the blend between them disappears. Red at 50 percent followed by blue at 50 percent, then green at 100 percent, produces linear-gradient(90deg, #ff0000 50%, #0000ff 50%, #00ff00 100%): the left half is solid red, the line at the middle is a sharp edge, and the right half fades from blue to green.
Stacking several such pairs makes stripes or a banded background without images. Remember that the position slider moves one color at a time, so set both colors of a pair deliberately.
Why some blends look muddy
Browsers mix colors in the sRGB space by default, channel by channel. Halfway between pure blue (#0000ff) and pure yellow (#ffff00) the values average to a mid gray, and halfway between red and green you get a dull olive. If a gradient between opposite colors looks dirty, add a third stop in the middle with a brighter color you choose, rather than relying on the automatic blend.
Nearby hues, such as two shades of blue or an orange fading to pink, blend cleanly and are the safest choice for backgrounds behind text.
Practical uses beyond a plain background
The line can go on any element, and you can use the same value with background-image if you also set a fallback background-color for older or constrained environments. Gradients can also fill text when combined with background-clip: text and a transparent text color, which is applied in your own CSS rather than here.
Because the colors are opaque, a gradient laid over a photo will hide it. To fade into transparency, copy the code and change one stop to an rgba or eight-digit hex color.
Questions
Does the CSS need a vendor prefix?
No. Current browsers support the plain linear-gradient and radial-gradient syntax.
Can I add transparency?
Not in this tool yet. You can edit the copied CSS and change a colour to rgba() or an 8-digit hex value.
Is anything saved?
No. Your gradient exists only in the page.
What is the maximum number of colours?
Five, which is enough for almost every design.
Why does the Add a colour button stop working?
A gradient here can have at most five colors. Remove one with its Remove button, or edit the copied CSS if you need more.
Why can I not remove a color when only two are left?
A gradient needs at least two colors to blend, so the tool keeps two as the minimum.
What does Random do to the angle?
It picks two or three random colors, spreads them evenly from 0 to 100 percent, and sets a random angle between 0 and 359 degrees.
Can I use this for a border or text?
The output is a background value. Gradient borders and gradient text need extra CSS properties that you add yourself.
How do I keep the text on top readable?
Check the contrast against both the lightest and the darkest stop, or place a semi-transparent panel behind the text.