Skip to content

Instantly share code, notes, and snippets.

@anied
Created June 18, 2021 02:55
Show Gist options
  • Select an option

  • Save anied/d8d8ed838210e5ed9c9c9bc4e6468b9e to your computer and use it in GitHub Desktop.

Select an option

Save anied/d8d8ed838210e5ed9c9c9bc4e6468b9e to your computer and use it in GitHub Desktop.
Example of a custom checkbox with _no_ consideration for proper accessibility.
.hide {
display: none;
}
.checkbox-wrapper {
display: flex;
}
#custom-subscribe {
display: inline-block;
border: 1px solid black;
height: 1rem;
width: 1rem;
margin-left: 0.5rem;
display: flex;
align-items: center;
justify-content: center;
}
#custom-subscribe-checkmark {
color: green;
}
<div class="checkbox-wrapper">
<span id="custom-subscribe-label">Subscribe to custom newsletter</span>
<span id="custom-subscribe">
<span id="custom-subscribe-checkmark" class="hide">✔</span>
</span>
</div>
const checkbox = document.querySelector("#custom-subscribe");
const checkmark = document.querySelector("#custom-subscribe-checkmark");
function toggleCustomSubscribe() {
checkmark.classList.toggle("hide");
}
checkbox.addEventListener("click", toggleCustomSubscribe);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment