SlideShare a Scribd company logo
Accessible
custom radio buttons
and checkboxes
The pain
Web designers and developers
have always struggled with how
to customise radio buttons and
checkboxes.
Diagram: A series of differently styled on/off switches.
The main issue is that these
elements are notoriously hard
to style - especially across
multiple browsers and devices.
In the past, some developers
resorted to JavaScript-based
solutions to solve this problem.
In some cases this involved
using JS to remove the
original radio or checkbox
element making the end result
inaccessible for a wide range of
assistive technologies.
It can be done
However, it is possible to style
these elements without having
to use JavaScript. And more
importantly, we can make the
end result accessible.
Let’s take a simple example of
an on/off switch that can be
applied to either radio or
checkbox elements:
unchecked
checked
Diagram: Shows the unchecked and checked version of the switch.
The solution I’m about to demo,
has four key accessibility
features:
Feature 1:
Using the intended semantic
elements, the input and label
elements will be explicitly
associated using matching "for"
and "id" values.
Feature 2:
The label content can used to
describe the purpose of each
switch for screen readers. This
content is hidden off-screen.
Feature 3:
The tick icon makes the two
different states clearly
distinguishable - aiding colour-
blind users and some types of
cognitive-impaired users.
Feature 4:
The switch is keyboard-friendly
(operates in the normal way) but
we also clearly flag the focus and
hover states.
HTML/CSS
<div class="switch">
<input
class="switch__control"
type="radio"
name="example01"
id="example01">
<label class="switch__label" for="example01">
<span class="switch__content">Label content</span>
</label>
</div>
Radio
<div class="switch">
<input
class="switch__control"
type="checkbox"
name="example01"
id="example01">
<label class="switch__label" for="example01">
<span class="switch__content">Label content</span>
</label>
</div>
Checkbox
<div class="switch">
<input
class="switch__control"
type="checkbox"
name="example01"
id="example01">
<label class="switch__label" for="example01">
<span class="switch__content">Label content</span>
</label>
</div>
ID value
“for” values
/* parent module */
.switch { }
/* descendants of parent module */
.switch__control { }
.switch__label { }
.switch__content { }
How does it work?
We can use the parent
container to create the overall
dimensions of the switch.
switch
Diagram: Shows the switch layer as a dotted outline.
The control is then positioned
on top of the parent, and set
with opacity: 0. This means it
exists on the page, and can be
interacted with, but it cannot be
seen.
switch
switch__control
Diagram: Shows the control sitting on top of the switch layer.
Then, the label is placed on top
of the radio button, and we can
style the background of this label
to look like a switch.
switch
switch__control
switch__label
Diagram: Shows label sitting on top of the control.
And finally, the label content is
hidden off screen so that it is
available for screen readers, but
does not clutter the visual
appearance of the switch.
The problem
Checkbox and radio button
elements can be manually
changed by users - from
unchecked to checked etc.
These elements can also be
given boolean “checked” and
“disabled” attributes.
<!-- unchecked -->
<input type="checkbox">
<!-- checked -->
<input type="checkbox" checked>
<!-- disabled -->
<input type="checkbox" disabled>
However, for this solution, most
of the styling is applied to the
label element, rather than the
input.
Unfortunately, the label element
has no checked, unchecked
or disabled state of its own.
We can get around this using
adjacent sibling selectors,
which target any label element
that is adjacent to (comes
directly after) the input.
/* unchecked input */
.switch__control + label { }
/* checked input */
.switch__control:checked + label { }
/* diabled input */
.switch__control[disabled] + label { }
unchecked
checked
disabled
Diagram: Shows the unchecked, checked and disabled version of the switch.
Different states
Finally, we also want to style
the :focus and :hover states of
the switch.
/* unchecked input */
.switch__control:hover + label { }
.switch__control:focus + label { }
/* checked input */
.switch__control:checked:hover + label { }
.switch__control:checked:focus + label { }
This gives us a series of
possible results that looks like
this:
unchecked hover
unchecked focus
unchecked
checked
checked hover
checked focus
disabled
Diagram: Shows variations of the switch.
Demo:
https://russmaxdesign.github.io/switch-checkbox/
Russ Weakley
Max Design

Site: maxdesign.com.au

Twitter: twitter.com/russmaxdesign

Slideshare: slideshare.net/maxdesign

Linkedin: linkedin.com/in/russweakley

More Related Content

What's hot (20)

