×

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 Browser Support

The desk underneath lists of all CSS properties and the way each belongs to it is supported in the generally unique browsers: - The quantity to the right of the browser...

2 minutes read.

How to Set Space between the Flexbox

For managing layout on the Web, CSS Flexbox and CSS Grid are two excellent tools. Flexbox handles one-dimensional layouts quite well, whereas CSS Grid manages two-dimensional layouts with columns and...

4 minutes read.

CSS Width

CSS Width The width property in CSS sets the content width of area of the element. These properties do not provide margin and border features. It is used to set the...

1 minute read.

What is CSS used for

What is CSS used for? CSS stands for Cascading Style Sheet. CSS is a stylesheet language for web pages. It specifies how a document created in a markup language looks and...

4 minutes read.

How to include CSS

How to include CSS CSS is included in HTML pages for formatting the documents based on the information inside a style sheet. We can add CSS in HTML documents in the following three ways: Inline...

5 minutes read.

CSS Reference

The CSS Reference lists all of the basic standard CSS properties, pseudo-classes, pseudo-elements, and data types, for all intents and purposes functional notations, and at-rules alphabetically.  The site also includes...

5 minutes read.

Grid Vs Flexbox in CSS

Grid: - CSS Grid Layout is a 2D grid-based matrix-based layout method with columns and rows that simplifies web pages created by eliminating the need for floats and placement. A grid layout, like...

4 minutes read.

CSS Image Gallery

Image galleries are used to display and store collections of images. Example Let’s discuss an example. CSS was used to create the following image gallery: Code is as follows: <html> <head> <style> div.gallery {   margin: 6px;   border: 1px...

5 minutes read.

CSS Pseudo-elements

Pseudo-elements The pseudo-classes in CSS can be represented as any keyword which is connected to the selector that represents any selected element’s unique state. On the other hand, pseudo-elements can be...

6 minutes read.

CSS Zoom

CSS Zoom: Zoom property in CSS extents the content. This property controls the content’s level of magnification. Rather than the use of this CSS property, we may also apply the...

3 minutes read.

CSS Dropdowns

Dropdowns are one of the maximum crucial parts of an interactive internet site. CSS is a kind used to design the drop-down menus. A drop-down essentially is a group of...

5 minutes read.

CSS Overflow

CSS Overflow: The Overflow property in CSS is used to manage the content if it overflows from its container of the block level. We have seen that all the elements...

3 minutes read.

CSS 2d Transform

Transform property in CSS is used mainly for enhancing the effects and to animate the elements. Transform is an effect that changes the shape, size and position of an element. It helps...

6 minutes read.

CSS Color

CSS Colors: The CSS color property is used for setting the HTML element’s color. The color of the fonts and the color of the background can be set-up by using...

5 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 Text Orientation

Introduction: The text-orientation property of CSS is used to specify the orientation of the text characters in the line of content. This property applies only with the vertical writing-mode and not...

4 minutes read.

CSS Pseudo-class

Pseudo-class The pseudo-class may be depicted as the keyword which can be mixed to any selector that specifies the elected element’s unique state. It can be included to a selector to...

6 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.

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 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.