Back to Content

AmbientLightSensor: illuminance property

files/en-us/web/api/ambientlightsensor/illuminance/index.md

latest795 B
Original Source

{{securecontext_header}}{{APIRef("Sensor API")}}{{SeeCompatTable}}

The illuminance read-only property of the {{domxref("AmbientLightSensor")}} interface returns the current light level in lux of the ambient light level around the hosting device.

Value

A {{jsxref('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

{{Specifications}}

Browser compatibility

{{Compat}}