iOS Chrome viewport behaves differently with keyboard
OS: iOS 16+ · Device: Mobile (iPhone/iPad) Any · Browser: Chrome (iOS) 120+ · Keyboard: English (QWERTY) or iOS Virtual Keyboard
Open case →Scenario
On iOS Safari, when the software keyboard becomes visible, viewport calculations become unreliable. `position:fixed` elements break, `height` returns incorrect values, and absolute positioning with `top`/`bottom` fails. This severely affects editors with floating toolbars or positioned elements.
On iOS Safari, when the software keyboard becomes visible, the viewport calculation and mechanics break down, causing CSS positioning and viewport dimension queries to return incorrect or unreliable values.
This issue occurs when:
position:fixed elements (e.g., floating toolbars)position:fixed elements should remain fixed relative to viewportwindow.innerHeight, document.documentElement.clientHeight should return visible viewport heightposition:absolute with top/bottom should work correctlywindow.innerHeight returns wrong value (doesn’t account for keyboard)position:absolute; top: Ypx doesn’t position correctlyiOS Safari’s viewport management has known issues when:
The Visual Viewport API and standard CSS positioning fail to work reliably when the keyboard is present.
position:fixed for overlay elementsUse Visual Viewport API (limited support):
if (window.visualViewport) {
const viewport = window.visualViewport;
// May provide more accurate dimensions
console.log('Viewport:', viewport);
}
Listen to keyboard visibility changes:
// iOS specific: detect keyboard show/hide
const initialHeight = window.innerHeight;
window.addEventListener('resize', () => {
const currentHeight = window.innerHeight;
// If viewport shrinks significantly, keyboard likely visible
if (currentHeight < initialHeight - 150) {
console.log('Keyboard is visible');
// Adjust UI positioning
updateForKeyboardState(true);
} else if (currentHeight >= initialHeight - 100) {
console.log('Keyboard is hidden');
updateForKeyboardState(false);
}
});
Use position: absolute with viewport units:
.fixed-element {
position: absolute;
bottom: 10vh; /* May work better than fixed */
/* Or use bottom: env(keyboard-inset-bottom, 0px) */
}
Use iOS viewport meta tag (limited help)**:
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
Provide user control for keyboard dismissal:
const editor = document.querySelector('[contenteditable]');
// Add "Done" button
const doneButton = document.createElement('button');
doneButton.textContent = 'Done';
doneButton.onclick = () => {
editor.blur(); // Hide keyboard
setTimeout(() => {
// Restore positioning after keyboard hides
editor.focus();
}, 300);
};
Use transform instead of position (may help):
.fixed-element {
position: fixed;
transform: translate(0, 0); /* Sometimes works better */
}
Visual view of how this scenario connects to its concrete cases and environments. Nodes can be dragged and clicked.
Each row is a concrete case for this scenario, with a dedicated document and playground.
| Case | OS | Device | Browser | Keyboard | Status |
|---|---|---|---|---|---|
| ce-0286-ios-viewport-keyboard-chrome-ios-en | iOS 16+ | Mobile (iPhone/iPad) Any | Chrome (iOS) 120+ | English (QWERTY) or iOS Virtual Keyboard | draft |
Open a case to see the detailed description and its dedicated playground.
OS: iOS 16+ · Device: Mobile (iPhone/iPad) Any · Browser: Chrome (iOS) 120+ · Keyboard: English (QWERTY) or iOS Virtual Keyboard
Open case →Other scenarios that share similar tags or category.
On iPhone/iPad Safari, when entering text or pressing "return" multiple times in a contenteditable element, the software keyboard appears but hides the text being typed. The page doesn't auto-scroll to keep text visible. Works fine on Android and other browsers.
When a contenteditable element has CSS backdrop-filter applied, rendering may be affected. Text may appear blurry, selection may not render correctly, and performance may be degraded, especially on mobile devices.
On mobile devices, the combination of enterkeyhint and inputmode attributes may affect Enter key behavior inconsistently on contenteditable elements. The Enter key may insert line breaks when it should perform an action, or vice versa.
The `inputmode` attribute, which should control the type of virtual keyboard shown on mobile devices, does not work on contenteditable regions in iOS Safari. The keyboard type cannot be controlled.
When a page with a contenteditable element responds to media query changes (e.g., orientation change, window resize), the layout changes may disrupt editing. The caret position may jump, and selection may be lost.
Have questions, suggestions, or want to share your experience? Join the discussion below.