CSS Gradient Effects
This example demonstrates how to create gradient effects using CSS. Explore linear, radial, conic, repeating, transparent, layered, and animated gradients. Gradients can be used for backgrounds, buttons, borders, headings, and decorative elements without requiring image files.
Horizontal Linear Gradient
A linear gradient transitions between colors from left to right.
Horizontal Gradient
The to right keyword controls the gradient direction.
Vertical Linear Gradient
A vertical gradient transitions between colors from top to bottom.
Vertical Gradient
The to bottom keyword creates a downward color transition.
Diagonal Linear Gradient
A gradient angle can create diagonal color transitions.
Diagonal Gradient
The 135deg value specifies the gradient direction.
Multiple Color Gradient
A gradient can contain three or more colors.
Multiple Colors
Additional color stops create transitions between several colors.
Radial Gradient
A radial gradient transitions outward from a central point.
Radial Gradient
The circle keyword creates a circular gradient shape.
Elliptical Radial Gradient
An elliptical gradient creates an oval-shaped color transition.
Elliptical Gradient
The ellipse keyword defines the gradient shape.
Conic Gradient
A conic gradient transitions colors around a central point.
Conic Gradient
The conic-gradient() function creates angular color transitions.
Repeating Linear Gradient
A repeating gradient creates a pattern of alternating colors.
Repeating Gradient
The repeating-linear-gradient() function repeats a defined color pattern.
Transparent Gradient
Gradients can transition between opaque and transparent colors.
Transparent Gradient
The rgba() function allows transparency to be included in gradient colors.
Sharp Color Stops
Two colors can meet at the same position to create a sharp boundary.
Sharp Color Stops
Matching color-stop positions create an immediate color change instead of a smooth transition.
Positioned Radial Gradient
The center of a radial gradient can be positioned anywhere inside an element.
Positioned Gradient
The at top left keywords position the gradient near the upper-left corner.
Layered Gradients
Multiple gradients can be layered to create more complex background effects.
Layered Gradients
Comma-separated background images allow gradients to appear on top of one another.
Gradient Text
A gradient can be clipped to the shape of text.
Gradient Text
The background-clip: text declaration displays the gradient through the text characters.
Gradient Border
A gradient background can create a colorful border around an element.
The outer element provides the gradient while the inner element creates the content area.
Gradient Button
Gradient backgrounds can be applied to buttons and other interface controls.
Gradient Button
The button combines a gradient background with hover and focus effects.
Animated Gradient
CSS animations can create the appearance of a moving gradient background.
Animated Gradient
The background-position property changes over time using CSS keyframes.
Gradient Hover Effect
A gradient background can shift when the pointer moves over an element.
Hover Over Me
The transition property smoothly changes the background position.
Gradient Hero Section
Gradients can create attractive backgrounds for hero sections, banners, and promotional content without using background images.
Learn How Gradients Work
Try It: Compare the different gradient styles and experiment with their colors, angles, and positions. Move your mouse over the Gradient Hover Effect and Gradient Button examples. Change the gradient color stops and animation duration to create your own designs.
How CSS Gradients Work
CSS gradients create smooth transitions between two or more colors.
Gradients are generated by the browser and can be used wherever CSS images are supported, including the background-image property.
CSS provides several gradient functions, including linear-gradient(), radial-gradient(), and conic-gradient().
The following CSS creates a basic linear gradient:
background: linear-gradient(to right, #146c94, #247a45);
The first color appears on the left, and the second color appears on the right.
Creating Linear Gradients
The linear-gradient() function creates a color transition along a straight line.
The direction can be defined using keywords such as to right, to bottom, or an angle.
For example, the following CSS creates a diagonal gradient:
background: linear-gradient(135deg, #146c94, #80549a);
Angles provide precise control over the direction of the gradient.
Multiple colors can be added by separating additional color stops with commas.
Creating Radial Gradients
The radial-gradient() function creates a color transition that extends outward from a central point.
Radial gradients can use circular or elliptical shapes.
The following CSS creates a circular radial gradient:
background: radial-gradient(circle, #247a45, #146c94);
The gradient's position can be changed using keywords or percentage values.
For example, circle at top left positions the gradient's center near the upper-left corner.
Creating Conic Gradients
The conic-gradient() function creates color transitions that rotate around a central point.
Unlike radial gradients, which extend outward, conic gradients change color according to their angle around the center.
The following CSS creates a multicolor conic gradient:
background: conic-gradient(
#146c94,
#247a45,
#80549a,
#146c94
);
Conic gradients can be used for decorative backgrounds, circular patterns, and chart-like visualizations.
When displaying actual data, provide accessible labels and values rather than relying on gradient colors alone.
Understanding Gradient Color Stops
Color stops define the colors and positions used within a gradient.
Positions can be specified using percentages, lengths, or other supported values.
The following example creates a sharp transition between two colors:
background: linear-gradient(
to right,
#146c94 0%,
#146c94 50%,
#247a45 50%,
#247a45 100%
);
Both colors meet at the 50% position, creating a sharp boundary.
Changing the color-stop positions changes how much space each color occupies.
Creating Repeating Gradients
Repeating gradients create patterns by repeating a defined sequence of color stops.
CSS provides repeating-linear-gradient(), repeating-radial-gradient(), and repeating-conic-gradient().
The following example creates diagonal stripes:
background: repeating-linear-gradient(
45deg,
#146c94 0,
#146c94 20px,
#247a45 20px,
#247a45 40px
);
The pattern repeats every 40 pixels along the gradient line.
Repeating gradients are useful for stripes, decorative patterns, and background textures.
Creating Gradient Text Effects
Gradient text combines a background gradient with the background-clip property.
The background is clipped to the text characters, allowing the gradient colors to appear inside the letters.
The following CSS creates gradient text:
.gradient-text {
background: linear-gradient(90deg, #146c94, #80549a);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
-webkit-text-fill-color: transparent;
}
The prefixed declarations provide compatibility with browsers that require them.
Use sufficient contrast between the gradient colors and the surrounding background to maintain readability.
Creating Gradient Borders
A gradient border can be created using nested elements.
The outer element uses a gradient background and padding, while the inner element provides a solid background.
The following CSS creates a gradient border:
.gradient-border {
padding: 5px;
background: linear-gradient(135deg, #146c94, #80549a);
border-radius: 12px;
}
.gradient-border-content {
background-color: #fff;
border-radius: 8px;
}
The outer element's padding determines the visible border thickness.
This technique works well for cards, featured sections, and decorative content boxes.
Creating Animated Gradients
CSS animations can create moving gradient backgrounds by changing their position over time.
The background-size property can make the gradient larger than its container.
The background-position property then moves the visible portion of the gradient.
The following CSS creates a continuously shifting gradient:
.gradient-animated {
background: linear-gradient(
120deg,
#146c94,
#247a45,
#80549a
);
background-size: 300% 300%;
animation: gradient-shift 6s ease infinite;
}
@keyframes gradient-shift {
0%, 100% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
}
The animation continuously changes the background position to create the appearance of moving colors.
Animated gradients should be used carefully to avoid unnecessary distractions.
CSS Gradient Accessibility
Gradients should enhance the visual presentation without making text difficult to read.
Ensure that text maintains sufficient contrast against every part of its gradient background.
Do not rely on color alone to communicate important information.
For animated gradients, use the prefers-reduced-motion media query to respect visitors who prefer less movement.
The following CSS disables the animated gradient when reduced motion is requested:
@media (prefers-reduced-motion: reduce) {
.gradient-animated {
animation: none;
}
}
Interactive elements with gradient backgrounds should also provide visible keyboard focus indicators.
Customizing CSS Gradient Effects
You can customize gradients by changing their colors, directions, positions, and color stops.
Use hexadecimal colors, RGB values, HSL values, or other supported CSS color formats.
Modify gradient angles to change the direction of linear color transitions.
Adjust radial gradient shapes and positions to create different lighting effects.
Combine multiple gradients to create layered backgrounds.
Use repeating gradients to create stripes and decorative patterns.
Experiment with background-size and background-position to create animated or interactive effects.
For a consistent website design, use a coordinated color palette throughout your gradient effects.