Sensors & Location

Ambient Light Sensor

Probing…

Ambient Light Sensor is a web platform capability in the Sensors & Location category. Environmental light level in lux. available behind a flag in Chromium; not available in Firefox and Safari. Requires a secure context (HTTPS or localhost) and a user gesture such as a click or tap.

Secure contextUser gesture

Permission ambient-light-sensor: unknown

Try it

Loading demo…

Code

const sensor = new AmbientLightSensor({ frequency: 5 })
sensor.addEventListener('reading', () => {
  console.log(sensor.illuminance, 'lux')
})
sensor.addEventListener('error', e => console.warn(e.error))
sensor.start()

Browser support

Chromium
Behind a flag
Firefox
No
Safari
No

Frequently asked questions

Which browsers support Ambient Light Sensor?

available behind a flag in Chromium; not available in Firefox and Safari.

Does Ambient Light Sensor require HTTPS?

Yes. Ambient Light Sensor needs a secure context, so it only works over HTTPS (or on localhost during development).

What is Ambient Light Sensor used for?

Environmental light level in lux.

Can I try Ambient Light Sensor in my browser?

Yes. shwcs.net runs a live Ambient Light Sensor demo that probes your current browser and lets you try the API. Everything runs locally — nothing is sent anywhere.

MDN reference ↗ Specification ↗