Web Development Bug Report

CSS 100vh cuts off the bottom bar on mobile: use dvh, svh and lvh

Our checkout button sat below the fold on phones because a full-screen panel used height: 100vh. On mobile, vh means the largest viewport, with the browser toolbar hidden. Switching to dvh with a vh fallback, and handling the keyboard, fixed it.

Le Minh Khoa Le Minh Khoa @leminhkhoa · November 14, 2026 · 7 min read · 152 Views
572-css-100vh-mobile-address-bar-dvh-svh

Our mobile checkout opens a full-screen order summary with the Pay now button pinned to the bottom. Analytics showed conversion on phones dropping by a few points after a redesign, and session recordings explained it: on first load, the button was hidden below the visible area. Users had to scroll a little, which collapsed the address bar, before it appeared. Some never found it.

The panel's CSS was the obvious suspect:

.summary {
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.summary__actions { margin-top: auto; }

Reproducing it

  1. Open the checkout on an iPhone in Safari or on Android in Chrome, with the toolbar visible.

  2. The panel is taller than the visible screen by roughly the height of the browser UI.

  3. Scroll slightly: the toolbar collapses and the button comes into view.

Desktop browsers showed no problem, because there the viewport does not change size as you scroll.

What we ruled out

  • Safe area insets. env(safe-area-inset-bottom) handles the home indicator on notched iPhones. We already used it; it did not account for a 50 to 80 pixel gap.

  • A fixed header. Removing the header did not change the overflow.

  • Viewport meta tag. We had the standard width=device-width, initial-scale=1.

Root cause

On mobile browsers, vh is based on the large viewport: the size of the screen when browser toolbars are retracted. When the page first loads, the toolbars are showing, so the visible area is smaller than 100vh. Our panel was sized for the bigger viewport and its bottom sat behind the toolbar. This is specified behaviour, chosen so that content does not jump every time the toolbar moves.

What is happening under the hood

Mobile browsers have dynamic toolbars that slide in and out while scrolling. CSS Values and Units Level 4 defines three viewport sizes to cover this:

Unit

Meaning

Changes while scrolling?

svh

Small viewport: toolbars fully shown

No

lvh

Large viewport: toolbars retracted

No

dvh

Dynamic viewport: whatever is visible now

Yes

vh

Same as lvh in mobile browsers

No

There are matching width units (svw, lvw, dvw) and logical ones (svb, dvi and so on). Safari 15.4, Chrome 108 and Firefox 101 shipped these units, so all current browsers support them.

The on-screen keyboard is a separate matter. Since Chrome 108 on Android, opening the keyboard by default resizes only the visual viewport, not the layout viewport, which matches iOS Safari. Units like dvh do not shrink for the keyboard in that mode. The interactive-widget key in the viewport meta tag lets a page ask Chromium to resize the layout viewport instead.

Environment

Component

Version / value

iPhone

iOS 26.1, Safari 26.1

Android

Android 16, Chrome 142

Desktop

Chrome 142, Firefox 145, Safari 26.1 (no repro)

App

Next.js 16 checkout, CSS modules

Minimal reproduction

<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
  body { margin: 0; }
  .panel { height: 100vh; display: flex; flex-direction: column; background: #eef; }
  .panel button { margin-top: auto; height: 56px; }
</style>
<div class="panel"><p>Order summary</p><button>Pay now</button></div>

Who is affected

  • Full-screen layouts on iOS Safari, Chrome for Android, and other mobile browsers with dynamic toolbars.

  • Bottom-pinned buttons, chat inputs, modals and hero sections sized with 100vh.

  • Older JavaScript workarounds (--vh set from window.innerHeight) that do not update on rotation or toolbar changes.

The fix

Use dvh for the panel, with a vh line first as a fallback for any engine that does not parse the new unit:

 .summary {
-  height: 100vh;
+  height: 100vh;   /* fallback */
+  height: 100dvh;  /* visible area, follows the toolbar */
   display: flex;
   flex-direction: column;
 }

A browser that does not understand dvh drops the second declaration and keeps the first.

For backgrounds and hero sections that should not resize while scrolling (resizing causes layout jumps and repaints), we used svh, which always fits the smallest visible area and never changes:

.hero { min-height: 100svh; }

Our rule of thumb:

  • Pinned UI that must be visible now (actions, chat input): dvh.

  • Large decorative sections: svh so they fit without moving.

  • Rarely, lvh for backgrounds that should cover the screen even when toolbars hide.

Handling the keyboard

The promo code field sits inside the panel. With the keyboard open on Android, the button stayed hidden behind the keyboard, because the layout viewport did not shrink. Two options:

Option A, Chromium only: ask for the layout viewport to resize.

<meta name="viewport" content="width=device-width, initial-scale=1, interactive-widget=resizes-content">

Chrome then shrinks the layout viewport, and dvh follows. Safari ignores the key.

Option B, all browsers: use the Visual Viewport API to lift the actions bar.

const vv = window.visualViewport;
function placeActions() {
  if (!vv) return;
  const hidden = window.innerHeight - vv.height - vv.offsetTop;
  actions.style.transform = `translateY(${-Math.max(0, hidden)}px)`;
}
vv?.addEventListener('resize', placeActions);
vv?.addEventListener('scroll', placeActions);

We shipped Option A plus Option B for iOS. Keep it simple where you can: many forms work fine if the focused input scrolls into view and the button follows naturally in document flow.

Alternatives and trade-offs

  • position: fixed; bottom: 0 for the button instead of a full-height flex column. Fixed elements follow the visible viewport on modern mobile browsers. It avoids sizing the panel at all, but needs bottom padding so content does not hide behind the bar.

  • The --vh JavaScript hack. Setting a custom property from innerHeight on resize worked before the new units existed. It is now unnecessary and causes jank if it runs on every scroll.

How to test the fix

  • Real devices, toolbar visible: the button is fully visible on first load.

  • Scroll down and up: the button stays visible as the toolbar moves.

  • Focus the promo code field: the button is not covered by the keyboard.

  • Rotate the device: layout adjusts without a reload.

Playwright can emulate mobile viewports but not dynamic toolbars, so we assert the CSS instead:

test('summary uses dynamic viewport height', async ({ page }) => {
  await page.goto('/checkout/summary');
  const h = await page.$eval('.summary', (el) => getComputedStyle(el).height);
  const vh = await page.evaluate(() => window.innerHeight);
  expect(parseFloat(h)).toBeCloseTo(vh, 0);
});

Confirming in production

Session recordings stopped showing the scroll-to-find-button pattern, and the numbers followed:

pay_button_visible_on_load{device="mobile"}   before: 61%   after: 99.4%
checkout_conversion{device="mobile"}          recovered to pre-redesign level within a week

We log the button's visibility with an IntersectionObserver on first render, which is how we measured the first line.

Regression guard

  • Stylelint rule unit-disallowed-list forbids vh in our checkout and modal folders unless the next declaration uses dvh, svh or lvh (enforced by a small custom rule).

  • The visibility event above has an alert if mobile first-render visibility drops below 95 percent.

  • Real-device checks for checkout are part of the release checklist.

Security implications

None. The change affects layout only. A hidden pay button is a conversion problem, not a security one, though layouts that hide important text (fees, terms) below toolbars can mislead users, so we check that totals are visible on load as well.

Prevention checklist

  • Never use bare 100vh for full-screen mobile layouts; use dvh or svh with a vh fallback.

  • Pick dvh for UI that must be visible now and svh for large static sections.

  • Plan for the keyboard: interactive-widget in Chromium, Visual Viewport on iOS.

  • Test on real phones with the toolbar visible.

References

Add a label

#css #viewport-units #mobile-safari #chrome-android #responsive-design
Written by
Le Minh Khoa @leminhkhoa

I work on databases and data pipelines: MySQL and PostgreSQL in production, Kafka streams, change data capture and the analytical stores downstream. I started as a backend developer on a gaming platform, where a single race condition could hand out items that did not exist, and that taught me to respect concurrency early. Most of my posts start with an alert: a disk filling overnight, a server at full CPU, missing rows after a failover. I show how we traced it to the root cause, the fix, and the monitoring or test we added so it does not happen twice.

Advertisement

Comments

0

No comments yet. Be the first to comment!

Sign In to post a comment.