Onze vrijwilligers hebben dit artikel nog niet naar het Nederlands vertaald. Doe mee en help de klus te klaren!
U kunt het artikel ook in het English (US) lezen.

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The CanvasRenderingContext2D.filter property of the Canvas 2D API provides filter effects like blurring or gray-scaling. It is similar to the CSS filter property and accepts the same functions.


ctx.filter = "<filter-function1> [<filter-function2] [<filter-functionN]";
ctx.filter = "none";

Filter functions

The filter property accepts one or more of the following filter functions in a DOMString.

The url() function takes an IRI pointing to an SVG filter element which may be embedded in an external XML file.
CSS length. Applies a Gaussian blur to the drawing.
Percentage. Applies a linear multiplier to the drawing, making it appear more or less bright.
Percentage. Adjusts the contrast of the drawing. A value of 0% will create a drawing that is completely black. A value of 100% leaves the drawing unchanged.
drop-shadow(<offset-x> <offset-y> <blur-radius> <color>)
Applies a drop shadow effect to the drawing. A drop shadow is effectively a blurred, offset version of the drawing's alpha mask drawn in a particular color, composited below the drawing. This function takes up to five arguments:
  • <offset-x>: See <length> for possible units. Specifies the horizontal distance of the shadow.
  • <offset-y>: See <length> for possible units. Specifies the vertical distance of the shadow.
  • <blur-radius>: The larger this value, the bigger the blur, so the shadow becomes bigger and lighter. Negative values are not allowed.
  • <color>: See <color> values for possible keywords and notations.
Percentage. Converts the drawing to a gray-scale picture. A value of 100% is completely gray-scale. A value of 0% leaves the drawing unchanged.
Degree. Applies a hue rotation on the drawing. A value of 0deg leaves the input unchanged.
Percentage. Inverts the drawing. A value of 100% means complete inversion. A value of 0% leaves the drawing unchanged.
Percentage. Applies transparency to the drawing. A value of 0% means completely transparent. A value of 100% leaves the drawing unchanged.
Saturates the drawing. A value of 0% means completely un-saturated. A value of 100% leaves the drawing unchanged.
Converts the drawing to sepia. A value of 100% means completely sepia. A value of 0% leaves the drawing unchanged.
No filter is applied. Initial value.


Using the filter property

This is just a simple code snippet using the filter property.


<canvas id="canvas"></canvas>


var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');

ctx.filter = 'blur(5px)';
ctx.font = '48px serif';
ctx.strokeText('Hello world', 50, 100);

Edit the code below and see your changes update live in the canvas (and make sure to use a browser which supports this feature, see the compatibility table):


Specification Status Comment
HTML Living Standard
The definition of 'CanvasRenderingContext2D.filter' in that specification.
Living Standard Initial definition.

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support52 ?


35 — 481

No No No
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support5252 ?


35 — 481

No No6.0

1. From version 35 until version 48 (exclusive): this feature is behind the canvas.filters.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

See also

Documentlabels en -medewerkers

Aan deze pagina hebben bijgedragen: fscholz, Kaiido, nmve, jpmedley, Sebastianz, Prinz_Rana, stuart, MarkusStange
Laatst bijgewerkt door: fscholz,