AmbientLightSensor: illuminance property

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

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

The illuminance read-only property of the AmbientLightSensor interface returns the current light level in lux of the ambient light level around the hosting device.

Value

A Number indicating the current light level in lux.

Examples

js
if ("AmbientLightSensor" in window) {
  const sensor = new AmbientLightSensor();
  sensor.addEventListener("reading", (event) => {
    console.log("Current light level:", sensor.illuminance);
  });
  sensor.addEventListener("error", (event) => {
    console.log(event.error.name, event.error.message);
  });
  sensor.start();
}

Specifications

Specification
Ambient Light Sensor
# ambient-light-sensor-reading-attribute

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
illuminance
Experimental
Chrome – No support
Chrome 56 (Release date: 2017-01-25)
footnote , disabled
disabled From version 56 users must explicitly set the #enable-experimental-web-platform-features preference to Enabled. To change preferences in Chrome, visit chrome://flags.
footnote In Chrome 79, this method stopped returning floats and returned integers to avoid fingerprinting.
Chrome – No support
Chrome 67 (Release date: 2018-05-29)
footnote , disabled
disabled From version 67 users must explicitly set the #enable-generic-sensor-extra-classes preference to Enabled. To change preferences in Chrome, visit chrome://flags.
footnote In Chrome 79, this method stopped returning floats and returned integers to avoid fingerprinting.
Edge – No support
Edge 79 (Release date: 2020-01-15)
footnote , disabled
disabled From version 79 users must explicitly set the #enable-experimental-web-platform-features preference to Enabled. To change preferences in Edge, visit about:flags.
footnote In Edge 79, this method stopped returning floats and returned integers to avoid fingerprinting.
Edge – No support
Edge 79 (Release date: 2020-01-15)
footnote , disabled
disabled From version 79 users must explicitly set the #enable-generic-sensor-extra-classes preference to Enabled. To change preferences in Edge, visit about:flags.
footnote In Edge 79, this method stopped returning floats and returned integers to avoid fingerprinting.
Firefox – No support
Firefox
footnote No support
Opera – No support
Opera 43 (Release date: 2017-02-07)
footnote , disabled
disabled From version 43 users must explicitly set the #enable-experimental-web-platform-features preference to Enabled. To change preferences in Opera, visit opera://flags.
footnote In Opera 66, this method stopped returning floats and returned integers to avoid fingerprinting.
Opera – No support
Opera 54 (Release date: 2018-06-28)
footnote , disabled
disabled From version 54 users must explicitly set the #enable-generic-sensor-extra-classes preference to Enabled. To change preferences in Opera, visit opera://flags.
footnote In Opera 66, this method stopped returning floats and returned integers to avoid fingerprinting.
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android 56 (Release date: 2017-02-01)
footnote , disabled
disabled From version 56 users must explicitly set the #enable-experimental-web-platform-features preference to Enabled. To change preferences in Chrome Android, visit chrome://flags.
footnote In Chrome Android 79, this method stopped returning floats and returned integers to avoid fingerprinting.
Chrome Android – No support
Chrome Android 67 (Release date: 2018-05-31)
footnote , disabled
disabled From version 67 users must explicitly set the #enable-generic-sensor-extra-classes preference to Enabled. To change preferences in Chrome Android, visit chrome://flags.
footnote In Chrome Android 79, this method stopped returning floats and returned integers to avoid fingerprinting.
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.
User must explicitly enable this feature.
Has more compatibility info.