The BatteryManager.level
property indicates the current battery charge level as a value between 0.0
and 1.0
. A value of 0.0
means the battery is empty and the system is about to be suspended. A value of 1.0
means the battery is full or the user agent is unable to report the battery status information. When its value changes, the levelchange
event is fired.
On this page
BatteryManager: level property
Value
A number.
Examples
Getting the battery level
HTML
html
<button id="get-level">Get battery level</button>
<div id="output"></div>
JavaScript
js
const getLevel = document.querySelector("#get-level");
const output = document.querySelector("#output");
getLevel.addEventListener("click", async () => {
if (!navigator.getBattery) {
output.textContent = "Battery manager is unsupported";
} else {
const manager = await navigator.getBattery();
const level = manager.level;
output.textContent = `Battery level: ${level}`;
}
});
Result
Specifications
Specification |
---|
Battery Status API # dom-batterymanager-level |
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 | |
level |
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/level