I want a particular form component to act as radio buttons (only one option may be selected at a time). I do not want the radio bullets to show, however, opting for alternative presentational methods such as high light selected, or some other method. This will allow for graceful degradation: if the user browser does not support Javascript it will just degrade to basic radio buttons. I am wish to hide the bullet buttons through Javascript or CSS. Anyone know how? thanks.

- 26,085
- 12
- 82
- 103

- 8,320
- 9
- 40
- 50
-
+1 to make "671" out of your current "666" :) – Alex Shesterov Apr 19 '13 at 22:26
8 Answers
I've got a simple solution working where I have a label surrounding my radio buttons with an image representing the thing being selected:
<label>
<input type="radio" name="foo">
<img src="...">
</label>
I have then applied the following styles:
label {
float: left;
width: 100px;
height: 100px;
position: relative;
cursor: pointer;
}
label input[type=radio] {
opacity: 0;
}
label img {
position: absolute;
top: 0;
left: 0;
opacity: 0.5;
}
:checked + img {
opacity: 1;
}
Essentially each label
becomes a regular sized box that is completely filled by an img
. The radio itself is hidden using opacity:0
. The user can tell what is selected as the img
next to the checked radio will be opaque whereas the others are semi-transparent. You could do various other kind of effects pretty easily.
The thing I like is that the form remains simple to process, it is just a group of radio buttons.
I used opacity for the radio buttons rather than display:none
or visibility:hidden
as then they are still in the tabindex and the form remains keyboard accessible.

- 8,317
- 4
- 31
- 40
Just the bit of hiding the radio buttons (without losing accessibility, of course) can be done with the following CSS:
input[type="radio"] {
left: -999em;
position: absolute;
}
Using opacity: 0;
isn't ideal, as the button is still there, taking up space in the page. Positioning it out of view is the way to go.

- 3,325
- 3
- 34
- 42
-
1This would not hide, but move them and cause viewport to overflow (and likely scroll). – AnrDaemon Jan 27 '23 at 13:13
-
@AnrDaemon That's interesting, I've used this for years and I've never gotten a scrollbar. You're also the first person to point this out, do you have an example that I can use to reproduce your issue? Because I can't seem to. – aross Jan 27 '23 at 15:03
-
Claim of what? That using hacks to achieve desired results is subpar to actual documented solution? You have `display:none`, `visibility:hidden` and a number of other CSS rules to achieve desired results, but moving element outside viewport was never the correct solution to hiding it. – AnrDaemon Feb 06 '23 at 11:42
-
@AnrDaemon I asked a question and you haven't answered it at all. My solution is perfectly valid. – aross Mar 02 '23 at 09:09
$('#js input[type=radio]').hide();

- 17,563
- 3
- 40
- 62
-
3
-
Come on - it's reasonable to assume at least a reading familiarity with jQuery in this context. – Dominic Cronin Oct 11 '13 at 09:55
If I understand this correctly, you want radio buttons but you don't want the buttons themselves to appear. Keep in mind that just removing the buttons will NOT provide the user experience you are looking for. You need to have some form of user feedback.
You have two options:
1) Program this using javascript / jquery. With that in mind I would suggest you use radio buttons as a starting placeholder, and then use javascript (ideally via a jquery plugin) which will redraw the page and replace the buttons with clickable divs and a dynamically changing hidden field value.
2) Use the CSS meta class of :checked which unfortunately doesn't appear to have cross browser support.
var inputs = document.getElementById('my-form').getElementsByTagName('input');
for (var i = 0, inputsLength = inputs.length;i < inputsLength; i++) {
var input = inputs[i];
if (input.getAttribute('type') == 'radio') {
input.style.display = 'none';
}
}
Alternatively, if your browser supports it (querySelectorAll in document
)...
document.querySelectorAll('#my-form input[type="radio"]').style.display = 'none';

- 479,566
- 201
- 878
- 984
I don't think you can hide it with css. You'd have to hide the radiobuttons and then replace the functionality with JS. maybe a selectable list of LIs would work for you.
From the jQuery UI Selectable : http://jqueryui.com/demos/selectable/
<input type='radio' value='1' name='rad' class='radio'>
<input type='radio' value='2' name='rad' class='radio'>
<input type='radio' value='3' name='rad' class='radio'>
<ol id="selectable" style='display:none'>
<li class="ui-widget-content">Item 1</li>
<li class="ui-widget-content">Item 2</li>
<li class="ui-widget-content">Item 3</li>
</ol>
$(function() {
$('.radio').hide();
$( "#selectable" ).show().selectable({
selected: function(event, ui) {//figure out which was selected and mark the hidden radio button}
});
});

- 49,507
- 13
- 108
- 140
-
You can hide it with CSS. Simple rule of `label input[type="radio"] { display: none; }` (for example) would affect the appearance of buttons but retain labels in view. See comment above about using `opacity: 0` for the purposes of improved accessibility. – AnrDaemon Jan 27 '23 at 13:16
Just insert:
style="display:none;"
inside every "<input type='radio'…>"
tag.
This makes the bullets invisible, but leaves the labels showing.

- 26,085
- 12
- 82
- 103

- 61
- 1
- 1
-
this would prevent graceful degradation in case of disabled JavaScript, since bullets would still be hidden. Setting `display` to `none` *per JavaScript* would be an option. P.S. downvote was **not** from me. – Alex Shesterov Apr 19 '13 at 22:16