Can I change the checkbox size using CSS? - html

Is it possible to set the size of a checkbox using CSS or HTML across browsers?
width and size work in IE6+, but not with Firefox, where the checkbox stays 16x16 even if I set a smaller size.

It's a little ugly (due to the scaling up), but it works on most newer browsers:
input[type=checkbox]
{
/* Double-sized Checkboxes */
-ms-transform: scale(2); /* IE */
-moz-transform: scale(2); /* FF */
-webkit-transform: scale(2); /* Safari and Chrome */
-o-transform: scale(2); /* Opera */
transform: scale(2);
padding: 10px;
}
/* Might want to wrap a span around your checkbox text */
.checkboxtext
{
/* Checkbox text */
font-size: 110%;
display: inline;
}
<input type="checkbox" name="optiona" id="opta" checked />
<span class="checkboxtext">
Option A
</span>
<input type="checkbox" name="optionb" id="optb" />
<span class="checkboxtext">
Option B
</span>
<input type="checkbox" name="optionc" id="optc" />
<span class="checkboxtext">
Option C
</span>

Working solution for all modern browsers.
input[type=checkbox] {
transform: scale(1.5);
}
<label><input type="checkbox"> Test</label>
Compatibility:
IE: 10+
FF: 16+
Chrome: 36+
Safari: 9+
Opera: 23+
iOS Safari: 9.2+
Chrome for Android: 51+
Appearance:
Chrome 58 (May 2017), Windows 10

An easy solution is use the property zoom:
input[type="checkbox"] {
zoom: 1.5;
}
<input type="checkbox" />

2020 version - using pseudo-elements, size depends on font size.
Default checkbox/radio is rendered outside of screen, but CSS creates virtual elements very similar to default elements. Supports all browsers, no blur. Size depends on font size. Keyboard actions (space, tabs) are also supported.
https://jsfiddle.net/ohf7nmzy/2/
body{
padding:0 20px;
}
.big{
font-size: 50px;
}
/* CSS below will force radio/checkbox size be same as font size */
label{
position: relative;
line-height: 1.4;
}
/* radio */
input[type=radio]{
width: 1em;
font-size: inherit;
margin: 0;
transform: translateX(-9999px);
}
input[type=radio] + label:before{
position: absolute;
content: '';
left: -1.3em;
top: 0;
width: 1em;
height: 1em;
margin: 0;
border:none;
border-radius: 50%;
background-color: #bbbbbb;
}
input[type=radio] + label:after{
position: absolute;
content: '';
left: -1.3em;
top: 0;
width: 1em;
height: 1em;
margin: 0;
border: none;
background-color: white;
border-radius: 50%;
transform: scale(0.8);
}
/*checked*/
input[type=radio]:checked + label:before{
position:absolute;
content:'';
left: -1.3em;
top: 0;
width: 1em;
height: 1em;
margin: 0;
border: none;
background-color: #3b88fd;
}
input[type=radio]:checked + label:after{
position: absolute;
content: '';
left: -1.3em;
top: 0;
width: 1em;
height: 1em;
margin: 0;
border: none;
background-color: white;
border-radius: 50%;
transform: scale(0.3);
}
/*focused*/
input[type=radio]:focus + label:before{
border: 0.2em solid #8eb9fb;
margin-top: -0.2em;
margin-left: -0.2em;
box-shadow: 0 0 0.3em #3b88fd;
}
/*checkbox/*/
input[type=checkbox]{
width: 1em;
font-size: inherit;
margin: 0;
transform: translateX(-9999px);
}
input[type=checkbox] + label:before{
position: absolute;
content: '';
left: -1.3em;
top: 0;
width: 1em;
height: 1em;
margin: 0;
border:none;
border-radius: 10%;
background-color: #bbbbbb;
}
input[type=checkbox] + label:after{
position: absolute;
content: '';
left: -1.3em;
top: 0;
width: 1em;
height: 1em;
margin: 0;
border: none;
background-color: white;
border-radius: 10%;
transform: scale(0.8);
}
/*checked*/
input[type=checkbox]:checked + label:before{
position:absolute;
content:'';
left: -1.3em;
top: 0;
width: 1em;
height: 1em;
margin: 0;
border: none;
background-color: #3b88fd;
}
input[type=checkbox]:checked + label:after{
position: absolute;
content: "\2713";
left: -1.3em;
top: 0;
width: 1em;
height: 1em;
margin: 0;
border: none;
background-color: #3b88fd;
border-radius: 10%;
color: white;
text-align: center;
line-height: 1;
}
/*focused*/
input[type=checkbox]:focus + label:before{
border: 0.1em solid #8eb9fb;
margin-top: -0.1em;
margin-left: -0.1em;
box-shadow: 0 0 0.2em #3b88fd;
}
<input type="checkbox" name="checkbox_1" id="ee" checked />
<label for="ee">Checkbox small</label>
<br />
<input type="checkbox" name="checkbox_2" id="ff" />
<label for="ff">Checkbox small</label>
<hr />
<div class="big">
<input type="checkbox" name="checkbox_3" id="gg" checked />
<label for="gg">Checkbox big</label>
<br />
<input type="checkbox" name="checkbox_4" id="hh" />
<label for="hh">Checkbox big</label>
</div>
<hr />
<input type="radio" name="radio_1" id="aa" value="1" checked />
<label for="aa">Radio small</label>
<br />
<input type="radio" name="radio_1" id="bb" value="2" />
<label for="bb">Radio small</label>
<hr />
<div class="big">
<input type="radio" name="radio_2" id="cc" value="1" checked />
<label for="cc">Radio big</label>
<br />
<input type="radio" name="radio_2" id="dd" value="2" />
<label for="dd">Radio big</label>
</div>
2017 version - using zoom or scale
Browser will use non-standard zoom feature if it is supported (nice quality) or standard transform: scale (blurry on Safari) as fallback.
https://jsfiddle.net/ksvx2txb/11/
#supports (zoom:2) {
input[type="radio"], input[type=checkbox]{
zoom: 2;
}
}
#supports not (zoom:2) {
input[type="radio"], input[type=checkbox]{
transform: scale(2);
margin: 15px;
}
}
label{
/* fix vertical align issues */
display: inline-block;
vertical-align: top;
margin-top: 10px;
}
<input type="radio" name="aa" value="1" id="aa" checked />
<label for="aa">Radio 1</label>
<br />
<input type="radio" name="aa" value="2" id="bb" />
<label for="bb">Radio 2</label>
<br /><br />
<input type="checkbox" name="optiona" id="cc" checked />
<label for="cc">Checkbox 1</label>
<br />
<input type="checkbox" name="optiona" id="dd" />
<label for="dd">Checkbox 1</label>

