A gradient button looks like a small thing until you try to write one by hand. You pick two colors, guess an angle, refresh the page, adjust, refresh again, and the hover state doubles the whole loop. The colors never quite match what you pictured, because you are editing numbers instead of looking at the blend.

The faster route is to separate the jobs. Design the gradient visually, where you can see it, and keep the button itself in your stylesheet, where it belongs. This guide uses the free CSS Gradient Generator on Ovatly to build a two-stop linear gradient, copy its background declaration onto a button, and then generate a second declaration for the hover state.

Contents

  • Quick answer
  • What the generator gives you, and what it does not
  • Angle: the setting that decides which edge looks lit
  • How to create a gradient button, step by step
  • Worked example: a sky-to-blue button with a hover state
  • Limitations and honest tradeoffs
  • Common mistakes
  • FAQs
  • Conclusion
  • References

Quick answer

Open the CSS Gradient Generator, choose linear, set two color stops, and pick an angle. Copy the background declaration it produces and paste it into your button's CSS rule. The button itself, its size, padding, text color and corners, is your own CSS; the generator supplies only the background. For a hover state, generate a second declaration, commonly with the two colors swapped, and place it under a :hover rule yourself, because the generator has no button or hover feature.

What the generator gives you, and what it does not

The generator builds linear, radial and conic gradients visually. You set the type, the angle, and up to six color stops, each with a color and a position, and the preview updates with every change. What you copy is a single CSS background declaration with hex colors, ready to paste.

That declaration is the whole deliverable, and it is worth being precise about the boundary. There is no button preview, no padding or font controls, and no export of a finished component. The preview you see is a live CSS rendering of the gradient, not an image file and not a button mockup. Everything about the button except its background stays in your stylesheet, which is where you want it anyway: the same declaration can dress a submit button today and a call-to-action link tomorrow.

Angle: the setting that decides which edge looks lit

A linear gradient runs in the direction its angle points, and the first stop's color sits at the edge the gradient starts from. At 180deg the gradient points downward, so the first color is at the top. Put the lighter color first and the top edge looks lit, as if light falls on the button from above. That is the classic raised-button look, and it costs you nothing but the order of two stops.

At 0deg the gradient runs bottom to top, so the first color sits at the bottom; swap the stops or the angle and the same button looks lit from below, which usually reads as pressed or wrong. At 90deg the blend runs left to right, first color on the left edge, which suits wide buttons where a horizontal sheen looks natural. Diagonal angles such as 135deg spread the highlight across a corner and feel more playful than formal.

The rule is simple: decide where the light comes from, then put the lighter color on that edge. Everything else about the angle is taste.

How to create a gradient button, step by step

  1. Open the CSS Gradient Generator and choose the linear type.
  2. Set the angle. For a standard button lit from above, use 180deg.
  3. Set the first stop to your lighter color at 0% and the second stop to your darker color at 100%. Check the preview: the blend should look even, with no band in the middle.
  4. Copy the background declaration and paste it into your button's rule in your stylesheet, alongside your own padding, text color, border and corner radius.
  5. For the hover state, go back to the generator, swap the two stop colors, and copy the new declaration. Paste it under your button's :hover rule.
  6. Load the page and hover the button. The background should shift without the button changing size or shape.

Worked example: a sky-to-blue button with a hover state

Build a linear gradient at 135deg with #0ea5e9 at 0% and #2563eb at 100%. The generator produces this declaration:

background: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);

Dropped into a button rule with ordinary button styling of your own, it looks like this:

.button {
  background: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
  color: #ffffff;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  cursor: pointer;
}

Only the first line came from the generator; the rest is standard button CSS. Now the hover state. Back in the generator, swap the stops so #2563eb sits at 0% and #0ea5e9 at 100%, and copy the second declaration:

.button:hover {
  background: linear-gradient(135deg, #2563eb 0%, #0ea5e9 100%);
}

Hovering now reverses the blend, which reads as the button responding to the pointer. A subtler option is to keep the stop order and shift the angle instead, but whichever you choose, the pattern is the same: one declaration per state, each generated on its own.

Limitations and honest tradeoffs

The generator emits solid hex colors only. Every stop is opaque, so there is no fade to transparent in the output. For a button that is rarely a loss, since a small surface reads better with a decisive blend, but an overlay-style button over a photo cannot be built from this output alone.

The six-stop ceiling is real, though a button almost never wants more than two or three stops; a small element with six pinned colors looks busy, not rich. The generator also gives you no fallback: the declaration is a single background line, so if you want a solid color behind the gradient for very old browsers, that line is yours to add. And because the preview is a live rendering rather than a button mockup, final judgement happens on your page, with your text, at your button's real size. A blend that looks smooth on a large preview can band on a short button, so check it in place.

Common mistakes

  • Expecting the generator to style the whole button. It supplies the background only. Flat text, square corners or a missing pointer cursor are stylesheet problems, not gradient problems.
  • Lighting the button from below. A darker color on top at 180deg makes the button look pressed in. Put the lighter color on the edge the light should hit.
  • Skipping the hover state, or faking it with opacity. Reducing opacity washes the whole button toward the page behind it. Generate a second declaration instead; it takes a minute.
  • Using a diagonal angle and a swapped hover that fight each other. Change one variable per state, angle or stop order, so the hover reads as a response rather than a different button.
  • Judging the gradient only in the large preview. Buttons are small. Check the blend at the real height before you ship it.

FAQs

Does the generator build the whole button for me? No. It builds the gradient and gives you one CSS background declaration. The button element, its padding, border, corner radius and text styling are your own CSS that the declaration drops into.

How do I create a hover effect for a gradient button? Generate a second declaration, for example with the two colors swapped, and place it under a :hover rule in your stylesheet. The generator has no hover feature, so the second state is a second trip through the same tool.

Which angle makes a button look lit from above? Use 180deg with the lighter color as the first stop. At 180deg the gradient points downward, so the first color sits at the top edge and the button reads as if light falls on it from above.

Can the button gradient fade to transparent? Not from this generator. Colors are emitted as hex values and every stop is a solid color, so the output has no transparent fade. A button rarely needs one; solid blends suit the small surface better.

Do I need vendor prefixes for the button gradient? No. Current browsers render standard linear gradients without prefixes, so the declaration you copy is the only line the background needs.

Conclusion

A gradient button is two small decisions made in the right tools: the blend, designed visually in the CSS Gradient Generator, and the button, styled in your own CSS with the copied declaration as its background. Generate one declaration per state, keep the lighter color on the lit edge, and check the result at real button size. If you are weighing whether a busier background gradient deserves more stops, our comparison of two-color vs multi-stop gradients works through that decision. For more guides in this series, see our Website and Webmaster Tools guides, which pair each technique with the free tool that performs it.

References