Switch Component: Checkbox

Switch Component: Checkbox

Published: July 26, 2018

Last updated: August 6, 2020

Pattern to modify a checkbox into a switch component.

Pattern Demo

Version: [type=”checkbox”] styled to look like a switch

Example Text 1:

Version: [type=”checkbox”][role=”switch”]

Example Text 2:

Version: [type=”checkbox”][role=”switch”] – Alternate Markup/Style

Example Text 3:

Visual design note

-moz-appearance: none; does not completely remove the styling
from the checkbox in Firefox ESR. (works as expected in Firefox 60+).

The box-shadow to provide an outline of the control does not
render as expected in IE11, did work as expected in Edge (legacy).

IE and Edge (legacy) don’t respect the box-shadow in High Contrast mode.
Previously, the ::-ms-check was re-enabled so that people will at least see
a checkmark when the switch is on, and an empty oval when off. Chromium Edge does respect the
box-shadow fill, so this has been updated. I no longer have Legacy Edge to verify if
this introduces an issue there or not.

Pattern Details

Pattern Markup
<!– Version: [type=”checkbox”] styled to look like a switch –>
<label class=”check-switch” for=”switch_1″>
Example Text 1:
<input id=”switch_1″ type=”checkbox”>
<span aria-hidden=”true”></span>
</label>

<!– Version: [type=”checkbox”][role=”switch”] –>
<label class=”check-switch” for=”switch_2″>
Example Text 2:
<input id=”switch_2″ data-check-switch=”” [...]

Read article at scottaohara.github.io

Article Taxonomies

Categories:
Fatal error: Uncaught Error: Object of class WP_Error could not be converted to string in /home/webable/www/www/wp-content/themes/webable/content-mcm.php:65 Stack trace: #0 /home/webable/www/www/wp-includes/template.php(812): require() #1 /home/webable/www/www/wp-includes/template.php(745): load_template('/home/webable/w...', false, Array) #2 /home/webable/www/www/wp-includes/general-template.php(206): locate_template(Array, true, false, Array) #3 /home/webable/www/www/wp-content/themes/webable/single-mcm_article.php(15): get_template_part('content-mcm') #4 /home/webable/www/www/wp-includes/template-loader.php(106): include('/home/webable/w...') #5 /home/webable/www/www/wp-blog-header.php(19): require_once('/home/webable/w...') #6 /home/webable/www/www/index.php(17): require('/home/webable/w...') #7 {main} thrown in /home/webable/www/www/wp-content/themes/webable/content-mcm.php on line 65