Toggle checkbox

by kuonyuu

HTML

<input type="checkbox" id="switch" /><label for="switch">Toggle</label>

CSS

input[type=checkbox]{
	height: 0;
	width: 0;
	visibility: hidden;
	margin: 0;
	display: none;
}

label {
	cursor: pointer;
	text-indent: -9999px;
	width: 40px;
	height: 20px;
	background: grey;
	display: block;
	border-radius: 100px;
	position: relative;
}

label:after {
	content: '';
	position: absolute;
	top: 2px;
	left: 2px;
	width: 16px;
	height: 16px;
	background: #fff;
	border-radius: 50%;
	transition: 0.3s;
}

input:checked + label {
	background: #bada55;
}

input:checked + label:after {
	left: calc(100% - 2px);
	transform: translateX(-100%);
}

label:active:after {
	width: 30px;
}

// centering
body {
	/* display: flex; */
	/* justify-content: center; */
	/* align-items: center; */
	/* height: 100vh; */
}