Linear Gradients in Action: Free HTML/CSS Examples

Laura Sep 01, 2026
Gradiente Pastel Suave — Fundo Perfeito para Design
Gradiente Pastel Suave — Fundo Perfeito para Design

Linear gradients are a powerful tool in web design, offering a wide range of possibilities for adding visual interest and depth to your user interfaces. They allow you to create smooth, continuous transitions between colors, which can be manipulated to create various effects, from subtle to dramatic.

Gradiente Pastel Suave — Fundo Perfeito para Design
Gradiente Pastel Suave — Fundo Perfeito para Design

In this article, we'll explore linear gradient examples, delve into their syntax, and demonstrate how to use them in various design scenarios. By the end, you'll have a solid understanding of linear gradients and be equipped to leverage them in your projects.

a blue and green background with vertical lines
a blue and green background with vertical lines

Understanding Linear Gradients

Before we dive into examples, let's ensure we're on the same page regarding what linear gradients are and how they work. Linear gradients are a way to transition between two or more colors linearly, along a straight line.

Vertical Linear PNG Transparent, Gradients Vertical Linear, Gradients, Color Gradient, Line Gradient PNG Image For Free Download
Vertical Linear PNG Transparent, Gradients Vertical Linear, Gradients, Color Gradient, Line Gradient PNG Image For Free Download

They are defined using the linear-gradient() function, which takes two required arguments: the direction and the stops. The direction determines the angle of the gradient, while the stops define the color transitions.

Syntax Basics

an orange and blue background with red lines in the bottom right corner that are parallel to each other
an orange and blue background with red lines in the bottom right corner that are parallel to each other

Here's the basic syntax of the linear-gradient() function:

background-image: linear-gradient(direction, color-stop1, color-stop2, ...);

The direction argument can be a specific angle (e.g., 45deg) or one of the predefined keywords (to top, to bottom, to left, to right). Color stops are specified as color names, RGB values, or hex codes.

an abstract background with many circles in pink, blue and orange colors on top of each other
an abstract background with many circles in pink, blue and orange colors on top of each other

Basic Linear Gradient Examples

Let's look at some basic linear gradient examples.

  • Horizontal gradient:

Linear Gradient Art | Sunset Neon Aesthetic
Linear Gradient Art | Sunset Neon Aesthetic

background-image: linear-gradient(to right, red, yellow);
  • Vertical gradient:

  • background-image: linear-gradient(to bottom, blue, green);
  • Diagonal gradient:

  • an orange and blue abstract background with the letter o in it's middle corner
    an orange and blue abstract background with the letter o in it's middle corner
    an image of a rainbow colored background
    an image of a rainbow colored background
    a book cover with an image of colorful lines
    a book cover with an image of colorful lines
    the top 10 fancy gradients for design
    the top 10 fancy gradients for design
    an image of two different colored lines in the same color scheme, one is blue and orange
    an image of two different colored lines in the same color scheme, one is blue and orange
    Deep Layers Volume 1
    Deep Layers Volume 1
    Grainy Gradients | @ellostudio.co
    Grainy Gradients | @ellostudio.co
    Design
    Design
    abstract gradient background
    abstract gradient background

    background-image: linear-gradient(45deg, purple, orange);

    Advanced Linear Gradient Techniques

    Now that we've covered the basics, let's explore some advanced linear gradient techniques.

    Multiple Color Stops

    You can create more complex gradients by using multiple color stops:

    background-image: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet);

    This creates a rainbow-like effect, transitioning smoothly through seven colors.

    Positions and Sizes

    You can also set the position and size of the gradient using percentages:

    background-image: linear-gradient(to right, red 20%, orange 40%, yellow 60%, green 80%);

    In this example, each color covers 20% of the gradient's width.

    Linear Gradients in Web Design

    Now that we've seen various linear gradient examples, let's discuss how they can be used in web design.

    Backgrounds

    Linear gradients are commonly used as backgrounds for elements, providing a solid foundation for the content they hold:

    background-image: linear-gradient(to bottom, #642C70 0%, #000000 100%);

    Buttons

    Gradients can be used to create engaging buttons that catch the user's attention:

    background-image: linear-gradient(to right, #FF12FF, #DA00FF);

    Remember, linear gradients should enhance the user experience and not detract from it. Use them strategically and in moderation to create visually appealing designs that are still accessible and functional.

    That's a wrap on linear gradient examples! Practice these techniques, and you'll soon be creating stunning gradients that add depth and visual interest to your web designs. Happy designing!