CSS Gradient Generator

Generate linear-gradient and radial-gradient visually.

About this tool

This tool generates linear-gradient and radial-gradient visually. Three features: 1) Adjust colors, angle, position with preview, 2) Copy generated CSS directly, 3) Supports both linear and radial gradients. Ideal for buttons and backgrounds.

Tool interface

  

The Complete Guide to CSS Gradients

CSS Gradients are a powerful tool in modern web design, adding depth, dimension, and visual interest to interfaces without the need for external image assets. In this comprehensive guide, we will explore everything from the basics of linear-gradient and radial-gradient to performance implications and advanced UI techniques.

What are CSS Gradients?

CSS Gradients allow you to display smooth transitions between two or more specified colors. Originally, developers had to rely on image editors like Photoshop to create gradient backgrounds, which negatively impacted page load times. With CSS3, gradients are purely code-based.

Because they are generated by the browser, gradients are resolution-independent and fully responsive. They can scale to any size without losing quality, making them perfect for responsive layouts. Furthermore, gradients can be animated to create dynamic, engaging user experiences.

💡 Key Benefits of CSS Gradients

  • Performance: Reduces HTTP requests and eliminates image loading wait times.
  • Responsiveness: Adapts automatically to any element size or screen resolution without pixelation.
  • Flexibility: Easily updated via CSS variables (custom properties) or manipulated through JavaScript for animations.

Core Syntax and Gradient Types

1. Linear Gradient (linear-gradient)

The most common type, where colors transition along a straight line. You can specify the direction using angles (degrees) or keywords.

/* Basic syntax: angle, start color, end color */
background: linear-gradient(90deg, #ff7e5f, #feb47b);

/* Using directional keywords */
background: linear-gradient(to right, #ff7e5f, #feb47b);
background: linear-gradient(to bottom right, #ff7e5f, #feb47b);

Angles are defined in degrees (deg), where 0deg points essentially "up", 90deg points "right", and so on. You can also define specific color stops (e.g., #ff7e5f 30%) to control exactly where a color should be fully opaque before transitioning.

2. Radial Gradient (radial-gradient)

Colors radiate outward from a central point, forming a circle or an ellipse. This is excellent for creating highlights behind elements or giving buttons a glowing effect.

/* Basic syntax: shape, start color, end color */
background: radial-gradient(circle, #00d2ff, #3a7bd5);

/* Specifying center position */
background: radial-gradient(circle at center, #00d2ff 0%, #3a7bd5 100%);

3. Conic Gradient (conic-gradient)

Colors transition rotated around a center point (like a color wheel or pie chart). This is incredibly useful for implementing CSS-only progress rings and data visualizations.

/* Colors change clockwise from 0 degrees */
background: conic-gradient(from 0deg, red, yellow, green, blue, red);

Design Tips for Beautiful Gradients

Mixing two random colors can sometimes result in muddy or unappealing gradients. Here are a few reliable techniques for creating visually stunning combinations.

Use Analogous Colors

Colors that sit next to each other on the color wheel (e.g., Blue and Purple, Red and Orange) blend smoothly together. Avoid highly contrasting complementary colors (like Red and Green) without an intermediary color, as they tend to create a muddy gray zone in the middle.

Implement Multi-Stop Gradients

If you need to transition between distant colors, add an intermediate "stop" color to bridge the gap and maintain vibrancy.

/* Poor example: Often results in a dull middle section */
background: linear-gradient(to right, red, blue);

/* Better example: Adding magenta keeps the gradient vibrant */
background: linear-gradient(to right, red, magenta, blue);

Leverage the Alpha Channel

Using rgba() or hex codes with transparency (e.g., #ffffff80) allows gradients to overlay images or patterns. This is the foundational technique behind the popular Glassmorphism design trend.

Practical UI Code Snippets

1. Gradient Text

Apply a gradient fill to text rather than just the background to make headers stand out.

.gradient-text {
  background: linear-gradient(90deg, #ff8a00, #e52e71);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

2. Animated Hover Buttons

By over-sizing the background and shifting its position on hover, you can create a fluid, animated gradient button.

.gradient-btn {
  background: linear-gradient(90deg, #00c6ff, #0072ff, #00c6ff);
  background-size: 200% auto;
  transition: background-position 0.5s ease;
}
.gradient-btn:hover {
  background-position: right center;
}

Accessibility Considerations (WCAG)

When placing text over a gradient background, contrast is critical. You must ensure that both the lightest and darkest parts of the gradient provide sufficient contrast against your text color. The WCAG AA standard requires a contrast ratio of at least 4.5:1 for normal text.

If your gradient is complex, consider adding a slight text-shadow or a semi-transparent dark overlay behind the text to guarantee readability across all devices.

About This CSS Gradient Generator

Writing gradient code manually and constantly switching back to the browser to preview changes is inefficient. This tool provides a visual slider and color picker interface to instantly generate, preview, and adjust complex CSS gradients. Once you have achieved the perfect look, simply click to copy the cross-browser compatible CSS code directly into your project.

Usage

  1. Adjust colors, angle, position with sliders or inputs
  2. Preview the gradient appearance
  3. Copy generated CSS and paste into your project

When to use

Button/background gradients, hero section decoration, icon/badge styles.

Examples

linear-gradient(135deg, #667eea 0%, #764ba2 100%), radial-gradient(circle, #fff 0%, #000 100%)

FAQ

What is linear-gradient?

CSS function for linear gradients. Specify direction (angle or to right) and color stops for smooth transitions.

How to use CSS gradients?

Set background or background-image: linear-gradient(90deg, red, blue) for left-to-right red→blue.

linear-gradient vs radial-gradient?

Linear = straight line (angle). Radial = from center outward (circle/ellipse). Buttons use linear; light effects use radial.

How to specify gradient angle?

Use deg: 0=up, 90=right, 180=down, 270=left. Or keywords: to right, to bottom right.

Related tools