[Edit]
+
0
-
0

CSS - styled radio button 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 86
<!doctype html> <html> <head> <style> /* --- BASIC STYLES --- */ label.radio { 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 --- */ circle.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="radio"> <input class="input" style="display: none" type="radio" /> <!-- You can add the following attributes to the input radio 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"> <circle style="fill: #767676" cx="8.552" cy="8.552" r="8.552"/> <circle style="fill: #ffffff" cx="8.552" cy="8.552" r="7.35"/> </svg> <svg class="icon checked" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 17.105 17.105"> <circle style="fill: #0075ff" cx="8.552" cy="8.552" r="8.552" /> <circle style="fill: #ffffff" cx="8.552" cy="8.552" r="7.35" /> <circle class="animation" style="fill: #0075ff" cx="8.552" cy="8.552" r="5.023" /> </svg> <span class="label">Label</span> </label> </body> </html> <!-- See also: 1. https://dirask.com/snippets/CSS-styled-input-checkbox-HTML-element-with-animation-pBVOyp -->
Reset