CSS Tutorial

Gradients

Introduction:

Gradients create smooth color transitions, adding visual interest and depth to your designs.

Types of Gradients:

  • Linear Gradients: Transition colors along a straight line.
  • Radial Gradients: Transition colors in a circular pattern.

Practical Steps to Create Gradients:

Linear Gradients:
  • Use the linear-gradient() function.
  • Specify the starting and ending colors.
  • Optional: Specify the angle of the gradient.

Example:

background: linear-gradient(to right, #0099ff, #ff6600);
Radial Gradients:
  • Use the radial-gradient() function.
  • Specify the center of the gradient.
  • Specify the starting and ending colors.
  • Optional: Specify the shape of the gradient.

Example:

background: radial-gradient(circle, #0099ff 0%, #ff6600 100%);

Additional Concepts:

  • Color Stops: Specify intermediate colors to create multiple transitions.
  • Angle: Controls the direction of the linear gradient.
  • Shape: Defines the shape of the radial gradient (e.g., circle, ellipse).

Example CSS for Smooth Color Transitions:

.container {
  background: linear-gradient(to right, #ff6600 0%, #ff0000 25%, #0099ff 50%, #0000ff 75%, #66ccff 100%);
}

This code creates a smooth color transition from orange to red to blue to purple to light blue using a linear gradient.