.custom-radio
.opacity: 0; position: absolute
, then apply JavaScript to toggle a .selected
class based on input state via the change
event.To keep custom radio buttons selected after being clicked in Webflow using custom code, you need to ensure your buttons are properly connected to the browser's form state and styled to reflect the selection.
.custom-radio
to each.addClass('selected')
) when selected.You need a script that ensures:
Here’s how to do it:
tag custom code area in the Page Settings:
// Assumes each custom radio button is wrapped in an element with class "custom-radio"document.querySelectorAll('.custom-radio input[type="radio"]').forEach(function(radioInput) { radioInput.addEventListener('change', function() { // Get all radios in the same group const name = this.name; document.querySelectorAll(`.custom-radio input[name="${name}"]`).forEach(function(radio) { if (radio.checked) { radio.closest('.custom-radio').classList.add('selected'); } else { radio.closest('.custom-radio').classList.remove('selected'); } }); });});
display: none
).custom-radio
, and design the selection style on .custom-radio.selected
.display: none
; use opacity: 0; position: absolute
instead so it remains in the DOM and interactive.To keep custom radio buttons selected in Webflow, use native radio inputs, hide them visually, wrap them in styled containers, and use JavaScript to sync selection states to visual classes by listening to the change
event.