

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.xiaoji-offscreen{
display: none;
}
.xiaoji-switch{
position: relative;
display: inline-block;
width: 40px;
height: 20px;
background-color: #ccc;
border-radius: 20px;
transition: all 0.3s;
}
.xiaoji-switch::after{
content: "";
position: absolute;
width: 18px;
height: 18px;
border-radius: 18px;
background-color: #fff;
top: 1px;
left: 1px;
transition: all 0.3s;
}
input[type="checkbox"]:checked+.xiaoji-switch::after{
transform: translateX(20px);
}
input[type="checkbox"]:checked+.xiaoji-switch{
background-color: #7983ff;
}
</style>
</head>
<body>
<form>
<input type="checkbox" name="" id="toggle" class="xiaoji-offscreen">
<label for="toggle" class="xiaoji-switch"></label>
</form>
</body>
</html>