On this page you will learn how to create cool iPhone toggle checkboxes and radio buttons with CSS3, minimal, semantic and accessible markup and no JavaScript at all.
Really, all you need is markup like this:
<div class="iphone-toggle-buttons"> <ul> <li><label for="checkbox-0"><input type="checkbox" name="checkbox-0" id="checkbox-0" /><span>checkbox 0</span></label></li> <li><label for="checkbox-1"><input type="checkbox" name="checkbox-1" id="checkbox-1" checked="checked" /><span>checkbox 1</span></label></li> </ul> </div>
… And the rest will be done with the magic of CSS3′s generated content, attribute selectors and gradients.
Supported browsers:
- Mozilla FireFox
- Opera
- Google Chrome
- Apple Safari
- Internet Explorer 9 (not fully supported)
- Internet Explorer 10 Beta
Older browsers that do not support CSS generated content, gradients and attribute selectors fall back nicely showing the normal checkboxes and radio buttons.
Go and check it out here… Find more experiments here.
Related Posts
- CSS3 Treeview. No JavaScript.
- HTML5 Resume Generator and Onepager Website
- CSS3 Driven Slides Viewer Without any JavaScript
- Fully Functional CSS3-only Tabstrip Without JavaScript
- Imageless CSS3 Custom Checkboxes and Radio Buttons
- Creating Gaussian Blur Effect With CSS3
- Selecting only the first element occurence out of siblings with the same class name with CSS3
- CSS3 Element Reflections
- Fancy CSS3 Toolips (Yeah, Without Any JavaScript)
- CSS3 Background Image Cropping

[...] = "#000000"; google_color_url = "#3399FF"; google_ui_features = "rc:0"; Source: http://acidmartin.wordpress.com/2011/06/18/css3-iphone-toggle-buttons/ Tags: blue, buttons, checkboxes, css, css3, [...]
Technically the switch control in iOS is the same as a checkbox. It’s therefore wrong to use it as a radio button group. For that iOS provides the selection list, which is a type of tableview whose cells display a check mark when selected. Only one cell of the tableview can be selected.
Hi Robert, technically you are right, but the idea of the blogpost was to demonstrate that this approach could be used both with check boxes and radio buttons.
[...] CSS3 iPhone Toggle Buttons [...]
[...] CSS3 iPhone Toggle Buttons [...]
[...] CSS3 iPhone Toggle Buttons New website for Acid.JS Web UI [...]
[...] CSS3 iPhone Toggle Buttons [...]
[...] CSS3 iPhone Toggle Buttons [...]
[...] CSS3 iPhone Toggle Buttons [...]
[...] CSS3 iPhone Toggle Buttons [...]
[...] CSS3 iPhone Toggle Buttons [...]
[...] CSS3 iPhone Toggle Buttons [...]
Thanks, great post! Can you tell me how you managed to prevent a fast double-click to “select” the text? I’ve been trying to implement a CSS toggle button myself and it behaves OK except for the text being selected as I switch quickly from ON to OFF. Any tips? Thanks.
Thank you very much, Alain – I am glad you like the post. Regarding your question – a very easy way to disable selection is to apply user-select: none; to the element you want to set as unselectable. You should use -moz-user-select: none for Firefox and -webkit-user-select: none for Chrome, for example:
.element
{
-moz-user-select: none;
-webkit-user-select: none;
user-select: none;
}
Internet Explorer does not support this property, but you can apply the unselectable=”on” attribute to the same element – it works the same as user-select:
<div unselectable=”on”></div>
Thanks! Worked like a charm. :)
Glad I could help! Merry Christmas!
[...] CSS3 iPhone Toggle Buttons [...]
[...] CSS3 iPhone Toggle Buttons [...]
[...] CSS3 iPhone Toggle Buttons [...]
[...] CSS3 iPhone Toggle Buttons [...]
[...] CSS3 iPhone Toggle Buttons [...]
[...] CSS3 iPhone Toggle Buttons [...]
[...] #iPhone toggle buttons acidmartin.wordpress.com/2011/06/18/css… #html5 #css #js #javascript #jquery #developers #svg #html #xhtml #devtools [...]
[...] CSS3 iPhone Toggle Buttons [...]
[...] CSS3 iPhone Toggle Buttons [...]
[...] CSS3 iPhone Toggle Buttons [...]