References

Beginner-friendly references for web development, with live, editable examples.

The HTML virtualkeyboardpolicy attribute

Global attribute Works on every element
In short

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

Live 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.virtualKeyboard before you set virtualkeyboardpolicy="manual". The object is exposed only in secure contexts such as HTTPS pages, and without it there is no show() to open the keyboard.
  • Call navigator.virtualKeyboard.show() from your own handler, such as a double-tap on the editor. Chrome ignores show() 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, because show() 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 a hide() 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?
Controls whether the on-screen keyboard appears automatically for a contenteditable element.
Is virtualkeyboardpolicy guaranteed to work?
No. Support is limited to Chromium-based browsers; others ignore it.
Which elements does virtualkeyboardpolicy affect?
It is a global attribute meant for contenteditable elements, and Chrome also applies it to text <input> fields and <textarea>. The draft spec still lists how those two are handled as an open issue.
What stops the keyboard from resizing the page, virtualkeyboardpolicy or overlaysContent?
Setting 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.