Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

switch — a switch control for input

In browsers that support it, the boolean switch attribute turns an input of type checkbox into a two-state switch. Its on/off state is still determined by checked.

Version: Nonstandard browser extension; not defined by the WHATWG HTML Living Standard.

Syntax

<input type="checkbox" switch>

switch applies to input with type="checkbox"; it is not a separate input type. The switch has two states: on and off, determined by checked. When the browser applies switch, indeterminate does not provide a third state. If the browser ignores switch, the control remains an ordinary checkbox, and indeterminate can affect its appearance.

This is a boolean attribute: valid forms are switch, switch="", and switch="switch". To disable it, remove the attribute. Writing switch="false" is invalid and still means the attribute is present. Removing switch is not the same as setting checked to false.

In the example, a label describes the control, and the text below displays checked. Check switch rendering separately in your target browser; the text output alone does not confirm switch support.

Examples

<!doctype html>
<meta charset="utf-8">
<title>Switch</title>
<label><input id="setting" type="checkbox" switch checked> Notifications</label>
<pre id="result"></pre>
<script>
  const setting = document.getElementById('setting');
  const result = document.getElementById('result');
  function render() {
    result.textContent = String(setting.checked);
  }
  setting.addEventListener('change', render);
  render();
</script>

Result

true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources