W3cubDocs

/Web APIs

BatteryManager: charging property

The BatteryManager.charging property is a Boolean value indicating whether or not the device's battery is currently being charged. When its value changes, the chargingchange event is fired.

If the battery is charging or the user agent is unable to report the battery status information, this value is true. Otherwise, it is false.

Value

A boolean.

Examples

HTML

html

<div id="charging">(charging state unknown)</div>

JavaScript

js

navigator.getBattery().then((battery) => {
  const charging = battery.charging;

  document.querySelector("#charging").textContent = charging;
});

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
charging 38 79 43–52 No 25 No 38 38 43–52 25 No 3.0

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/BatteryManager/charging