I'm currently adding some date input to a form. I have a 'Start Date' and 'End Date' input but only want to use a single label ('Dates') for both inputs.
Is it possible to do this? What are the accessibility concerns?
My current thinking is to have a label 'Dates' that is shown then have two hidden labels for each input for screen readers etc. Is this the way to go? Are there any examples of large websites doing this kind of thing (Government websites if possible)?
This is a project that may be user by a government agency so there are strict rules on it complying with accessibility.
In this case I think the best markup would be to wrap the inputs in a fieldset
, use a legend
for "Dates", use labels
for both inputs
and hide the labels:
HTML
<fieldset>
<legend>Dates</legend>
<label for="startdate">Start Date</label>
<input type="text" name="startdate" id="startdate" placeholder="Start Date">
<label for="enddate">End Date</label>
<input type="text" name="enddate" id="enddate" placeholder="End Date">
</fieldset>
CSS
fieldset {
border: none;
}
label {
margin-left: -999em;
}
input {
display: block;
}
Fiddle here
Also see: WCAG 2, H71: Providing a description for groups of form controls using fieldset and legend elements
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With