#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
CSS3 Fundamentals

CSS3 Filters

The CSS filter property applies graphical effects such as blur, brightness changes or greyscale to an element as the browser draws it. Filters work on images, text, backgrounds and whole containers without editing the original files, which makes them handy for hover effects, disabled states and quick image adjustments.

The built-in filter functions

FunctionTypical valueEffect
blur()4pxSoftens the element; larger values blur more.
brightness()0.7 or 130%Below 1 darkens, above 1 lightens.
contrast()1.4Increases or reduces difference between light and dark.
grayscale()1Removes colour; 1 means fully grey.
sepia()0.8Adds a warm brown, old-photo tone.
saturate()2Boosts or reduces colour intensity.
hue-rotate()90degShifts every colour around the colour wheel.
invert()1Flips colours to their opposites.
opacity()0.5Makes the element see-through.
drop-shadow()0 4px 6px #0006Shadow that follows the visible shape.

Combining filters and animating them

List several functions separated by spaces. They are applied in order, left to right, and the order can change the result. Filters can also be transitioned, which gives smooth hover effects:

.gallery img {
  filter: grayscale(1) brightness(0.9);
  transition: filter 0.3s ease;
}

.gallery img:hover,
.gallery img:focus-visible {
  filter: grayscale(0) brightness(1.05);
}

.button[disabled] {
  filter: saturate(0.2) opacity(0.6);
  cursor: not-allowed;
}

.logo {
  /* shadow traces the transparent PNG outline */
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}

For a transition to animate smoothly, keep the same functions in the same order in both states, changing only their values, as the gallery example does.

drop-shadow versus box-shadow

box-shadow always draws around the element's rectangular box. filter: drop-shadow() follows the actual visible pixels, so a transparent PNG icon or an SVG gets a shadow shaped like the icon rather than a square behind it. However, drop-shadow() has no spread value and no inset option, so box-shadow remains the better choice for cards and buttons.

Blurring what is behind an element

A related property, backdrop-filter, applies the same functions to whatever sits behind an element instead of the element itself. Combined with a semi-transparent background, it creates the frosted-glass look often used on sticky headers: background: rgba(255,255,255,0.6); backdrop-filter: blur(8px);. Without a partly transparent background you will not see any effect, because the element hides what lies behind it.

Gotchas worth knowing

A filter on a parent affects every child. If you blur a card, its text blurs too, and there is no way for a child to opt out. Apply the filter to a separate background layer, such as a pseudo-element, if only the background should change.

Filters also create a new stacking context and a containing block. That means a child with position: fixed inside a filtered element is positioned relative to that element, not the viewport, which can break sticky headers or modals placed inside it. They can also flatten 3D transforms. Finally, heavy blur values on large or animated areas cost the browser more work, so test scrolling on a low-end phone.

Main points

Use filter to adjust how an element looks without editing assets, chain functions in a deliberate order, transition them for smooth hover states, and reach for drop-shadow() when the shadow must follow a shape. Keep in mind that filters affect all children and change how fixed positioning behaves inside them.

Ready to master real-world web development?

Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.

Explore Course