×

CSS Filter

CSS Filter

CSS filter is used to apply visual effects on the images, text, and other factors of the webpage. This filter property in CSS allows us to admit the effects like blur or color, shifting on an element rendering, etc. before these elements get represented.

Syntax:                

The filter property’s syntax is below.

filter: none | invert() | drop-shadow() | brightness() | saturate() | blur() | hue-rotate() | contrast() | opacity() | grayscale() | sepia() | url();  

Property Values:

There are a few property values which are discussed and explained below:

invert()

It is applied to invert many samples in an input image. If we define 100% value, then it represents that it is completely inverted. If we define 0% values(default value), then it will represent the real image. It is not allowed for negative values.

Example:

<!DOCTYPE html>  
<html>        
<head>  
<title>Invert Property in CSS</title>  
<style>  
body
{ 
    text-align: center; 
} 
#img
{  
    filter: invert(40);  
}  
</style>  
</head>  
<body>  
        <img src =  "Lion.png" >
      <h2> Real Image </h2> 
 <img src =  "Lion.png" id = "img">
         <h2> invert(40) </h2>
</body> 
</html>  

Output:

drop-shadow()

This value of CSS referred to an effect, i.e., drop-shadow to the various input images. It accepts several values, which are v-shadow, h-shadow, color, blur, and spread.

Example:

<!DOCTYPE html>
<html>
<head>
<title> Drop-Shadow Property in CSS </title>
<style>
body
{
 text-align: center;
}
 .img
{
 filter: drop-shadow(10px 20px 30px lightblue);
}
</style>
</head>
<body>
 <img src= "Lion1.png"> <h2> Real Image </h2>
 <img src= "Lion1.png" class= "img"> <h2> drop-shadow(10px 20px 30px lightblue); </h2>
</body>
</html>

Output:

brightness()

The brightness() value can be used to apply the brightness on an element. When we set the 0% brightness, then it illustrates completely black, although the 100% brightness shows the real one. It also obtains values that are above 100% that give brighter results.

Example:

We will understand it with the help of the following example.

<!DOCTYPE html>
<html>
<head>
<title> Brightness Property in CSS</title>
<style>
body
{
 text-align: center;
}
.img
{
 filter: brightness(150%);
}
</style>
</head>
<body>
 <img src= "Lion1.png"> <h2> Real Image </h2>
 <img src= "Lion1.png" class= "img"> <h2> brightness(150%) </h2>
</body>
</html>

Output:

saturate()

It sets an element’s saturation. When we place 0% saturation, then it depicts a fully saturated element, although the 100% saturation illustrates the real one. The values which are higher than the 100% are permitted that give super-saturate outcomes. We can’t use any negative value in this property.

Example:

We will understand it with the help of the following example:

<!DOCTYPE html>
<html>
<head>
<title> Saturate Property in CSS</title>
<style>
body
{
 text-align: center;
}
.img
{
 filter: saturate(30);
}
</style>
</head>
<body>
 <img src= "Lion1.png"> <h2> Real Image </h2>
 <img src= "Lion1.png" class= "img"> <h2> saturate(30) </h2>
</body>
</html>

Output:

blur()

It is referred to apply a blur effect on the element. When a blur values are not described properly, then the 0 value is set as the default value. The blur() property’s parameter does not take the values in percentage. More blur can be created using its larger value.

Example:

Consider the following example:

<!DOCTYPE html>
<html>
<head>
<title> Blur Property in CSS</title>
<style>
body
{
 text-align: center;
}
.img
{
 filter: blur(3px);
}
</style>
</head>
<body>
 <img src= "Lion1.png"> <h2> Real Image </h2>
 <img src= "Lion1.png" class= "img"> <h2> blur(3px) </h2>
</body>
</html>

Output:

hue-rotate()

It uses a hue-rotation value on several input image. There are some perimeter value describes the degrees number around the circle of color; then the image will efficiently be adjusted. The 0 degree is its default value, which shows the real image. 360 degrees is its maximum value.

Example:

Consider the following example:

<!DOCTYPE html>
<html>
<head>
<title> Hue-Rotate Property in CSS</title>
<style>
body
{
 text-align: center;
}
.img
{
 filter: hue-rotate(250deg);
}
</style>
</head>
<body>
 <img src= "Lion1.png"> <h2> Real Image </h2>
 <img src= "Lion1.png" class= "img"> <h2> hue-rotate(250deg) </h2>
</body>
</html>

Output:

contrast()

It sets the contrast level of an input. When we define 0% value, it will make a fully black image, although after defining the 100% values, it will leave the contrast unchanged input that shows the real one. In this value type, it is allowed to use values which are greater than the 100% that provides outcome along with lesser contrasts.

Example:

Consider the following example:

<!DOCTYPE html>
<html>
<head>
<title> Contrast Property in CSS</title>
<style>
body
{
 text-align: center;
}
.img
{
 filter: contrast(60%);
}
</style>
</head>
<body>
 <img src= "Lion1.png"> <h2> Real Image </h2>
 <img src= "Lion1.png" class= "img"> <h2> contrast(60%) </h2>
</body>
</html>

Output:

opacity()

It is employed to set the transparency on various input image. When we define 0% value, it indicates the completely transparent image. Although when we define 100% value, it indicates the real image that is fully opaque.

Example:

Consider the following example:

