Custom Checkbox in Webkit with CSS3

While exploring possibilities of Webkit engine I decided to see if it is possible to create custom checkbox without any additional markup or javascript.

After a little bit of research I came across a special css property -webkit-appearance that controls default rendering styles for the elements in Webkit. If you set it to none you essitially get a blank slate in terms of visual appearence of an element. After that it was very straightforward with the exception of tick itself. Since I didn't want to use any images or extra markup I used rotated 45 deg ::after pseudo-element with left and right borders composing sides of the tick. Here's final code:

input[type=checkbox] {
  font-size: 16px;
  position: relative;
  border: 1px solid #262626;
  display: inline-block;
  line-height: 1em;
  margin: 0;
  padding: 0;
  width: 1em;
  height: 1em;
  vertical-align: text-top;
  background: -webkit-linear-gradient(
    top, rgba(255,255,255,0.4), rgba(255,255,255,0.1)
  -webkit-appearance: none;
  -webkit-box-shadow: 0 1px 0 rgba(255,255,255, 0.1),
                      inset 0 0 1px rgba(255,255,255, 0.4);
  -webkit-border-radius: 3px;

input[type=checkbox]:active {
  background: -webkit-linear-gradient(
    top, rgba(255,255,255,0.05), rgba(255,255,255,0.2)

input[type=checkbox]:checked::after {
  position: absolute;
  content: '';
  left: 15%;
  top: -10%;
  height: 40%;
  width: 90%;
  border-bottom: 2px solid #fff;
  border-left: 2px solid #fff;
  -webkit-box-shadow: -1px 1px 0 rgba(0,0,0,0.8);
  -webkit-transform: rotate(-45deg);

Demo page.

Social comments Cackle