PPT
CSS Basics
WordPress Memphis
 
PDF
Introduction to HTML5
Gil Fink
 
PDF
Php introduction
krishnapriya Tadepalli
 
PPTX
Java beans
Rajkiran Mummadi
 
PPTX
Buffer and scanner
Arif Ullah
 
PDF
Bootstrap
Jadson Santos
 
PPT
Js ppt
Rakhi Thota
 
PPTX
Web Application Technologies
Se-Han Lee
 
PPT
SHA 1 Algorithm.ppt
Rajapriya82
 
PPT
Visual Basic menu
kuldeep94
 
PPT
Css lecture notes
Santhiya Grace
 
PPT
Hyperlinks in HTML
Aarti P
 
PDF
HTTP Request and Response Structure
BhagyashreeGajera1
 
PDF
Data Flow Diagram - Level 0.pdf
AbhasAbhirup
 
PPTX
Password management
Sai Kumar
 
DOCX
Practical file on web technology(html)
RAJWANT KAUR
 
PPTX
An Introduction to the DOM
Mindy McAdams
 
PPT
Introduction to Web Programming - first course
Vlad Posea
 
PPT
Chapter04 automated tools for systems development
Dhani Ahmad
 
PPTX
Java Datatypes
Mayank Aggarwal
 
CSS Basics
WordPress Memphis
 
Introduction to HTML5
Gil Fink
 
Php introduction
krishnapriya Tadepalli
 
Java beans
Rajkiran Mummadi
 
Buffer and scanner
Arif Ullah
 
Bootstrap
Jadson Santos
 
Js ppt
Rakhi Thota
 
Web Application Technologies
Se-Han Lee
 
SHA 1 Algorithm.ppt
Rajapriya82
 
Visual Basic menu
kuldeep94
 
Css lecture notes
Santhiya Grace
 
Hyperlinks in HTML
Aarti P
 
HTTP Request and Response Structure
BhagyashreeGajera1
 
Data Flow Diagram - Level 0.pdf
AbhasAbhirup
 
Password management
Sai Kumar
 
Practical file on web technology(html)
RAJWANT KAUR
 
An Introduction to the DOM
Mindy McAdams
 
Introduction to Web Programming - first course
Vlad Posea
 
Chapter04 automated tools for systems development
Dhani Ahmad
 
Java Datatypes
Mayank Aggarwal
 

Similar to Accessible custom radio buttons and checkboxes (14)

PDF
Creating a Simple, Accessible On/Off Switch
Russ Weakley
 
PDF
Javascript for Beginners 2022
flutterhub
 
PDF
CSS Disable Button - How to Disable Buttons Using CSS - Blogs
RonDosh
 
PDF
How to build accessible UI components
Russ Weakley
 
PDF
Clickable DIVs and other icebergs
Ben Buchanan
 
PDF
Accessibility in Design systems - the pain and glory
Russ Weakley
 
PPTX
Module 2-web-a11y-steve lee
Steve Lee
 
KEY
The Inclusive Web: hands-on with HTML5 and jQuery
colinbdclark
 
POTX
Reusable acceptance criteria and test cases for accessibility
Intopia
 
PPT
05 html-forms
Palakshya
 
PDF
Aria Widgets
toddkloots
 
PDF
TPR4
tutorialsruby
 
PDF
TPR4
tutorialsruby
 
PDF
Android accessibility for developers and QA
Ted Drake
 
Creating a Simple, Accessible On/Off Switch
Russ Weakley
 
Javascript for Beginners 2022
flutterhub
 
CSS Disable Button - How to Disable Buttons Using CSS - Blogs
RonDosh
 
How to build accessible UI components
Russ Weakley
 
Clickable DIVs and other icebergs
Ben Buchanan
 
Accessibility in Design systems - the pain and glory
Russ Weakley
 
Module 2-web-a11y-steve lee
Steve Lee
 
The Inclusive Web: hands-on with HTML5 and jQuery
colinbdclark
 
Reusable acceptance criteria and test cases for accessibility
Intopia
 
05 html-forms
Palakshya
 
Aria Widgets
toddkloots
 
Android accessibility for developers and QA
Ted Drake
 
Ad

More from Russ Weakley (20)

PDF
Accessible chat windows
Russ Weakley
 
PDF
Accessible names & descriptions
Russ Weakley
 
PDF
A deep dive into accessible names
Russ Weakley
 
PDF
What are accessible names and why should you care?
Russ Weakley
 
