CSS Filters
Chapter: 72
CSS Filters
CSS Filters
The CSS filter property lets you apply graphical effects like blurring or color shifting to an element.
Filters are commonly used to adjust the rendering of images, backgrounds, and borders.
Image filtering is useful when you want to have different styling for the same image.
Instead of uploading multiple images to the website, you can upload only one image and then define visual effects using the filter property.
Filter functions include blur(), brightness(), contrast(), drop-shadow(), grayscale(), hue-rotate(), invert(), opacity(), saturate() and sepia().
Tap Continue to explore the filters and see them in action!
CSS Filters
Which of the following is not a filter function?
The drop-shadow Function
drop-shadow(w h b c) creates a shadow effect that extends beyond an image for the width w and height h with blur b and color c.
w, h, and b are values in pixels.
For example:
filter: drop-shadow(5px 9px 2px blue);
}
Positive values create the shadow to the right and below the image.
Negative width and height values create the shadow above and to the left of the image.
The drop-shadow Function
Fill in the blanks to create a red shadow.
Chapter: 73
Filter Functions
The grayscale Function
The grayscale function converts an image to grayscale.
The only parameter defines the proportion of the conversion.
0% grayscale is the original image, whereas 100% makes the image completely grayscale.
Here is an example using a percentage value to make an image completely grayscale:
filter: grayscale(100%);
}
The grayscale Function
Fill in the blanks to apply the grayscale function.
The sepia Function
The sepia function converts an image to sepia.
This is similar to using grayscale but with a reddish-brown color tone.
The idea behind sepia filters is that they can make black and white photos look a bit more eye-catching than the basic grayscale version.
0% sepia is the original image, whereas 100% converts the image to sepia completely:
filter: sepia(100%);
}
The sepia Function
Fill in the blanks to create a valid sepia function.
The saturate Function
The saturate function controls the color saturation for an image. The only parameter determines the proportion of the saturation that is applied to the image.
The parameter can be either a percentage value or a number.
0% creates a completely unsaturated image (grayscale), whereas 100% is the original image.
filter: saturate(50%);
}
Here is an example using a number value to make an image super-saturated
filter: saturate(2.5);
}
The hue-rotate Function
The hue-rotate function applies a hue rotation (based on the color circle) to an image.
The function takes an angle of rotation as its parameter. The value of angle defines the number of degrees around the color circle the input samples will be adjusted.
If the image contains red color, which is at 0 degrees on the color circle, rotating the hue by 240deg will make the red color blue.
Here is an example of a hue rotation:
filter: hue-rotate(180deg);
}
The hue-rotate Function
Rotating the hue by 120deg will make the red color in an image:
The invert Function
The invert function inverts the colors of an image to make dark areas bright and bright areas dark.
The function takes the proportion of the conversion as its parameter.
The parameter can be either a percentage value or a number.
0%invert leaves the image unchanged, whereas 100% creates a completely inverted image that is similar to a photographic negative.
Here is an example using a percentage value to make the image partially inverted:
filter: invert(70%);
}
Chapter: 74
Opacity and Brightness
The opacity Function
The opacity function sets the opacity of an image to change its transparency.
0% opacity creates a completely transparent image, whereas 100% is the original image.
For example:
filter: opacity(70%);
}
The brightness Function
The brightness(amount) function adjusts the brightness of an image, making it appear brighter or darker.
The amount parameter determines the brightness level of the image. The parameter can take either a percentage value or a number.
A value of 0% results in an image that is completely black.
A value of 100% results in an image that is unchanged.
Any amount over 100% produces a brighter image.
Here is an example using a percentage value to make the image darker:
filter: brightness(50%);
}
A number value of 0.5 has the same effect as the percentage value of 50%. A value of 1 is the same as 100%.
Here is an example using a number value to make the image brighter:
filter: brightness(1.9);
}
The brightness Function
Fill in the blanks to make an image brighter and circled.
The contrast Function
The contrast function adjusts the contrast of the image.
The amount parameter can take either a percentage value or a number.
A value under100%decreases the contrast, while a value over 100% increases it.
A value of 0% will create an image that is completely gray, while a value of 100% leaves the image unchanged.
The value 0.5 corresponds to 50%, while 1 is the same as 100%.
Here is an example using a percentage value to give the image more contrast:
filter: contrast(140%);
}
The contrast Function
Fill in the blanks to make an image completely gray.
The blur Function
The blur function applies a blur effect to an image.
The blur function has only one parameter, radius, which defines how many pixels on the screen blend into each other. (a larger value creates more blur).
For example:
filter: blur(5px);
}
If no parameter is provided, then the default value 0 is used, which leaves the image unchanged.
For example:
/* Both have no effect on the picture*/
blur(); /* If no parameter is provided, then a value 0 is used.*/
blur(0); /* A value of 0 leaves the input unchanged.*/
}
The blur Function
Fill in the blanks to apply a blur effect.
Chapter: 75
Using Multiple CSS Filters
Using Multiple CSS Filters
Multiple CSS filters can be used together by separating them with spaces.
The following code demonstrates the use of the blur and the hue-rotate functions:
filter: blur(5px) hue-rotate(180deg);
}
Another Example:
filter: saturate(30%) drop-shadow(5px 9px 2px gray) blur(1px);
}
Another example from the 19th century:
filter: brightness(150%) sepia(100%);
}






Comments
Post a Comment