Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

brightness() — filter brightness multiplier

`brightness()` is a filter function that multiplies the input image’s color components, making it darker or brighter without changing its layout-box size.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

brightness( [ <number> | <percentage> ]? )

brightness() is a filter function that multiplies the input image’s color components, making it darker or brighter without changing its layout-box size.

The example sets filter: brightness(150%). Its computed value is brightness(1.5), and the pixel rgb(40 80 120) becomes 60,120,180. A separate brightness(0) pass yields black 0,0,0, proving a pixel effect rather than parser acceptance.

Grammar: brightness( [ <number> | <percentage> ]? ).

The argument can be a <number> or <percentage>: 1 and 100% leave the image unchanged, 0 produces black, and values above 1 brighten with no upper bound. Negative values are forbidden. An omitted argument uses 1; when filter lists interpolate, a missing matching function also uses the initial interpolation value 1.

Examples

const swatch=document.createElement('div');document.body.append(swatch);swatch.style.filter='brightness(150%)';const computed=getComputedStyle(swatch).filter;const source=document.createElement('canvas'),lit=document.createElement('canvas'),dark=document.createElement('canvas');for(const canvas of [source,lit,dark]){canvas.width=canvas.height=1}const sourceContext=source.getContext('2d');sourceContext.fillStyle='rgb(40 80 120)';sourceContext.fillRect(0,0,1,1);const litContext=lit.getContext('2d');litContext.filter=computed;litContext.drawImage(source,0,0);const darkContext=dark.getContext('2d');darkContext.filter='brightness(0)';darkContext.drawImage(source,0,0);const pixel=[...litContext.getImageData(0,0,1,1).data].slice(0,3),zero=[...darkContext.getImageData(0,0,1,1).data].slice(0,3);if(computed!=='brightness(1.5)'||pixel.join(',')!=='60,120,180'||zero.join(',')!=='0,0,0')throw new Error('brightness evidence mismatch: '+[computed,pixel,zero]);console.log('computed='+computed+'; pixel='+pixel.join(',')+'; zero='+zero.join(','));

Result

computed=brightness(1.5); pixel=60,120,180; zero=0,0,0

`brightness()` is a filter function that multiplies the input image’s color components, making it darker or brighter without changing its layout-box size.

Sources