CSS

CSS Overview Selectors Declarations Rule Sets Comments Reset/Normalize Origin Importance Order Specificity Inheritance Cascade Layers Inline Styles Internal Styles External Styles @import Absolute Units Relative Units Dynamic Viewport Angle Units Time Units Frequency Units: Resolution Units Keywords Color Formats Color Functions & Spaces Background Color Background Image Background Repeat Background Position Background Size Background Attachment Background Shorthand Multiple Backgrounds Linear Gradients Radial Gradients Conic Gradients Font Family Font Size Font Weight Font Style Line Height Text Align Text Decoration Text Transform Letter Spacing Word Spacing Text Shadow Text Wrap Variable Fonts Content Box Padding Box Border Box Margin Box Box Sizing Property Margin Padding Border Outline Box Shadow Block Display Inline Display Inline Block Display Static Position Relative Position Absolute Position Fixed Position Sticky Position Top Element Position Right Element Position Bottom Element Position Left Element Position Z Index Flexbox Box Layout Display Flex Flex Direction Flex Wrap Justify Content Align Items Align Content Gap, Row Gap & Column Gap Flex Grow Flex Shrink Flex Basis Flex Shorthand Order Property Align Self Practical Applications CSS Grid Layout Grid Display Grid Template Columns Grid Template Rows Grid Template Areas Justify Items Grid Auto Columns Justify Self Nested Grids Responsive Web Design Min Width Max Width Orientation Logical Operators Pointer Hover Prefers Color Scheme Fluid Images Flexible Typography Viewport Width Advanced CSS Features Defining variables Using variables Scope & Inheritance of CSS Variables Property Value Fallback Practical Applications :Hover :Active :Focus :Focus Visible :Visited :Link :First Child :Last Child :Nth Child :Nth of Type :Empty :Checked :Disabled :Enabled :Valid :Invalid :Required :Has :Not :Is :Where ::Before Pseudo Element ::After Pseudo Element ::First Letter ::First Line ::Selection ::Marker CSS 2D Transformations CSS 3D Transformations Transform Origin Transform Style Backface Visibility Transition Property Transition Duration Transition Timing Function Transition Delay Transition Shorthand Ease Timing Function Linear Timing Function Ease In Timing Function Ease Out Timing Function Ease In Out Timing Function Cubic Bezier Function Animations (@keyframes) Defining @keyframes Animation Name CSS Animation Duration Animation Timing Function CSS Animation Delay CSS Animation Iteration Count Animations Direction CSS Animation Fill Mode CSS Animation Play State CSS Filter Blur CSS Filter Brightness CSS Filter Contrast() CSS Drop Shadow CSS Grayscale CSS Hue Rotate CSS Invert CSS Opacity CSS Saturate CSS Sepia Mix Blend Mode Background Blend Mode Object Fit & Object Position Scroll Snap Type Scroll Snap Align Scroll Padding Scroll Margin Scroll Triggered Animations JS Variables

Radial Gradients


The CSS radial-gradient() function creates an image consisting of a progressive transition between two or more colors that radiate from an origin. Its shape can be a circle or an ellipse. This function is a powerful tool for creating depth, focus, and visually interesting backgrounds without the need for image files.


Example 1: Basic Circular Radial Gradient

.gradient-1 {
  /* Creates a simple circular gradient */
  /* from yellow in the center to red at the edges */
  background: radial-gradient(circle, yellow, red);
  height: 200px;
  width: 200px;
}

Explanation

This code generates a circular gradient that transitions from yellow at its center to red at its edges. The circle keyword dictates the shape of the gradient.


Example 2: Elliptical Radial Gradient

.gradient-2 {
  /* Creates a simple elliptical gradient */
  /* from a light blue to a dark blue */
  background: radial-gradient(ellipse, #87CEEB, #00008B);
  height: 200px;
  width: 300px; /* Wider than its height to show the ellipse */
}

Explanation

Here, an elliptical gradient is created, which is the default shape if not specified. The gradient smoothly transitions from a light sky blue to a dark blue, conforming to the dimensions of the element.


Example 3: Setting the Gradient Center

.gradient-3 {
  /* Positions the gradient's center at the top left */
  /* 'at 0% 0%' places the center at the top-left corner */
  background: radial-gradient(circle at 0% 0%, white, green);
  height: 200px;
  width: 200px;
}

Explanation

This example demonstrates how to control the origin of the gradient. By using at 0% 0%, the gradient's center is moved to the top-left corner of the element.


Example 4: Defining Color Stop Positions

.gradient-4 {
  /* Defines specific positions for color stops */
  /* Red starts at 5%, yellow at 15%, and green at 60% */
  background: radial-gradient(red 5%, yellow 15%, green 60%);
  height: 200px;
  width: 200px;
}

Explanation

This code shows how to set precise positions for each color in the gradient. The color red will extend to the 5% mark, yellow to 15%, and green will fill the rest of the space up to the 60% mark.


Example 5: Using Sizing Keywords (farthest-corner)

.gradient-5 {
  /* The gradient's size is determined by the farthest corner */
  /* This is the default sizing behavior */
  background: radial-gradient(farthest-corner at 40% 40%, teal, black);
  height: 200px;
  width: 200px;
}

Explanation

The farthest-corner keyword sets the size of the gradient to be large enough to reach the corner of the element that is farthest from its center. In this case, the gradient extends from the 40% 40% position to the bottom-right corner.


Example 6: Using Sizing Keywords (closest-side)

.gradient-6 {
  /* The gradient's size extends to the closest side from its center */
  background: radial-gradient(closest-side at 30% 50%, orange, purple);
  height: 200px;
  width: 200px;
}

Explanation

This example uses closest-side, which sizes the gradient to meet the side of the container closest to its center. This often results in a smaller, more contained gradient effect.


Example 7: Repeating Radial Gradient

.gradient-7 {
  /* Creates a repeating pattern of concentric circles */
  /* A blue circle from 10px to 20px, then a red circle to 30px, repeating */
  background: repeating-radial-gradient(circle, blue 10px, red 20px, blue 30px);
  height: 200px;
  width: 200px;
}

Explanation

The repeating-radial-gradient() function is used to create a pattern of repeating concentric shapes. This code produces a series of blue and red rings that emanate from the center of the element.