I just came out with this:
input[type="checkbox"] {display:none;}
input[type="checkbox"] + label:before {content:"☐";}
input:checked + label:before {content:"☑";}
label:hover {color:blue;}
<input id="check" type="checkbox" /><label for="check">Checkbox</label>
Of course, thanks to this, you can change the value of content to your needs and use an image if you wish or use another font...
The main interest here is that:
The checkbox size stays proportional to the text size
You can control the aspect, the color, the size of the checkbox
No extra HTML needed !
Only 3 lines of CSS needed (the last one is just to give you ideas)
Edit:
As pointed out in the comment, the checkbox won't be accessible by key navigation. You should probably add tabindex=0 as a property for your label to make it focusable.

Preview:
http://jsfiddle.net/h4qka9td/
*,*:after,*:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 0;
margin: 0;
}
.switch {
margin: 50px auto;
position: relative;
}
.switch label {
width: 100%;
height: 100%;
position: relative;
display: block;
}
.switch input {
top: 0;
right: 0;
bottom: 0;
left: 0;
opacity: 0;
z-index: 100;
position: absolute;
width: 100%;
height: 100%;
cursor: pointer;
}
/* DEMO 3 */
.switch.demo3 {
width: 180px;
height: 50px;
}
.switch.demo3 label {
display: block;
width: 100%;
height: 100%;
background: #a5a39d;
border-radius: 40px;
box-shadow:
inset 0 3px 8px 1px rgba(0,0,0,0.2),
0 1px 0 rgba(255,255,255,0.5);
}
.switch.demo3 label:after {
content: "";
position: absolute;
z-index: -1;
top: -8px; right: -8px; bottom: -8px; left: -8px;
border-radius: inherit;
background: #ababab;
background: -moz-linear-gradient(#f2f2f2, #ababab);
background: -ms-linear-gradient(#f2f2f2, #ababab);
background: -o-linear-gradient(#f2f2f2, #ababab);
background: -webkit-gradient(linear, 0 0, 0 100%, from(#f2f2f2), to(#ababab));
background: -webkit-linear-gradient(#f2f2f2, #ababab);
background: linear-gradient(#f2f2f2, #ababab);
box-shadow: 0 0 10px rgba(0,0,0,0.3),
0 1px 1px rgba(0,0,0,0.25);
}
.switch.demo3 label:before {
content: "";
position: absolute;
z-index: -1;
top: -18px; right: -18px; bottom: -18px; left: -18px;
border-radius: inherit;
background: #eee;
background: -moz-linear-gradient(#e5e7e6, #eee);
background: -ms-linear-gradient(#e5e7e6, #eee);
background: -o-linear-gradient(#e5e7e6, #eee);
background: -webkit-gradient(linear, 0 0, 0 100%, from(#e5e7e6), to(#eee));
background: -webkit-linear-gradient(#e5e7e6, #eee);
background: linear-gradient(#e5e7e6, #eee);
box-shadow:
0 1px 0 rgba(255,255,255,0.5);
-webkit-filter: blur(1px);
-moz-filter: blur(1px);
-ms-filter: blur(1px);
-o-filter: blur(1px);
filter: blur(1px);
}
.switch.demo3 label i {
display: block;
height: 100%;
width: 60%;
border-radius: inherit;
background: silver;
position: absolute;
z-index: 2;
right: 40%;
top: 0;
background: #b2ac9e;
background: -moz-linear-gradient(#f7f2f6, #b2ac9e);
background: -ms-linear-gradient(#f7f2f6, #b2ac9e);
background: -o-linear-gradient(#f7f2f6, #b2ac9e);
background: -webkit-gradient(linear, 0 0, 0 100%, from(#f7f2f6), to(#b2ac9e));
background: -webkit-linear-gradient(#f7f2f6, #b2ac9e);
background: linear-gradient(#f7f2f6, #b2ac9e);
box-shadow:
inset 0 1px 0 white,
0 0 8px rgba(0,0,0,0.3),
0 5px 5px rgba(0,0,0,0.2);
}
.switch.demo3 label i:after {
content: "";
position: absolute;
left: 15%;
top: 25%;
width: 70%;
height: 50%;
background: #d2cbc3;
background: -moz-linear-gradient(#cbc7bc, #d2cbc3);
background: -ms-linear-gradient(#cbc7bc, #d2cbc3);
background: -o-linear-gradient(#cbc7bc, #d2cbc3);
background: -webkit-gradient(linear, 0 0, 0 100%, from(#cbc7bc), to(#d2cbc3));
background: -webkit-linear-gradient(#cbc7bc, #d2cbc3);
background: linear-gradient(#cbc7bc, #d2cbc3);
border-radius: inherit;
}
.switch.demo3 label i:before {
content: "off";
text-transform: uppercase;
font-style: normal;
font-weight: bold;
color: rgba(0,0,0,0.4);
text-shadow: 0 1px 0 #bcb8ae, 0 -1px 0 #97958e;
font-family: Helvetica, Arial, sans-serif;
font-size: 24px;
position: absolute;
top: 50%;
margin-top: -12px;
right: -50%;
}
.switch.demo3 input:checked ~ label {
background: #9abb82;
}
.switch.demo3 input:checked ~ label i {
right: -1%;
}
.switch.demo3 input:checked ~ label i:before {
content: "on";
right: 115%;
color: #82a06a;
text-shadow:
0 1px 0 #afcb9b,
0 -1px 0 #6b8659;
}
<div class="switch demo3">
<input type="checkbox">
<label><i></i>
</label>
</div>
<div class="switch demo3">
<input type="checkbox" checked>
<label><i></i>
</label>
</div>

The appearance of checkboxes seems to be fixed by default. But as pointed out by Worthy7 this can be remedied using CSS appearance property. It will make checkboxes completely empty, so you can define your own appearance. What is nice about this: You can use your existing HTML code. Downside: It is experimental technology. Edge (legacy) and IE do not use the custom style.
Here are the needed CSS styles:
input[type=checkbox] {
width: 14mm;
-webkit-appearance: none;
-moz-appearance: none;
height: 14mm;
border: 0.1mm solid black;
}
input[type=checkbox]:checked {
background-color: lightblue;
}
input[type=checkbox]:checked:after {
margin-left: 4.3mm;
margin-top: -0.4mm;
width: 3mm;
height: 10mm;
border: solid white;
border-width: 0 2mm 2mm 0;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
content: "";
display: inline-block;
}
<label><input type="checkbox"> Test</label>
Screenshots:
Chrome:
Firefox:
Edge:
Edge (legacy):
IE:

I think the simplest solution is re-style the checkbox as some users suggest. The CSS below is working for me, only requires a few lines of CSS, and answers the OP question:
input[type=checkbox] {
-webkit-appearance: none;
-moz-appearance: none;
vertical-align: middle;
width: 14px;
height: 14px;
font-size: 14px;
background-color: #eee;
}
input[type=checkbox]:checked:after {
position: relative;
bottom: 3px;
left: 1px;
color: blue;
content: "\2713"; /* check mark */
}
As mentioned in this post, the zoom property seems not to work on Firefox, and transforms may cause undesired effects.
Tested on Chrome and Firefox, should work for all modern browsers. Just change the properties (colors, size, bottom, left, etc.) to your needs. Hope it helps!

This should work
input {
width: 25px;
height: 25px;
}
It worked for me for Firefox and Chrome and iPhone's Firefox, Chrome and Safari at least.

I was looking to make a checkbox that was just a little bit larger and looked at the source code for 37Signals Basecamp to find the following solution-
You can change the font size to make the checkbox slightly larger:
font-size: x-large;
Then, you can align the checkbox properly by doing:
vertical-align: top;
margin-top: 3px; /* change to center it */

You can make checkboxes larger in Safari — which is generally resistant to the usual approaches — with this attribute: -webkit-transform: scale(1.3, 1.3);
Source

My reputation is slightly too low to post comments, but I made a modification to Jack Miller's code above in order to get it to not change size when you check and uncheck it. This was causing text alignment problems for me.
input[type=checkbox] {
width: 17px;
-webkit-appearance: none;
-moz-appearance: none;
height: 17px;
border: 1px solid black;
}
input[type=checkbox]:checked {
background-color: #F58027;
}
input[type=checkbox]:checked:after {
margin-left: 4px;
margin-top: -1px;
width: 4px;
height: 12px;
border: solid white;
border-width: 0 2px 2px 0;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
content: "";
display: inline-block;
}
input[type=checkbox]:after {
margin-left: 4px;
margin-top: -1px;
width: 4px;
height: 12px;
border: solid white;
border-width: 0;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
content: "";
display: inline-block;
}
<label><input type="checkbox"> Test</label>

My understanding is that this isn't easy at all to do cross-browser. Instead of trying to manipulate the checkbox control, you could always build your own implementation using images, javascript, and hidden input fields. I'm assuming this is similar to what niceforms is (from Staicu lonut's answer above), but wouldn't be particularly difficult to implement. I believe jQuery has a plugin to allow for this custom behavior as well (will look for the link and post here if I can find it).

I found this CSS-only library to be very helpful:
https://lokesh-coder.github.io/pretty-checkbox/
Or, you could roll your own with this same basic concept, similar to what #Sharcoux posted. It's basically:
Hide the normal checkbox (opacity 0 and placed where it would go)
Add a css-based fake checkbox
Use input:checked~div label for the checked style
make sure your <label> is clickable using for=yourinputID
.pretty {
position: relative;
margin: 1em;
}
.pretty input {
position: absolute;
left: 0;
top: 0;
min-width: 1em;
width: 100%;
height: 100%;
z-index: 2;
opacity: 0;
margin: 0;
padding: 0;
cursor: pointer;
}
.pretty-inner {
box-sizing: border-box;
position: relative;
}
.pretty-inner label {
position: initial;
display: inline-block;
font-weight: 400;
margin: 0;
text-indent: 1.5em;
min-width: calc(1em + 2px);
}
.pretty-inner label:after,
.pretty-inner label:before {
content: '';
width: calc(1em + 2px);
height: calc(1em + 2px);
display: block;
box-sizing: border-box;
border-radius: 0;
border: 1px solid transparent;
z-index: 0;
position: absolute;
left: 0;
top: 0;
background-color: transparent;
}
.pretty-inner label:before {
border-color: #bdc3c7;
}
.pretty input:checked~.pretty-inner label:after {
background-color: #00bb82;
width: calc(1em - 6px);
height: calc(1em - 6px);
top: 4px;
left: 4px;
}
/* Add checkmark character style */
.pretty input:checked~.pretty-inner.checkmark:after {
content: '\2713';
color: #fff;
position: absolute;
font-size: 0.65em;
left: 6px;
top: 3px;
}
body {
font-size: 20px;
font-family: sans-serif;
}
<div class="pretty">
<input type="checkbox" id="demo" name="demo">
<div class="pretty-inner"><label for="demo">I agree.</label></div>
</div>
<div class="pretty">
<input type="checkbox" id="demo" name="demo">
<div class="pretty-inner checkmark"><label for="demo">Please check the box.</label></div>
</div>

use this css code
input[type=checkbox]
{
/* Double-sized Checkboxes */
-ms-transform: scale(1.5); /* IE */
-moz-transform: scale(1.5); /* FF */
-webkit-transform: scale(1.5); /* Safari and Chrome */
-o-transform: scale(1.5); /* Opera */
transform: scale(1.5);
padding: 10px;
}

The problem is Firefox doesn't listen to width and height. Disable that and your good to go.
input[type=checkbox] {
width: 25px;
height: 25px;
-moz-appearance: none;
}
<label><input type="checkbox"> Test</label>

The other answers showed a pixelated checkbox, while I wanted something beautiful.
The result looks like this:
Even though this version is more complicated I think it's worth giving it a try.
.checkbox-list__item {
position: relative;
padding: 10px 0;
display: block;
cursor: pointer;
margin: 0 0 0 34px;
border-bottom: 1px solid #b4bcc2;
}
.checkbox-list__item:last-of-type {
border-bottom: 0;
}
.checkbox-list__check {
width: 18px;
height: 18px;
border: 3px solid #b4bcc2;
position: absolute;
left: -34px;
top: 50%;
margin-top: -12px;
transition: border .3s ease;
border-radius: 5px;
}
.checkbox-list__check:before {
position: absolute;
display: block;
width: 18px;
height: 22px;
top: -2px;
left: 0px;
padding-left: 2px;
background-color: transparent;
transition: background-color .3s ease;
content: '\2713';
font-family: initial;
font-size: 19px;
color: white;
}
input[type="checkbox"]:checked ~ .checkbox-list__check {
border-color: #5bc0de;
}
input[type="checkbox"]:checked ~ .checkbox-list__check:before {
background-color: #5bc0de;
}
<label class="checkbox-list__item">
<input class="checkbox_buttons" type="checkbox" checked="checked" style="display: none;">
<div class="checkbox-list__check"></div>
</label>
JSFiddle: https://jsfiddle.net/asbd4hpr/

You can change the height and width in the code below
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 20px;
width: 20px;
border-radius:5px;
border:1px solid #ff7e02;
}
<div class="check">
<label class="container1">Architecture/Landscape
<input type="checkbox" checked="checked">
<span class="checkmark"></span>
</label>
</div>

Put the checkbox inside a parent with display:grid and make sure it doesn't have margin:auto
https://codepen.io/sneffel/pen/oNPYvBx
body{
text-align:center;
}
.grid{
display:grid;
}
input{
height:25px;
}
<div class="container grid">
<input type="checkbox" id="first">
</div>
<form class="container">
<input type="checkbox" id="second">
</form>

Related

Check box button not functioning on click

I am trying to give a checkbox button. Even though the button box and checkmark is shown,it's not functioning (not getting unchecked on click).Could anyone sort this out. I am new to HTML,CSS.
```
<div class="col-sm-1 accept-box ">
<input
class=""
type="checkbox"
name="accept"
value="accepted"
checked
/><label for=""></label>
</div>
input[type='checkbox'] + label {
font-family: Proxima Nova,Open Sans,Corbel,Arial,sans-serif;
font-weight: 400;
cursor: pointer;
padding: 0;
position: relative;
height: 1rem !important;
width: 1rem !important;
}
input[type='checkbox']:checked + label::after {
background: #FFF;
border: 1px solid var(--link-default);
border-width: 0 0.125rem 0.125rem 0;
content: '';
height: 0.875rem !important;
left: 0.35rem !important;
position: absolute;
top: 0;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
width: 0.5rem !important;
position: absolute !important;
}
```
label must be provided id of the controlled element in its attribute for.
div {
/* optional styling. Just to show label */
background-color: #000;
}
input[type='checkbox']+label {
font-family: Proxima Nova, Open Sans, Corbel, Arial, sans-serif;
font-weight: 400;
cursor: pointer;
padding: 0;
position: relative;
height: 1rem !important;
width: 1rem !important;
}
input[type='checkbox']:checked+label::after {
background: #FFF;
border: 1px solid var(--link-default);
border-width: 0 0.125rem 0.125rem 0;
content: '';
height: 0.875rem !important;
left: 0.35rem !important;
position: absolute;
top: 0;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
width: 0.5rem !important;
}
<div class="col-sm-1 accept-box">
<input id="accept" type="checkbox" name="accept" value="accepted" checked>
<label for="accept"></label>
</div>

Custom tick mark in a custom checkobx is not displaying

I have a custom checkbox which I want to add a tick mark inside it when checked
Here is code snippet:
input[type="checkbox"] {
transform: scale(3, 3) !important;
margin: 0px 21px;
}
.checkbox-custom,
.checkbox-custom-label {
display: inline-block;
vertical-align: middle;
margin: 5px 7px;
cursor: pointer;
font-size: 2.4rem;
font-family: "FuturaPT_BOOK";
/* padding: 6px; */
}
[type="checkbox"]:not(:checked)+label:after,
[type="checkbox"]:checked+label:after {
content: '✔';
position: absolute;
top: 8px;
left: 10px;
font-size: 24px;
line-height: 0.8;
color: #fff;
transition: all .2s;
}
.checkbox-custom+.checkbox-custom-label:before {
content: '';
background: #fff;
border: 1px solid #000;
display: inline-block;
vertical-align: middle;
width: 30px;
height: 30px;
padding: 2px;
margin-right: 30px;
text-align: center;
border-radius: 24%;
}
.checkbox-custom:checked+.checkbox-custom-label:before {
background: #0000;
box-shadow: inset 0px 0px 0px 4px #fff;
}
<p class="checkbox">
<input type="checkbox" class="checkbox checkbox-custom" name="cgv" id="cgv" value="1" {if $checkedTOS}checked="checked" {/if} />
<label class="checkbox-custom-label" for="cgv">{l s='I agree to the terms of service' mod='threepagecheckout'}</label>
{l s='(Read the Terms of Service)' mod='threepagecheckout'}
</p>
unfortunately when I click on check box nothing is displayed, I have tried different combination but nothing worked,
what am I doing wrong?
First you have to hide the default checkbox:
[type="checkbox"] {
display: none
}
Then put some general styling for label:after:
[type="checkbox"]+label:after {
content: '';
position: absolute;
...
}
Then style the :checked state
[type="checkbox"]:checked+label:after {
content: '✔';
}
And also position the tick mark so that it appears correctly in middle of your custom checkbox. Your tick mark was outside the box.
input[type="checkbox"] {
transform: scale(3, 3) !important;
margin: 0px 21px;
}
.checkbox-custom,
.checkbox-custom-label {
display: inline-block;
vertical-align: middle;
margin: 5px 7px;
cursor: pointer;
font-size: 2.4rem;
font-family: "FuturaPT_BOOK";
/* padding: 6px; */
}
[type="checkbox"] {
display: none
}
[type="checkbox"]+label:after {
content: '';
position: absolute;
top: 31px;
left: 23px;
font-size: 24px;
line-height: 0.8;
color: #fff;
transition: all .2s;
}
[type="checkbox"]:checked+label:after {
content: '✔';
}
.checkbox-custom+.checkbox-custom-label:before {
content: '';
background: #fff;
border: 1px solid #000;
display: inline-block;
vertical-align: text-top;
width: 30px;
height: 30px;
padding: 2px;
margin-right: 30px;
text-align: center;
border-radius: 24%;
}
.checkbox-custom:checked+.checkbox-custom-label:before {
background: #000;
box-shadow: inset 0px 0px 0px 4px #fff;
}
<p class="checkbox">
<input type="checkbox" class="checkbox checkbox-custom" name="cgv" id="cgv" value="1" />
<label class="checkbox-custom-label" for="cgv">I agree to the terms of service</label>
Read the Terms of Service
</p>
i have modified my code
/* Base for label styling */
[type="checkbox"]:not(:checked),
[type="checkbox"]:checked {
position: absolute;
left: -9999px;
}
[type="checkbox"]:not(:checked) + label,
[type="checkbox"]:checked + label {
position: relative;
padding-left: 1.95em;
cursor: pointer;
}
/* checkbox aspect */
[type="checkbox"]:not(:checked) + label:before,
[type="checkbox"]:checked + label:before {
content: '';
position: absolute;
left: 0; top: 0;
width: 1.25em; height: 1.25em;
border: 2px solid #ccc;
background: #fff;
border-radius: 4px;
box-shadow: inset 0 1px 3px rgba(0,0,0,.1);
}
/* checked mark aspect */
[type="checkbox"]:not(:checked) + label:after,
[type="checkbox"]:checked + label:after {
content: '\2713\0020';
position: absolute;
top: .15em; left: .22em;
font-size: 1.3em;
line-height: 0.8;
color: #09ad7e;
transition: all .2s;
font-family: 'Lucida Sans Unicode', 'Arial Unicode MS', Arial;
}
/* checked mark aspect changes */
[type="checkbox"]:not(:checked) + label:after {
opacity: 0;
transform: scale(0);
}
[type="checkbox"]:checked + label:after {
opacity: 1;
transform: scale(1);
}
<p class="checkbox">
<input type="checkbox" class="checkbox checkbox-custom" name="cgv" id="cgv" value="1" {if $checkedTOS}checked="checked" {/if} />
<label class="checkbox-custom-label" for="cgv">{l s='I agree to the terms of service' mod='threepagecheckout'}</label>
{l s='(Read the Terms of Service)' mod='threepagecheckout'}
</p>

Input checked state does not affect css selector

So I've been trying to trigger my CSS selector via the checkbox state as you can see below but I've had no luck getting it to trigger. What should happen on click is the tick should simply disappear.
.i-cb input[type="checkbox"]:checked + label::before {
display: none;
width:0px;
height: 0px;
}
JSFiddle : https://jsfiddle.net/7tnepc8r/4/
It's a problem with order.
You should change order your HTML.
The + selector is used to select elements that is placed immediately after(not inside) the first specified element.
.i-cb input[type=checkbox] {
visibility: hidden;
}
.i-cb label {
position: relative;
display: inline-block;
width: 44px;
height: 44px;
border: 4px solid #48c8f1;
border-radius: 50%;
border-top-color: transparent;
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
z-index: 0;
}
.i-cb label::before {
content: "";
position: absolute;
width: 6px;
height: 45px;
background-color: #93c83d;
left: 22px;
top: -15px;
z-index: 1;
}
.i-cb label::after {
content: "";
position: absolute;
width: 18px;
height: 6px;
background-color: #93c83d;
left: 10px;
top: 24px;
z-index: 1;
}
.i-cb input[type=checkbox]:checked + label::after {
display: none !important;
width: 0px !important;
height: 0px !important;
}
.i-cb input[type=checkbox]:checked + label::before {
display: none;
width: 0px;
height: 0px;
}
<div class="i-cb">
<input id="check" type="checkbox" />
<label for="check"></label>
</div>
You just need change the markup order, because you using + sign which indicating label after input:
<div class="i-cb">
<input id="check" type="checkbox" />
<label for="check"></label>
</div>

Erased border with the scale

There stylized input, but the zoom in / out, they change size, it seems as if the border is lost, I can't understand what went wrong, thanks in advance.
My codepen
For example, Chrome - zoom 75%
<div class="checkbox-remember-me">
<input type="radio" name="gender" id="male" checked/>
<label for="male"></label>
</div>Male
This happens because you use an absolute positioned label to cover its parent partially to make it appear to have a border, and when the page is zoomed, depending on how the browser calculate its position, it jumps a pixel up and down, hence sometimes fully aligns with its parent's edge.
Update your css like this, and use a border instead, and it will work fine.
.checkbox-remember-me {
display: inline-block;
width: 24px;
height: 24px;
position: relative;
border: 1px solid #666;
margin-left: 34px;
margin-right: 10px;
}
.checkbox-remember-me label {
width: 22px;
height: 22px;
cursor: pointer;
position: absolute;
background: #eee;
margin: 1px;
}
.checkbox-remember-me {
display: inline-block;
width: 24px;
height: 24px;
position: relative;
border: 1px solid #666;
margin-left: 34px;
margin-right: 10px;
}
.checkbox-remember-me label {
width: 22px;
height: 22px;
cursor: pointer;
position: absolute;
background: #eee;
margin: 1px;
}
.checkbox-remember-me label:after {
content: '';
width: 15px;
height: 10px;
position: absolute;
top: 4px;
left: 4px;
border: 3px solid red;
border-top: none;
border-right: none;
background: transparent;
opacity: 0;
transform: rotate(-45deg);
}
.checkbox-remember-me label:hover:after {
opacity: 0.3;
}
input[type=radio] {
display: none;
}
input[type=radio]:checked + label:after {
opacity: 1;
}
<h4>Gender</h4>
<div class="checkbox-remember-me">
<input type="radio" name="gender" id="male" checked/>
<label for="male"></label>
</div>Male
<div class="checkbox-remember-me">
<input type="radio" name="gender" id="female" />
<label for="female"></label>
</div>Female
Updated codepen: https://codepen.io/anon/pen/LRLrNO

How to make checkboxes rounded?

Is there any way to make checkboxes with rounded corners using bootstrap or some css property?
Just using css, however, you lose the checkbox tick.
.checkbox-round {
width: 1.3em;
height: 1.3em;
background-color: white;
border-radius: 50%;
vertical-align: middle;
border: 1px solid #ddd;
appearance: none;
-webkit-appearance: none;
outline: none;
cursor: pointer;
}
.checkbox-round:checked {
background-color: gray;
}
<input type="checkbox" class="checkbox-round" />
.container {
display: block;
position: relative;
padding-left: 35px;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* Hide the browser's default checkbox */
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
/* Create a custom checkbox */
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: #eee;
border-radius: 15px;
}
/* On mouse-over, add a grey background color */
.container:hover input ~ .checkmark {
background-color: #ccc;
}
/* When the checkbox is checked, add a blue background */
.container input:checked ~ .checkmark {
background-color: #2196F3;
}
/* Create the checkmark/indicator (hidden when not checked) */
.checkmark:after {
content: "";
position: absolute;
display: none;
}
/* Show the checkmark when checked */
.container input:checked ~ .checkmark:after {
display: block;
}
/* Style the checkmark/indicator */
.container .checkmark:after {
left: 9px;
top: 5px;
width: 5px;
height: 10px;
border: solid white;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
<label class="container">One
<input type="checkbox" checked="checked">
<span class="checkmark"></span>
</label>
<label class="container">Two
<input type="checkbox">
<span class="checkmark"></span>
</label>
<label class="container">Three
<input type="checkbox">
<span class="checkmark"></span>
</label>
<label class="container">Four
<input type="checkbox">
<span class="checkmark"></span>
</label>
Try to do
body {
background-color: #f1f2f3;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.container {
margin: 0 auto;
}
.round {
position: relative;
}
.round label {
background-color: #fff;
border: 1px solid #ccc;
border-radius: 50%;
cursor: pointer;
height: 28px;
left: 0;
position: absolute;
top: 0;
width: 28px;
}
.round label:after {
border: 2px solid #fff;
border-top: none;
border-right: none;
content: "";
height: 6px;
left: 7px;
opacity: 0;
position: absolute;
top: 8px;
transform: rotate(-45deg);
width: 12px;
}
.round input[type="checkbox"] {
visibility: hidden;
}
.round input[type="checkbox"]:checked + label {
background-color: #66bb6a;
border-color: #66bb6a;
}
.round input[type="checkbox"]:checked + label:after {
opacity: 1;
}
<div class="container">
<div class="round">
<input type="checkbox" id="checkbox" />
<label for="checkbox"></label>
</div>
</div>
One of the Best And Easiest Method is to use CSS clip path property:
<input type="checkbox" id="checkbox" />
<label for="checkbox" >Option</label>
input[type="checkbox"] {
width: 45px; /* Set width */
height: 45px; /* Set height */
clip-path: circle(46% at 50% 50%); /* Set the clip path of circle*/
}
if you still see some pointed corners, try reducing the first percentage values, (where I have used 46%), play with it a little bit and it will definitely work.
Well, this is the simplest and optimal solution. You set appearance to none and then use clip-path when its checked.
.rounded-checkbox {
width:35px;
height: 35px;
border-radius: 50%;
vertical-align: middle;
border: 1px solid black;
appearance: none;
-webkit-appearance: none;
outline: none;
cursor: pointer;
}
.rounded-checkbox:checked {
appearance: auto;
clip-path: circle(50% at 50% 50%);
background-color: blue;
}
<input
type="checkbox"
class="rounded-checkbox"
id="checkbox"
/> <label for="checkbox">Checkbox</label>
in css you may play with height, width, border-radius. basically height and width should be equal and border-radius should be half of them.
if you are using bootstrap you can use this class and add it where your shape or in this case your checkbox class is: class="rounded-circle"
look: borders bootstrap 5
for example to make a checkbox rounded in bootstrap 5 (also working for v4):
<div class="form-check">
<input
class="form-check-input rounded-circle"
type="checkbox"
/>
<label class="form-check-label" for="flexCheck1">
rounded checkbox
</label>
</div>
CSS
.checkbox {
clip-path: circle(46% at 50% 50%);
}
HTML
<input type="checkbox" class="checkbox" />
No need to hide the default checkbox and create a custom just set the clip-path and you can easily achieve a circular checkbox.
I thing the best way to make a rounded corners is by using the border-radius property. This site has a nice collection of checkboxes.
For example:
cursor: pointer;
position: absolute;
width: 20px;
height: 20px;
top: 0;
border-radius: 10px;
The last line(border-radius: 10px) will give you a checkbox with rounded corners.