Skip to content

Instantly share code, notes, and snippets.

@ihorduchenko
Created September 18, 2021 20:53
Show Gist options
  • Save ihorduchenko/0000f0189cd7822d5c37ad35c6d51c4c to your computer and use it in GitHub Desktop.
Save ihorduchenko/0000f0189cd7822d5c37ad35c6d51c4c to your computer and use it in GitHub Desktop.
Create custom checkbox
<label for="custom-checkbox" class="custom-checkbox">
<input id="custom-checkbox" type="checkbox" name="custom_checkbox">
<span>Custom checkbox</span>
</label>
<style>
.custom-checkbox > input[type=checkbox] {
opacity: 0;
cursor: pointer;
position: absolute;
}
.custom-checkbox > span {
display: block;
position: relative;
padding-left: 1.5em;
line-height: 1.3;
}
.custom-checkbox > span:before,
.custom-checkbox > span:after {
content: '';
position: absolute;
}
.custom-checkbox > span:before {
left: 0;
top: 0;
width: 1.3em;
height: 1.3em;
border: 1px solid currentColor;
border-radius: 3px;
}
.custom-checkbox > span:after {
opacity: 0;
width: 0.7em;
height: 0.4em;
border-left: 2px solid #fff;
border-bottom: 2px solid #fff;
left: 0.3em;
top: 0.3em;
transform: rotate(-45deg);
}
.custom-checkbox > input[type=checkbox]:checked + span:before {
background-color: currentColor;
}
.custom-checkbox > input[type=checkbox]:checked + span:after {
opacity: 1;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment