Apply a CSS filter: blur() property to the element you want to change, then use transition on that same property to control the speed. Set the duration in seconds or milliseconds within the transition rule to determine how long the effect takes.
This method works for most elements like images or cards. However, it behaves differently if you are trying to blur the background behind an element rather than the element itself.
Set Up the Base Styles
You need to establish the starting state of your element before adding the movement. This ensures the browser knows what the normal view looks like before the user interacts with it.
- Create a class for your target element, such as
.blur-card. - Assign a width and height to ensure the element has space to display. A standard size is about 300 pixels wide by 200 pixels tall.
- Set the
positiontorelativeif you plan to layer content over it later. - Add a
background-colororborder-radiusto make the element visible on the page.
Define the Transition Speed
The transition property is the engine that slows down the change. Without it, the blur would appear instantly, which feels jarring to the user.
- Select the base class from the previous step.
- Add the property
transition. - Specify the property to animate. Use
filterso only the blur changes, not the position or size. - Set the duration. A calm, slow effect typically takes between 0.5s and 1.5s. For example, write
transition: filter 0.8s ease;. - Choose an easing function. The word
easestarts the motion slowly and ends it quickly. Uselinearfor a constant speed throughout the entire duration.
Apply the Blur State
Now you define what happens when the mouse enters the area of the element. This is called the :hover pseudo-class.
- Create a new selector using the base class name followed by a colon and hover:
.blur-card:hover. - Inside the curly braces, add the
filterproperty. - Set the value to
blur(5px). You can adjust the number inside the parentheses. Start with 3px for a subtle shift or 10px for a heavy blur. - Close the bracket and save your file.
Fix Common Mistakes
If the effect does not work or runs poorly, check these specific issues. Each mistake causes a distinct visual problem.
| Mistake | What It Causes | The Fix |
|---|---|---|
Transitioning transform instead of filter |
The element moves or scales, but the blur stays static. | Change the transition property to filter. |
Using display: none during transition |
The transition breaks because the element disappears instantly. | Use opacity or keep the element visible with zero opacity. |
| Blur applied to text directly | The text becomes unreadable and pixels look jagged. | Apply the blur to a container image or background, not the font. |
| Missing vendor prefixes | The effect fails on older browsers like legacy Safari. | Add -webkit-filter alongside the standard filter. |
Optimize Performance
Blurring requires the browser to recalculate every pixel on the screen. If you apply this to many elements at once, the page may lag.
- Limit the blur radius. Values above 10px require more processing power.
- Avoid blurring large background images repeatedly. Instead, blur a small overlay element.
- Use
will-change: filter;on the element to hint to the browser to prepare resources in advance.
Checklist Before You Start
- Confirm your CSS file is linked correctly in the HTML head.
- Ensure no other CSS rules are overriding your transition settings.
- Test the effect in both Chrome and Firefox to verify consistency.
- Verify that the element has a defined width and height.
Alternative: Blurring the Background
Sometimes you want to blur the content behind a modal or card, not the card itself. This requires a different approach because filter only affects the element it is attached to.
- Create a separate div for the background content.
- Apply
backdrop-filter: blur(5px)to the foreground element. - Set the foreground element to
position: absoluteorfixed. - Add
transition: backdrop-filter 0.8s ease;to the foreground class. - Note that
backdrop-filteris not supported in all browsers. Check compatibility before using it in production.
Why This Works
CSS transitions interpolate between two states. By defining a start state (no blur) and an end state (blur), the browser calculates the intermediate frames. The transition-duration tells the browser how many seconds to spend moving between those frames. A longer duration means more frames per second are spread out, creating a slower, smoother visual experience.
Debugging Your Code
If the blur appears but does not move, inspect the element in your browser developer tools. Look at the Computed tab. Verify that the transition property lists filter. If it lists all, it might be working but conflicting with other animations. If it lists nothing, the syntax is likely incorrect.
Adjusting for Touch Devices
Hover effects do not exist on touchscreens. Users tapping a button will see the hover state permanently until they tap elsewhere. To handle this, consider using a click event or JavaScript to toggle a class instead of relying solely on :hover.
Refining the Easing
The default ease curve is good, but you can customize it further. Use cubic-bezier(0.4, 0, 0.2, 1) for a standard material design feel. Use ease-out if you want the animation to finish quickly after starting slowly. Experiment with these values to match the mood of your site.
Related
- Slow Down to Go Faster: What It Means and How to Use It
- Intentional Nature Walks: How to Do Them
- How to Enjoy the Holidays Without Stress
General information for everyday wellbeing, not medical advice. If something affects your health, sleep or mood for more than a short while, talk to a qualified professional. Read more
Spotted an error? Tell us and we will correct it (corrections policy).