Ambient Light Sensor

W3C Working Draft,

This version:
Latest version:
Editor's Draft:
Previous Versions:
Version History:
Feedback: with subject line “[ambient-light] … message topic …” (archives)
Issue Tracking:
Level 2 Issues
Anssi Kostiainen (Intel Corporation)
Tobie Langel (Intel Corporation)
Former Editor:
Doug Turner (Mozilla Corporation)
Bug Reports:
via the w3c/ambient-light repository on GitHub


This specification defines a concrete sensor interface to monitor the ambient light level or illuminance of the device’s environment.

Status of this document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at

This document was published by the Device APIs Working Group as a Working Draft. This document is intended to become a W3C Recommendation.

If you wish to make comments regarding this document, please send them to (subscribe, archives). When sending e-mail, please put the text “ambient-light” in the subject, preferably like this: “[ambient-light] …summary of comment…”. All comments are welcome.

Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

This document is governed by the 1 September 2015 W3C Process Document.

1. Introduction

The Ambient Light Sensor extends the Generic Sensor API [GENERIC-SENSOR] to provide information about ambient light levels, as detected by the device’s main light detector, in terms of lux units.

The light-level media feature [MEDIAQUERIES-4] provides less granular information about the ambient light level.

Note: it might be worthwhile to provide a high-level Light Level Sensor which would mirror the light-level media feature, but in JavaScript. This sensor would _not require additional user permission to be activated_ in user agents that exposed the light-level media feature.

2. Examples

let sensor = new AmbientLightSensor();
sensor.onchange = function(event) {

sensor.onerror = function(event) {
    console.log(, event.error.message);

3. Security and Privacy Considerations

There are no specific security and privacy considerations beyond those described in the Generic Sensor API [GENERIC-SENSOR].

4. Model

The Ambient Light Sensor’s associated Sensor subclass is the AmbientLightSensor class.

The Ambient Light Sensor’s associated SensorReading subclass is the AmbientLightSensorReading class.

The Ambient Light Sensor has a default sensor, which is the device’s main light detector.

The Ambient Light Sensor has a single supported reporting mode which is "auto".

The Ambient Light Sensor’s permission name is "ambient-light". It has no associated PermissionDescriptor.

The Ambient Light Sensor has an associated abstract operation to retrieve the sensor permission which must simply return a permission whose name is "ambient-light".

The Ambient Light Sensor has an associated abstract operation to construct a SensorReading object which creates a new AmbientLightSensorReading object and sets its illuminance attribute to the current light level.

The current light level#current-light-levelReferenced in:4. Model5.2.2. The illuminance attribute or illuminance is a value that represents the ambient light levels around the hosting device. Its unit is the lux (lx) [SI].

Note: The precise lux value reported by different devices in the same light can be different, due to differences in detection method, sensor construction, etc.

5. API

5.1. The AmbientLightSensor Interface

[Constructor(optional SensorOptions sensorOptions)]
interface AmbientLightSensor#ambientlightsensorReferenced in:4. Model : Sensor {
  readonly attribute AmbientLightSensorReading? reading;

To Construct an AmbientLightSensor Object the user agent must invoke the construct a Sensor object abstract operation.

5.2. The AmbientLightSensorReading Interface

[Constructor(AmbientLightSensorReadingInit ambientLightSensorReadingInit)]
interface AmbientLightSensorReading#ambientlightsensorreadingReferenced in:4. Model (2)5.1. The AmbientLightSensor Interface5.2.2. The illuminance attribute : SensorReading {
    readonly attribute unrestricted double illuminance#dom-ambientlightsensorreading-illuminanceReferenced in:4. Model5.2.2. The illuminance attribute;
dictionary AmbientLightSensorReadingInit#dictdef-ambientlightsensorreadinginitReferenced in:5.2. The AmbientLightSensorReading Interface {
  unrestricted double illuminance;

5.2.1. The AmbientLightSensorReading constructor

5.2.2. The illuminance attribute

The illuminance attribute of the AmbientLightSensorReading interface represents the current light level.

6. Acknowledgements

Doug Turner for the initial prototype and Marcos Caceres for the test suite.

Paul Bakaus for the LightLevelSensor idea.


Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Conformant Algorithms

Requirements phrased in the imperative as part of algorithms (such as "strip any leading space characters" or "return false and abort these steps") are to be interpreted with the meaning of the key word ("must", "should", "may", etc) used in introducing the algorithm.

Conformance requirements phrased as algorithms or specific steps can be implemented in any manner, so long as the end result is equivalent. In particular, the algorithms defined in this specification are intended to be easy to understand and are not intended to be performant. Implementers are encouraged to optimize.

Conformance Classes

A conformant user agent must implement all the requirements listed in this specification that are applicable to user agents.

A conformant server must implement all the requirements listed in this specification that are applicable to servers.


Terms defined by this specification

Terms defined by reference


Normative References

Tobie Langel. Generic Sensor API. 24 March 2016. WD. URL:
Florian Rivoal; Tab Atkins Jr.. Media Queries Level 4. 26 January 2016. WD. URL:
Mounir Lamouri; Marcos Caceres. The Permissions API. 7 April 2015. WD. URL:
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL:

Informative References

SI Brochure: The International System of Units (SI), 8th edition. 2014. URL:

IDL Index

[Constructor(optional SensorOptions sensorOptions)]
interface AmbientLightSensor : Sensor {
  readonly attribute AmbientLightSensorReading? reading;

[Constructor(AmbientLightSensorReadingInit ambientLightSensorReadingInit)]
interface AmbientLightSensorReading : SensorReading {
    readonly attribute unrestricted double illuminance;
dictionary AmbientLightSensorReadingInit {
  unrestricted double illuminance;