Align label left of toggle switch
See CSS overrides in the HTML panel.
.switch {
/* Finetune the switch */
--height: 18px;
--width: 40px;
--border: 2px;
--font-size: 1em;
--switch-color-checked: #1795fe;
--switch-color-unchecked: gray;
--dot-color-checked: white;
--dot-color-unchecked: white;
font-size: var(--size);
}
.switch label {
display: block;
position: relative;
cursor: pointer;
padding-left: calc(var(--width) + 1em);
min-width: var(--width);
min-height: var(--height);
/* Switch Background */
/* Dot */
}
.switch label::before,
.switch label::after {
content: "";
position: absolute;
top: 0;
left: 0;
transition: 0.25s ease-in-out;
box-sizing: border-box;
}
.switch label::before {
z-index: 1;
background-color: var(--switch-color-unchecked);
width: var(--width);
height: var(--height);
border-radius: calc(var(--height) * 0.5);
}
.switch label::after {
z-index: 2;
background-color: var(--dot-color-unchecked);
height: calc(var(--height) - (var(--border) * 2));
width: calc(var(--height) - (var(--border) * 2));
transform: translate(var(--border), var(--border));
border-radius: calc(var(--height) / 2);
}
.switch input {
width: 0;
height: 0;
visibility: hidden;
display: none;
}
.switch input:checked+label::before {
transition: 0.5s;
background-color: var(--switch-color-checked);
}
.switch input:checked+label::after {
transform: translate(calc(var(--width) - 100% - var(--border)), var(--border));
background-color: var(--dot-color-checked);
}
<style>
/* overrides to be included in your custom stylesheet */
.switch.align-left label {
display: flex;
padding-left: 0;
}
.switch.align-left label::before,
.switch.align-left label::after {
position: relative;
order: 2; /* could technically be 1, but this is more intuitive */
margin-left: 8px;
}
.switch.align-left label::after {
margin-left: -40px;
}
</style>
<div class="switch align-left">
<input id="switch__input" type="checkbox">
<label for="switch__input">
I am a label that wants to be on the left
</label>
</div>
.switch {
/* Finetune the switch */
--height: 18px;
--width: 40px;
--border: 2px;
--font-size: 1em;
--switch-color-checked: #1795fe;
--switch-color-unchecked: gray;
--dot-color-checked: white;
--dot-color-unchecked: white;
font-size: var(--size);
}
.switch label {
cursor: pointer;
display: flex;
gap: 0.5rem;
}
.switch label span {
display: inline-block;
position: relative;
cursor: pointer;
min-width: var(--width);
min-height: var(--height);
/* Switch Background */
/* Dot */
}
.switch label span::before,
.switch label span::after {
position: absolute;
top: 0;
left: 0;
display: inline-block;
content: "";
transition: 0.25s ease-in-out;
box-sizing: border-box;
}
.switch label span::before {
z-index: 1;
background-color: var(--switch-color-unchecked);
width: var(--width);
height: var(--height);
border-radius: calc(var(--height) * 0.5);
}
.switch label span::after {
z-index: 2;
background-color: var(--dot-color-unchecked);
height: calc(var(--height) - (var(--border) * 2));
width: calc(var(--height) - (var(--border) * 2));
transform: translate(var(--border), var(--border));
border-radius: calc(var(--height) / 2);
}
.switch input {
width: 0;
height: 0;
visibility: hidden;
display: none;
}
.switch input:checked+label span::before {
background: #f00;
transition: 0.5s;
background-color: var(--switch-color-checked);
}
.switch input:checked+label span::after {
transform: translate(calc(var(--width) - 100% - var(--border)), var(--border));
background-color: var(--dot-color-checked);
}
<div class="switch">
<input id="switch__input" type="checkbox">
<label for="switch__input">
I am a label that wants to be on the left<span></span>
</label>
</div>
I added an extra span to the label and made it look like a radio button. To view the source, refer the Codepen.