API field guide / 04

DEVICE BATTERY CHARGE API

Battery-aware experiences begin with supported signals. Explore device battery status, browser limitations, native integration boundaries, and helpful behavior when data is unavailable.

What can a device battery API provide?

A device battery API gives an application a supported view of a device’s reported battery state. The web Battery Status API defines values such as a battery level and whether the device is charging, but availability depends on the browser and its security and privacy constraints. Native platforms have separate APIs and rules. Design around the capabilities actually present in the environment.

Treat battery data as an optional capability

A website should still work when battery information is not exposed. Test whether the relevant API exists before invoking it, handle rejected requests, and maintain the normal experience when access is unavailable. A missing value is not proof that the battery is empty, the device is plugged in, or the user has disabled a setting.

Make units explicit

A browser-reported fractional level and an interface displaying a percentage are different representations of the same signal. Normalize carefully, validate the expected range, and preserve the original observation when debugging. Avoid displaying a precision that the device or API does not actually support. Where time estimates are absent or unbounded, present a neutral message instead of a misleading countdown.

Use the signal for a proportionate purpose

Before adding battery awareness, explain the benefit in product terms. A user preference for a lighter experience may be more dependable than inferring intent from a battery reading. Keep collection limited to the immediate feature’s needs and avoid retaining detailed battery histories merely because an API makes them available.

Keep browser and native contracts separate

Do not promise identical behavior across web browsers, mobile operating systems, and connected hardware. Document where the feature runs, which fields it expects, and what happens if they change. When a native application uses operating-system battery information, review that platform’s own documentation and lifecycle behavior rather than copying assumptions from a browser example.

A practical data checklist

Use this as an evaluation framework for your own data contract. Field names and actual availability remain provider-specific.

AreaWhat to examineDesign consideration
SupportAPI presence and request outcomeFeature-detect and handle unavailable access.
Reported levelFraction or percentageLabel and normalize units deliberately.
Charging stateDevice-reported charging flagDo not infer hardware or battery health from it.
Optional estimatesReported timing, if supportedRepresent missing or unbounded estimates clearly.
Primary reference

W3C Battery Status API specification

The specification defines the web API’s signals and constraints. Confirm current implementation support in your target browsers.

Let’s connect

GOOD INTEGRATIONS START
WITH GOOD QUESTIONS.

Talk charging with us