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

CSS Filter Blur


The CSS filter property applies graphical effects like blur or color shifting to an element. The blur() function specifically creates a fog-like or out-of-focus effect on the element's content. The amount of blur is determined by a radius value; a larger value will create more blur.


Example 1: Basic Image Blur

.blur-image {
  /* Applies a 5-pixel blur to the image */
  filter: blur(5px);
}

Explanation: This code selects an element with the class .blur-image and applies a 5px blur. The px unit specifies the blur radius, which dictates how much the pixels blend into each other.


Example 2: Text Blur

.blur-text {
  color: transparent;
  /* Applies a 2-pixel blur to the text shadow, making the text appear blurred */
  text-shadow: 0 0 2px rgba(0,0,0,0.7);
  filter: blur(1px); /* Adds an additional layer of blur */
}

Explanation: This example makes the text itself transparent and then applies a blurred text-shadow to create a blur effect. An additional filter: blur(1px) is added to enhance the haziness of the text.


Example 3: Hover Effect Blur

.blur-on-hover {
  transition: filter 0.3s ease-in-out; /* Smooth transition for the filter property */
}

.blur-on-hover:hover {
  /* Blurs the element when the mouse hovers over it */
  filter: blur(4px);
}

Explanation: This demonstrates a common interactive effect. Initially, the element is clear. When a user hovers their mouse over it, a 4px blur is smoothly applied over 0.3 seconds due to the transition property.


Example 4: Blurring a Background Image

.background-blur-container {
  position: relative;
  width: 100%;
  height: 300px;
  overflow: hidden; /* Ensures the blurred pseudo-element doesn't spill out */
}

.background-blur-container::before {
  content: '';
  position: absolute;
  top: -10px; right: -10px; bottom: -10px; left: -10px; /* Extends pseudo-element to avoid hard edges */
  background: url('your-image.jpg') center/cover;
  /* Applies an 8-pixel blur to the background pseudo-element */
  filter: blur(8px);
  z-index: -1; /* Places the blurred background behind the content */
}

Explanation: This code uses a pseudo-element (::before) to create a blurred background for a container. This allows you to have sharp, readable content on top of a soft, out-of-focus background image.


Example 5: Animating Blur Effect

.animated-blur {
  animation: pulse-blur 4s infinite alternate; /* Applies the animation */
}

@keyframes pulse-blur {
  from {
    /* Starts with no blur */
    filter: blur(0px);
  }
  to {
    /* Ends with a 10-pixel blur */
    filter: blur(10px);
  }
}

Explanation: This example uses @keyframes to create an animation named pulse-blur. The element with the class .animated-blur will cycle between being sharp (blur(0px)) and heavily blurred (blur(10px)) over a 4-second duration, infinitely.


Example 6: Using rem units for Blur

.rem-unit-blur {
  /* Applies a blur radius based on the root element's font-size */
  filter: blur(0.25rem);
}

Explanation: Here, rem units are used for the blur radius. This makes the blur effect responsive to changes in the root font-size, allowing for better scalability and accessibility in your designs.


Example 7: Blurring an Entire Section

.section-to-blur {
  /* Applies a 6-pixel blur to all content within this section */
  filter: blur(6px);
  /* Ensures the blurred content does not affect layout of other elements */
  user-select: none;
  pointer-events: none;
}

Explanation: This applies a blur to an entire container, affecting all child elements including text, images, and buttons. The user-select and pointer-events properties are added to prevent interaction with the now-unreadable content.