Suggestion: Better CSS Accessibility on “Required” fields
-
I am attempting to format some of the field labels that are generated, and I wish to modify the label on *required* fields. Presently, the HTML for a required field is similar to the following:
<p class="ctct-form-field ctct-form-field-email"><label for="email___123abc">Email <abbr title="required">*</abbr></label><input required type="email" name="email___123abc" id="email___123abc" value="" placeholder="Enter your email address"class="ctct-email"/></p>
Note: There’s an error in that there is no space before the “class” attribute on the “input” tag.
I see that the required field is formatted with an asterisk surrounded in an “abbr” tag. While workable, it’s not flexible. If instead of using an asterisk, you gave the <p> element an additional class of “ctct-form-field-required”, one could use something like:
.ctct-form-field-required label:after {content: '*'; color: #f00;}
to format the label. They could put the asterisk (or whatever they want) before or after the label, they could use CSS to add a colon after field names, and most importantly, they could have CSS distinguish between required and non-required fields.
With the way it is now, if I want the asterisk to appear before the label, I would need to use CSS to specifically target the label with the specific “for” attribute value, hide the “abbr” tag on it, and add my other CSS code to handle the preceeding asterisk – a lot more work than it could be with the added class, especially if one simply wants to do it to all required field labels.
Having that class applied to the containing element (in this case the ‘p’ tag), would also allow conditional formatting of the required fields themselves (in addition to the labels) without having to reference the ID of every field one wants to do it to.
- The topic ‘Suggestion: Better CSS Accessibility on “Required” fields’ is closed to new replies.