HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
  • Insights
  • Verify Certificate
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials

HTML5andCSS3.org helps developers learn modern frontend skills with practical tutorials, production-ready snippets, and fast web tools built for everyday coding.

Quick Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Copyright
  • Disclaimer

Top Tools

  • Try It Editor
  • JSON Formatter
  • CSS Minifier
  • HTML Minifier
  • Base64 Encoder / Decoder

Contact

  • business@html5andcss3.org
Newsletter

Learn at your own pace, practice with useful tools, and build websites you're proud of.

© 2011-2026 html5andcss3.org. All rights reserved.

How to Use

CSS Tutorial

CSS Introduction

What is CSSCSS SyntaxHow to Add CSSCSS Comments

CSS Foundations

Cascade & InheritanceCSS SpecificityCSS UnitsBox SizingCSS VariablesCSS Math Functions

CSS Selectors

CSS Element SelectorCSS Class SelectorCSS ID SelectorCSS Universal SelectorCSS Group SelectorCSS CombinatorsCSS Attribute SelectorsCSS Pseudo ClassesCSS Pseudo Elements

CSS Colors and Backgrounds

CSS ColorsCSS HEX ColorsCSS RGB ColorsModern ColorsCSS Background ColorCSS Background ImageLayered Backgrounds

CSS Text & Fonts

CSS Text ColorCSS Text AlignmentCSS Text DecorationCSS Font FamilyCSS Font SizeWeb Fonts & TypographyText Wrapping

CSS Box Model

CSS MarginCSS PaddingCSS BorderCSS OutlineCSS Width and Height

CSS Layout

Normal FlowCSS DisplayCSS PositionAnchor PositioningCSS FloatCSS OverflowCSS Z-indexIntrinsic SizingAspect Ratio & Object FitMulti-column Layout

CSS Flexbox

Flex ContainerFlex DirectionJustify ContentAlign ItemsFlex WrapFlex Item Sizing

CSS Grid

CSS Grid ContainerCSS Grid ColumnsCSS Grid RowsCSS Grid GapCSS Grid Layout ExampleGrid PlacementGrid AreasCSS Subgrid

CSS Lists, Tables & Forms

CSS ListsCSS TablesCSS Form StylingCSS Input Fields

CSS Effects

CSS ShadowsCSS GradientsCSS FiltersCSS OpacityClipping & MaskingBlending & BackdropScroll Snap

CSS Animations & Transitions

CSS TransformCSS 2D TransformCSS 3D TransformCSS TransitionsEntry & Exit TransitionsCSS AnimationsScroll AnimationsView TransitionsMotion Paths

CSS Responsive Design

CSS Media QueriesResponsive LayoutMobile First DesignContainer QueriesPreference Media QueriesFeature Queries

Modern CSS Authoring

Cascade LayersNesting & ScopeLogical PropertiesGenerated Content

CSS Accessibility

Accessible CSSCSS ThemingModern Form StylingCSS User Interface

CSS Output & Performance

Print StylesCSS PerformanceCSS ArchitectureDebugging CSS

CSS Reference

CSS At-rulesCSS FunctionsCSS Tutorial PDF

CSS Projects

Responsive CSS Project
  1. Home
  2. /
  3. Tutorials
  4. /
  5. CSS Tutorial
  6. /
  7. CSS Gradients

CSS Effects

CSS Gradients

CSS Gradients are used to create smooth transitions between two or more colors without using images.

Gradients are commonly used for:

  • Website backgrounds
  • Buttons
  • Cards
  • Hero sections
  • Modern UI designs

Because gradients are generated by CSS, they load faster than image-based backgrounds and scale perfectly on all screen sizes. The supporting concepts are explained in CSS Colors and Modern Colors.

CSS provides two main gradient types:

  • Linear Gradient
  • Radial Gradient

Syntax

Linear Gradient

Linear Gradient Syntax

css

selector {
    background: linear-gradient(color1, color2);
}

Linear Gradient Example

css

div {
    background: linear-gradient(red, blue);
}

Creates a gradient from red to blue.

Radial Gradient

Radial Gradient Syntax

css

selector {
    background: radial-gradient(color1, color2);
}

Radial Gradient Example

css

div {
    background: radial-gradient(yellow, orange);
}

Creates a circular gradient effect.

Attributes

FunctionDescriptionExample
linear-gradient()Creates a linear color transitionlinear-gradient(red, blue)
radial-gradient()Creates a circular gradientradial-gradient(yellow, orange)
repeating-linear-gradient()Repeats a linear gradientrepeating-linear-gradient(red, blue 20px)
repeating-radial-gradient()Repeats a radial gradientrepeating-radial-gradient(red, blue 20px)
color stopsDefines transition pointsred 20%, blue 80%

Example

CSS Gradients Complete Example

html

<!DOCTYPE html>
<html>
<head>
    <title>CSS Gradients Example</title>
    <style>
        .linear-box {
            width: 300px;
            height: 150px;
            background: linear-gradient(to right, #007acc, #00c6ff);
            margin-bottom: 20px;
        }
        .radial-box {
            width: 300px;
            height: 150px;
            background: radial-gradient(circle, yellow, orange);
        }
    </style>
</head>
<body>
    <div class="linear-box"></div>
    <div class="radial-box"></div>
</body>
</html>

Browser Support

Feature
Chrome
Edge
Firefox
Safari
linear-gradient()2612167

Versions show the first stable desktop release with unprefixed support. Data source: MDN Browser Compatibility Data 8.0.8.

Notes

  • Gradients are commonly used as background images.
  • Multiple colors can be added to a gradient.
  • Gradients reduce the need for image files.
  • Direction can be specified using to right, to left, to top, to bottom, and angle values such as 45deg.

Three-Color Gradient

Three-Color Gradient

css

background: linear-gradient(
    red,
    yellow,
    blue
);

Directional Gradient

Directional Gradient

css

background: linear-gradient(
    to right,
    purple,
    pink
);

Angle-Based Gradient

Angle-Based Gradient

css

background: linear-gradient(
    45deg,
    #007acc,
    #00ffcc
);

Radial Gradient

Radial Gradient

css

background: radial-gradient(
    circle,
    white,
    blue
);

Conclusion

CSS Gradients provide a powerful way to create modern, colorful, and visually appealing backgrounds without using images. By combining colors, directions, and gradient types, you can design professional interfaces that are lightweight, responsive, and easy to maintain.

PreviousCSS ShadowsNextCSS Filters