<filter-function>
Quick Summary for <filter-function>
The <filter-function> CSS data type represents a graphical effect that can change the appearance of an input image. It is used in the filter and backdrop-filter properties.
Code Usage for <filter-function>
<div></div> <ul>   <li>     <label for="filter-select">Choose a filter function:</label>     <select id="filter-select">       <option selected>blur</option>       <option>brightness</option>       <option>contrast</option>       <option>drop-shadow</option>       <option>grayscale</option>       <option>hue-rotate</option>       <option>invert</option>       <option>opacity</option>       <option>saturate</option>       <option>sepia</option>     </select>   </li>   <li>     <input type="range"><output></output>   </li>   <li>     <p>Current value: <code></code></p>   </li> </ul> 
More Details for <filter-function>

<filter-function>

The <filter-function> CSS data type represents a graphical effect that can change the appearance of an input image. It is used in the filter and backdrop-filter properties.

Syntax

The <filter-function> data type is specified using one of the filter functions listed below. Each function requires an argument which, if invalid, results in no filter being applied.

blur()

Blurs the image.

brightness()

Makes the image brighter or darker.

contrast()

Increases or decreases the image's contrast.

drop-shadow()

Applies a drop shadow behind the image.

grayscale()

Converts the image to grayscale.

hue-rotate()

Changes the overall hue of the image.

invert()

Inverts the colors of the image.

opacity()

Makes the image transparent.

saturate()

Super-saturates or desaturates the input image.

sepia()

Converts the image to sepia.

Examples

Filter function comparison

This example provides a simple graphic, along with a select menu to allow you to choose between the different types of filter function, and a slider to allow you to vary the values used inside the filter function. Updating the controls updates the filter effect in real time, allowing you to investigate the effects of different filters.

HTML
<div></div> <ul>   <li>     <label for="filter-select">Choose a filter function:</label>     <select id="filter-select">       <option selected>blur</option>       <option>brightness</option>       <option>contrast</option>       <option>drop-shadow</option>       <option>grayscale</option>       <option>hue-rotate</option>       <option>invert</option>       <option>opacity</option>       <option>saturate</option>       <option>sepia</option>     </select>   </li>   <li>     <input type="range"><output></output>   </li>   <li>     <p>Current value: <code></code></p>   </li> </ul> 
CSS
div {   width: 300px;   height: 300px;   background: url(https://media.prod.mdn.mozit.cloud/attachments/2020/07/29/17350/3b4892b7e820122ac6dd7678891d4507/firefox.png) no-repeat center; }  li {   display: flex;   align-items: center;   justify-content: center;   margin-bottom: 20px; }  input {   width: 60% }  output {   width: 5%;   text-align: center; }  select {   width: 40%;   margin-left: 2px; } 
JavaScript
const selectElem = document.querySelector('select'); const divElem = document.querySelector('div'); const slider = document.querySelector('input'); const output = document.querySelector('output'); const curValue = document.querySelector('p code');  selectElem.addEventListener('change', () => {   setSlider(selectElem.value);   setDiv(selectElem.value); });  slider.addEventListener('input', () => {   setDiv(selectElem.value); });  function setSlider(filter) {   if(filter === 'blur') {     slider.value = 0;     slider.min = 0;     slider.max = 30;     slider.step = 1;     slider.setAttribute('data-unit', 'px');   } else if(filter === 'brightness' || filter === 'contrast' || filter === 'saturate') {     slider.value = 1;     slider.min = 0;     slider.max = 4;     slider.step = 0.05;     slider.setAttribute('data-unit', '');   } else if(filter === 'drop-shadow') {     slider.value = 0;     slider.min = -20;     slider.max = 40;     slider.step = 1;     slider.setAttribute('data-unit', 'px');   } else if(filter === 'opacity') {     slider.value = 1;     slider.min = 0;     slider.max = 1;     slider.step = 0.01;     slider.setAttribute('data-unit', '');   } else if(filter === 'grayscale' || filter === 'invert' || filter === 'sepia') {     slider.value = 0;     slider.min = 0;     slider.max = 1;     slider.step = 0.01;     slider.setAttribute('data-unit', '');   } else if(filter === 'hue-rotate') {     slider.value = 0;     slider.min = 0;     slider.max = 360;     slider.step = 1;     slider.setAttribute('data-unit', 'deg');   } }  function setDiv(filter) {   if(filter === 'drop-shadow') {     divElem.style.filter = `${selectElem.value}(${Math.round(slider.value)}${slider.getAttribute('data-unit')} ${Math.round(slider.value)}${slider.getAttribute('data-unit')} ${Math.round(Math.abs(slider.value/2))}${slider.getAttribute('data-unit')})`;   } else {     divElem.style.filter = `${selectElem.value}(${slider.value}${slider.getAttribute('data-unit')}`;   }    updateOutput();   updateCurValue(); }  function updateOutput() {   output.textContent = slider.value; }  function updateCurValue() {   curValue.textContent = `filter: ${divElem.style.filter}`; }  setSlider(selectElem.value); setDiv(selectElem.value); 
Result

Specifications

Specification
Filter Effects Module Level 2 # typedef-filter-function

See also

Properties that use this data type: filter and backdrop-filter Select your preferred language English (US)EspañolFrançais日本語한국어Português (do Brasil)Русский中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

You could also follow me on twitter. I have a couple of youtube channels if you want to see some video related content. RuneScape 3, Minecraft and also a coding channel here Web Dev.

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote

"Olivia, my eldest daughter, caught measles when she was seven years old. As the illness took its usual course I can remember reading to her often in bed and not feeling particularly alarmed about it. Then one morning, when she was well on the road to recovery, I was sitting on her bed showing her how to fashion little animals out of coloured pipe-cleaners, and when it came to her turn to make one herself, I noticed that her fingers and her mind were not working together and she couldn’t do anything. 'Are you feeling all right?' I asked her. 'I feel all sleepy,' she said. In an hour, she was unconscious. In twelve hours she was dead. The measles had turned into a terrible thing called measles encephalitis and there was nothing the doctors could do to save her. That was...in 1962, but even now, if a child with measles happens to develop the same deadly reaction from measles as Olivia did, there would still be nothing the doctors could do to help her. On the other hand, there is today something that parents can do to make sure that this sort of tragedy does not happen to a child of theirs. They can insist that their child is immunised against measles. ...I dedicated two of my books to Olivia, the first was ‘James and the Giant Peach’. That was when she was still alive. The second was ‘The BFG’, dedicated to her memory after she had died from measles. You will see her name at the beginning of each of these books. And I know how happy she would be if only she could know that her death had helped to save a good deal of illness and death among other children."

I just checked google books for BFG, and the dedication is there. 

https://www.google.com.au/books/edition/_/quybcXrFhCIC?hl=en&gbpv=1 


Roald Dahl, 1986
Random CSS Property

text-underline-position

The text-underline-position CSS property specifies the position of the underline which is set using the text-decoration property's underline value.
text-underline-position css reference