<!DOCTYPE html>
<html>
<head>
<title> Opacity Property in CSS</title>
<style>
body
{
 text-align: center;
}
.img
{
 filter: opacity(50%);
}
</style>
</head>
<body>
 <img src= "Lion1.png"> <h2> Real Image </h2>
 <img src= "Lion1.png" class= "img"> <h2> opacity(50%) </h2>
</body>
</html>

Output:

grayscale()

It can convert various input image to the white and black color. When we define 0% value, it indicates the real image, although when we define 100% value, it indicates the fully grayscale image. It can transform the color of the object into 256 types of the gray.

Example:

It will more understandable by the following illustration:

<!DOCTYPE html>
<html>
<head>
<title> Grayscale Property in CSS</title>
<style>
body
{
 text-align: center;
}
.img
{
 filter: grayscale(70%);
}
</style>
</head>
<body>
 <img src= "Lion1.png"> <h2> Real Image </h2>
 <img src= "Lion1.png" class= "img"> <h2> grayscale(70%) </h2>
</body>
</html>

Output:

sepia()

It is referred to convert any image into the sepia image. When we define 0% value, it shows the real image, although when we define 100% value, it illustrates the fully sepia image.

Example:

Consider the following example:

<!DOCTYPE html>
<html>
<head>
<title> Sepia Property in CSS</title>
<style>
body
{
 text-align: center;
}
.img
{
 filter: sepia(80%);
}
</style>
</head>
<body>
 <img src= "Lion1.png"> <h2> Real Image </h2>
 <img src= "Lion1.png" class= "img"> <h2> sepia(80%) </h2>
</body>
</html>

Output:

url()

The url() function gets the XML file’s location that specifies the SVG filter, then this may add an anchor element to a particular filter element.

Example:

filter: url(svg-url#element-id) ;

← Prev Next →


Related Topics

CSS Filter

CSS Filter CSS filter is used to apply visual effects on the images, text, and other factors of the webpage. This filter property in CSS allows us to admit the effects like...

7 minutes read.

CSS Masking

CSS Masking The CSS mask property is applied to hide a component with the use of the masking or clipping an image at any specific point. The masking depicts the use...

3 minutes read.

CSS Tutorial

CSS refers to the Cascading Style Sheet. CSS is a form of a programming language. In other words, CSS is a language of the style sheet that is utilised for...

9 minutes read.

CSS Background-blend-mode

Background-blend-mode The background-blend-mode property sets a blend mode of the component’s every background layer (color/image). It illustrates how the element background image blends well with the element background color. We can...

9 minutes read.

Hover condition for a:before and a:after in CSS

In CSS, :after and :before are used to add content after and before the element. The CSS pseudo-class is used to add some styling effect to the webpage. We can change...

4 minutes read.

CSS Clip

CSS Clip The Clip property in CSS describes the element’s visible area. It applies over the elements which are absolutely positioned (position: absolute ;). Generally, it is used when an image...

2 minutes read.

CSS Color Keywords

Here, we will discuss the following keywords: transparent currentcolor Inherit Transparent keyword A color can generally be made transparent by using the transparent keyword. Often it is used to for all intents...

4 minutes read.

CSS @keyframes rule

CSS @keyframes rule It describes the rule of animation that depicts the properties of CSS for the components at every state along with the timeline. We may make the properties of complex...

4 minutes read.

CSS Units

CSS Units In CSS, there are so many units available to show the length’s measurement. A single unit of CSS is applied to examine the size of the property, which the...

5 minutes read.

CSS calc()

CSS calc(): The CSS calc() function is a CSS function of inbuilt type, which permits us to implement calculations. It is used for calculating the angle, integer frequency, number, time,...

3 minutes read.

CSS Text-decoration

CSS Text-decoration: It is an essential property of CSS that is used to decorate the content of the text. It can add-on the lines above, under, and over the text....

3 minutes read.

CSS Specificity

CSS Specificity: If one or more conflicting rules of CSS express a similar element, a browser will pursue a few rules to examine the specific one. Specificity can be specified...

3 minutes read.

Create a 3D text effect using HTML and CSS

A3D text effect is a beautiful and attractive part of a webpage. As a web page developer, it is crucial to know how to create a 3D text effect with...

3 minutes read.

CSS Display

CSS Display: The CSS Display property is one of an essential property among all other properties of CSS. The display property specifies how the HTML elements should be displayed on...

4 minutes read.

CSS Navigation bar

CSS Navigation bar: A navigation system or navigation bar comes upon GUI that can help many visitors to access the information. A Navigation bar is a UI component on the...

11 minutes read.

CSS Counters

CSS Counters: The CSS counter property is similar to the variables. CSS counters are controlled via CSS, and its values are incremented via rules of CSS to record how much...

4 minutes read.

CSS Text-stroke

Text-stroke Text-stroke CSS property inserts the stroke to any text and gives a decoration option to them also. It describes the stroke’s width and color for various text characters. It is...

2 minutes read.

CSS Float

CSS Float: The float property of CSS is the positioning property. This property is applied to elements to push them either to left or right. It permits for wrapping facility...

4 minutes read.

Css Box Model

Introduction The Box Model property of CSS is used for design and layout of an html page. In CSS, all the elements has a rectangular box around it, you have to...

5 minutes read.

CSS Opacity

The CSS Opacity property is used to set the clarity of the image. It is defined as degree and specify the transparency of an element. Note: Opacity value will be less...

1 minute read.