PDF
What is WCAG 2 and why should we care?
Russ Weakley
 
PDF
Accessible states in Design Systems
Russ Weakley
 
PDF
Creating accessible modals and autocompletes
Russ Weakley
 
PDF
Building an accessible progressive loader
Russ Weakley
 
PDF
Accessible Inline errors messages
Russ Weakley
 
PDF
What is accessibility?
Russ Weakley
 
PDF
Accessibility in Pattern Libraries
Russ Weakley
 
PDF
Accessibility in pattern libraries
Russ Weakley
 
PDF
Building an accessible auto-complete - #ID24
Russ Weakley
 
PDF
Building an accessible auto-complete
Russ Weakley
 
PDF
Creating Acessible floating labels
Russ Weakley
 
PDF
Creating an Accessible button dropdown
Russ Weakley
 
PDF
Deep Dive into Line-Height
Russ Weakley
 
PDF
Building Accessible Web Components
Russ Weakley
 
PDF
Building accessible web components without tears
Russ Weakley
 
PDF
Understanding the mysteries of the CSS property value syntax
Russ Weakley
 
Accessible chat windows
Russ Weakley
 
Accessible names & descriptions
Russ Weakley
 
A deep dive into accessible names
Russ Weakley
 
What are accessible names and why should you care?
Russ Weakley
 
What is WCAG 2 and why should we care?
Russ Weakley
 
Accessible states in Design Systems
Russ Weakley
 
Creating accessible modals and autocompletes
Russ Weakley
 
Building an accessible progressive loader
Russ Weakley
 
Accessible Inline errors messages
Russ Weakley
 
What is accessibility?
Russ Weakley
 
Accessibility in Pattern Libraries
Russ Weakley
 
Accessibility in pattern libraries
Russ Weakley
 
Building an accessible auto-complete - #ID24
Russ Weakley
 
Building an accessible auto-complete
Russ Weakley
 
Creating Acessible floating labels
Russ Weakley
 
Creating an Accessible button dropdown
Russ Weakley
 
Deep Dive into Line-Height
Russ Weakley
 
Building Accessible Web Components
Russ Weakley
 
Building accessible web components without tears
Russ Weakley
 
Understanding the mysteries of the CSS property value syntax
Russ Weakley
 
Ad

Recently uploaded (20)

PPTX
SD_GMRC5_Session 6AB_Dulog Pedagohikal at Pagtataya (1).pptx
NickeyArguelles
 
PPTX
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
ENGlish 8 lesson presentation PowerPoint.pptx
marawehsvinetshe
 
PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
PDF
Lesson 1 - Nature of Inquiry and Research.pdf
marvinnbustamante1
 
PPTX
PLANNING FOR EMERGENCY AND DISASTER MANAGEMENT ppt.pptx
PRADEEP ABOTHU
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PDF
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
PDF
Vietnam Street Food & QSR Market 2025-1.pdf
ssuserec8cd0
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PDF
I3PM Case study smart parking 2025 with uptoIP® and ABP
MIPLM
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PDF
Lean IP - Lecture by Dr Oliver Baldus at the MIPLM 2025
MIPLM
 
PPTX
Lesson 1 Cell (Structures, Functions, and Theory).pptx
marvinnbustamante1
 
PPTX
ENG8_Q1_WEEK2_LESSON1. Presentation pptx
marawehsvinetshe
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
SD_GMRC5_Session 6AB_Dulog Pedagohikal at Pagtataya (1).pptx
NickeyArguelles
 
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
ENGlish 8 lesson presentation PowerPoint.pptx
marawehsvinetshe
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
Lesson 1 - Nature of Inquiry and Research.pdf
marvinnbustamante1
 
PLANNING FOR EMERGENCY AND DISASTER MANAGEMENT ppt.pptx
PRADEEP ABOTHU
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
Vietnam Street Food & QSR Market 2025-1.pdf
ssuserec8cd0
 
epi editorial commitee meeting presentation
MIPLM
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
I3PM Case study smart parking 2025 with uptoIP® and ABP
MIPLM
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Lean IP - Lecture by Dr Oliver Baldus at the MIPLM 2025
MIPLM
 
Lesson 1 Cell (Structures, Functions, and Theory).pptx
marvinnbustamante1
 
ENG8_Q1_WEEK2_LESSON1. Presentation pptx
marawehsvinetshe
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 

Accessible custom radio buttons and checkboxes