Skip to main content
added 313 characters in body
Source Link
Jan Turoň
  • 33.1k
  • 24
  • 139
  • 179

I'd followI'd follow the advice of SW4's answer. Not anymore: Volomike's answer is far superior to all the advice ofanswers here SW4's answer(note my suggested improvement in the comment to the answer). Proceed reading this answer if you are curious about alternative approaches, which this answer comments.


First of all, hide the checkbox and to cover it with a custom span, suggesting this HTML:

I'd follow the advice of SW4's answer to hide the checkbox and to cover it with a custom span, suggesting this HTML:

I'd follow the advice of SW4's answer. Not anymore: Volomike's answer is far superior to all the answers here (note my suggested improvement in the comment to the answer). Proceed reading this answer if you are curious about alternative approaches, which this answer comments.


First of all, hide the checkbox and to cover it with a custom span, suggesting this HTML:

added 2 characters in body
Source Link
Jan Turoň
  • 33.1k
  • 24
  • 139
  • 179

Do not hide it using visibility: hidden or display: none

Do not hide it using visibility: hidden or display: none

Test it on JS Fiddle

Test it on JS Fiddle

Do not hide it using visibility: hidden or display: none

Test it on JS Fiddle

Do not hide it using visibility: hidden or display: none

Test it on JS Fiddle

safari-only style link added
Source Link
Jan Turoň
  • 33.1k
  • 24
  • 139
  • 179

#Do not hide it using visibility: hidden or display: none

Do not hide it using visibility: hidden or display: none

  1. Add focus outline

     input[type="checkbox"]:focus + span:before { outline: 1px dotted #aaa; } 

    Safari doesn't provide this feature (see @Jason Sankey's comment), you should usesee window.navigator to detect the browser and skip it if it isthis answer for Safari.-only CSS

  2. Set gray color for disabled checkbox

     input[type="checkbox"]:disabled + span { color: #999; } 
  3. Set hover shadow on non-disabled checkbox

     input[type="checkbox"]:not(:disabled) + span:hover:before { text-shadow: 0 1px 2px #77F; } 

#Demo Fiddle


Test it on JS Fiddle

#Do not hide it using visibility: hidden or display: none

  1. Add focus outline

     input[type="checkbox"]:focus + span:before { outline: 1px dotted #aaa; } 

    Safari doesn't provide this feature (see @Jason Sankey's comment), you should use window.navigator to detect the browser and skip it if it is Safari.

  2. Set gray color for disabled checkbox

     input[type="checkbox"]:disabled + span { color: #999; } 
  3. Set hover shadow on non-disabled checkbox

     input[type="checkbox"]:not(:disabled) + span:hover:before { text-shadow: 0 1px 2px #77F; } 

#Demo Fiddle

Do not hide it using visibility: hidden or display: none

  1. Add focus outline

     input[type="checkbox"]:focus + span:before { outline: 1px dotted #aaa; } 

    Safari doesn't provide this feature (see @Jason Sankey's comment), see this answer for Safari-only CSS

  2. Set gray color for disabled checkbox

     input[type="checkbox"]:disabled + span { color: #999; } 
  3. Set hover shadow on non-disabled checkbox

     input[type="checkbox"]:not(:disabled) + span:hover:before { text-shadow: 0 1px 2px #77F; } 

Test it on JS Fiddle

Active reading. Applied some formatting (as a result the diff looks more extensive than it really is - use view "side-by-side markdown" to compare).
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134
Loading
removed broken snippet
Source Link
Jan Turoň
  • 33.1k
  • 24
  • 139
  • 179
Loading
Added syntax highlighting for CSS, improved formatting.
Source Link
Vadim Ovchinnikov
  • 14.1k
  • 7
  • 68
  • 95
Loading
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot
Loading
Jason's comment integrated.
Source Link
Jan Turoň
  • 33.1k
  • 24
  • 139
  • 179
Loading
added 231 characters in body
Source Link
Jan Turoň
  • 33.1k
  • 24
  • 139
  • 179
Loading
deleted 11 characters in body
Source Link
Jan Turoň
  • 33.1k
  • 24
  • 139
  • 179
Loading
Source Link
Jan Turoň
  • 33.1k
  • 24
  • 139
  • 179
Loading