
The filter property adjusts an element’s rendered appearance. It can affect a whole container and all its painted contents, or be applied to a single image so labels and controls remain unchanged.
1. Filter syntax and order
List functions separated by spaces. They are applied in that order. Use none to remove all filters. A filter on a parent applies to the rendered group, including child content.
.preview img { filter: grayscale(.4) contrast(1.15); }2. Common filter functions
Use blur for softness; brightness and contrast for tonal changes; grayscale, sepia, saturate, invert, and hue-rotate for color effects; opacity for transparency; and drop-shadow for a shadow based on the visible shape.
3. Filter a container
Apply a filter directly to a container only when its text, border, or descendants should change too. Check the resulting contrast. Filter and backdrop-filter act on different rendered material.
4. Filter an image
Target the image alone for a photographic effect. A drop shadow on a transparent image can follow its silhouette, while a box shadow follows the element’s box.
.product img { filter: drop-shadow(0 3px 6px rgb(0 0 0 / 28%)); }5. Practice
Try grayscale and contrast in both orders. Apply the result first to the image and then to its container. Compare the effect on the caption and test whether the original image stays recognizable.