[Edit]
+
0
-
0

CSS - styled input checkbox HTML element (custom style with animation)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
<!doctype html> <html> <head> <style> /* --- BASIC STYLES --- */ label.checkbox { cursor: pointer; } svg.icon { width: 13px; height: 13px; vertical-align: middle; } svg.icon.default { display: inline-block; } svg.icon.checked { display: none; } input.input:checked~svg.icon.default { display: none; } input.input:checked~svg.icon.checked { display: inline-block; } span.label { margin: 0 0 0 3px; vertical-align: middle; font: 13px Arial; color: #5f6368; } /* --- ANIMATION STYLES --- */ path.animation { animation: flow-in 0.1s; } @keyframes flow-in { 0% { transform: scale(0); transform-origin: center; } 100% { transform: scale(1); transform-origin: center; } } </style> </head> <body> <label class="checkbox"> <input class="input" style="display: none" type="checkbox" /> <!-- You can add the following attributes to the input checkbox element: - name="field-name" - value="field-value" - checked (or: checked="checked") --> <svg class="icon default" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 17.105 17.105"> <rect style="fill: #767676" width="17.105" height="17.105" x="0" y="0" ry="2.005" rx="2.005" /> <rect style="fill: #ffffff" width="14.7" height="14.7" x="1.203" y="1.203" ry="1.136" rx="1.136" /> </svg> <svg class="icon checked" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 17.105 17.105"> <rect style="fill: #0075ff" width="17.105" height="17.105" x="0" y="0" ry="2.005" rx="2.005" /> <path class="animation" style="fill: #ffffff" d="m7.185 14.566 7.75-9.755-2.07-1.871-5.947 7.35-2.406-2.138-1.87 1.87z" /> </svg> <span class="label">Label</span> </label> </body> </html> <!-- See also: 1. https://dirask.com/snippets/CSS-style-radio-button-HTML-element-with-animation-pq6o4j -->
Reset