Advanced Search Usage Terms Submit Contact
Dynamic Drive CSS Library
 
CSS Library

Advertise Here

CSS Layouts
Web Graphics
Online Tools:

CSS Library: Form CSS: CSS3 demos: Here

CSS3 checkbox and radio button replacements

Author: Dynamic Drive

By hiding the default INPUT element of a checkbox/ radio button and styling its associated LABEL element instead, checkboxes and radio buttons can take on an entirely new look while maintaining their functionality inside a form. The following demonstrates just that. The custom checkbox and radio buttons you see are actually label elements richly styled with the help of CSS2 ::before and ::after generated content and the usual dose of CSS3 transition, shadows etc. When the form is submitted, each selected checkbox or radio value will be passed along like with their regular counterparts.

Demo:

The CSS:

Note: The check mark seen inside the checkbox replacement is a CSS icon font from Font Awesome. We specify the unicode of the desired font symbol inside our CSS to show it, in this case, a check mark:

label.toggler::after{ /* check mark */
content: '\f00c'; /* fontAwesome icon font unicode. See http://fortawesome.github.io/Font-Awesome/cheatsheet/ for others */
position:absolute;
left: 3px;
top: 3px;
font: bold 18px FontAwesome;
color: #1B4977;
width: 0; /* hide check mark initially */
text-shadow: 0 0 2px #eee;
overflow: hidden;
}

 Click here to see the full list of Font Awesome's font unicode values.

The HTML:

Code Info

Rate this code:

Date Posted: 09/29/2014

Revision History: None

Usage Terms: Click here

Your Comments (0)

Got a question or need help customizing this CSS code? Post it in the CSS Forums. If you have a comment or suggestion instead, post it in the comments section below.


Copyright 2006-2014 Dynamic Drive Read our Usage Terms before using any of the CSS codes.