How Does a Phone Bubble Level Work? The Sensors Explained
A traditional spirit level relies on a bubble of air floating in liquid. Your phone has no liquid and no bubble — yet it can tell you if a shelf is level to within a few tenths of a degree. The secret is a set of tiny sensors that have been inside smartphones for well over a decade.
The accelerometer: sensing gravity
An accelerometer measures acceleration along three axes: left–right (X), up–down along the screen (Y), and in–out of the screen (Z). The sensor in your phone is a MEMS device — a micro-electro-mechanical system etched into silicon, smaller than a grain of rice.
Inside is a microscopic mass suspended on flexible silicon springs, surrounded by comb-like electrodes. When the phone accelerates or tilts, the mass shifts very slightly, changing the electrical capacitance between the electrodes. The chip measures that change thousands of times per second.
Here’s the key insight: when the phone is sitting still, the only “acceleration” it feels is gravity, pulling at about 9.81 m/s² toward the centre of the Earth. By measuring how much of that pull falls on each of the three axes, the phone knows exactly which way is down.
- Lying flat and level: all of gravity is on the Z axis; X and Y read zero.
- Tilted slightly to the right: a small part of gravity appears on the X axis.
- Standing upright: gravity is mostly on the Y axis.
The tilt angle comes from simple trigonometry. For example, the side-to-side tilt is the arctangent of the X reading divided by the Z reading.
The gyroscope: sensing rotation
A gyroscope measures how fast the phone is rotating around each axis. It’s also a MEMS device, using a vibrating structure that experiences a tiny sideways force (the Coriolis effect) when rotated.
The gyroscope is excellent at tracking quick movements smoothly, but it drifts over time. The accelerometer is stable over time but noisy and easily confused by movement. Phones combine both using sensor fusion algorithms, which take the best of each: a smooth, responsive and stable estimate of orientation.
From sensors to a web page
Modern browsers make this fused orientation available to websites through the DeviceOrientation API. It reports three angles:
- alpha — rotation around the vertical axis (like a compass heading)
- beta — front-to-back tilt
- gamma — left-to-right tilt
Our level reads beta and gamma, converts them into a direction-of-gravity vector, and rotates that vector to match your screen orientation. From there it calculates the reading for each mode: the side tilt for Bar Level, the two-axis tilt for Surface Level, and the full angle for the Angle Finder. A small low-pass filter — the “smoothing” setting — averages out jitter so the bubble glides instead of shaking.
All of this happens in your browser, on your device. Nothing is sent to a server.
Why iPhones ask for permission
Motion sensors can, in theory, reveal what you’re doing — walking, typing or even tapping specific parts of the screen. To protect privacy, Apple introduced a permission prompt in iOS 13. A website must ask, and you must tap Allow, before it can receive motion data. Browsers also only provide these sensors on secure (https) pages.
How accurate is it?
Phone accelerometers typically have a resolution far finer than 0.1°, but their absolute accuracy is limited by small manufacturing offsets — often a few tenths of a degree, sometimes more. Phone cases and camera bumps add their own error when the phone lies flat.
That’s why calibration matters. Once calibrated, most phones give repeatable results within about 0.1°–0.3°, which is comparable to an inexpensive spirit level and more than enough for household jobs.
Where a phone falls short is length. A 1.2-metre spirit level averages out bumps over its full length, while a phone only touches 15 cm of surface. For long runs, rest your phone on a straight board.
Spirit level vs phone level
| Spirit level | Phone level | |
|---|---|---|
| Reads exact angle | No (only “level or not”) | Yes |
| Long-span accuracy | Excellent | Needs a straight edge |
| Units | — | Degrees, %, in/ft, mm/m |
| Audible alert | No | Yes |
| Always in your pocket | Rarely | Almost always |
Both tools have a place. For quick jobs and angle measurement, the phone in your pocket is hard to beat.