The HTML virtualkeyboardpolicy attribute
The HTML virtualkeyboardpolicy attribute controls whether the on-screen keyboard appears automatically when a contenteditable element is focused. Values are auto and manual. It is a global attribute from the VirtualKeyboard API, currently in Chromium-based browsers.
Overview
On editable elements, focusing usually pops up the on-screen keyboard automatically. The virtualkeyboardpolicy attribute lets you take control: auto keeps the default behavior, while manual stops the automatic keyboard so you can show or hide it yourself through the VirtualKeyboard API.
This is useful for custom editing surfaces (drawing apps, code editors, games) where the default keyboard would get in the way. Support is currently limited to Chromium-based browsers.
Values
| Value |
|---|
| auto | manual |
Example
<div contenteditable="true" virtualkeyboardpolicy="manual" style="border:1px solid #cbd5e1; padding:10px; border-radius:8px;">Editable region with manual virtual-keyboard control.</div>
Best practices
- Check for
navigator.virtualKeyboardbefore you setvirtualkeyboardpolicy="manual". The object is exposed only in secure contexts such as HTTPS pages, and without it there is noshow()to open the keyboard. - Call
navigator.virtualKeyboard.show()from your own handler, such as a double-tap on the editor. Chrome ignoresshow()until the user has interacted with the page and logs a console warning instead. - Avoid
inputmode="none"on a manual editor whose keyboard you open from script, becauseshow()does nothing while the focused element's inputmode is none. - With manual, focusing or tapping the editor leaves the keyboard as it was, so pair each
show()with ahide()call when editing ends. - Treat it as experimental. Chrome 94 and Edge 94 added it, and the VirtualKeyboard API behind it is still a W3C Working Draft, last published in 2022.
Frequently asked questions
What does the virtualkeyboardpolicy attribute do?
Is virtualkeyboardpolicy guaranteed to work?
Which elements does virtualkeyboardpolicy affect?
What stops the keyboard from resizing the page, virtualkeyboardpolicy or overlaysContent?
navigator.virtualKeyboard.overlaysContent to true does, while virtualkeyboardpolicy governs when the keyboard opens and closes. With overlaysContent on, the browser must not resize the viewport or the visual viewport.






















