I'm using <label>
to wrap an input such that its success and error messages can appear inside its label for association. What do you think is the most semantic markup for this scenario?
<label>
<b>Username</b>
<input>
<strong>Username already taken :(</strong>
</label>
For errors is strong
appropriate? Or is span
better? Is role=status
appropriate?
There are two ways to pair a label and an input. One is by wrapping the input in a label (implicit), and the other is by adding a for attribute to the label and an id to the input (explicit). Think of an implicit label as hugging an input, and an explicit label as standing next to an input and holding its hand.
We can show errors with two methods without using the alert box. Syntax: node. textContent = "Some error message" // To draw attention node.
The label is used to tell users the value that should be entered in the associated input field.
There is no right tag to use for an error message. It all depends on how and where you want to display the error. Once you decide on these things, your choices will be narrowed, as tag properties and limitations differ.
The WCAG provides an example of error displaying using both aria-invalid
and aria-describedby
properties.
In your example, the code would be:
<label>
<b>Username</b>
<input aria-invalid="true" aria-describedby="error">
<strong id="error">Username already taken :(</strong>
</label>
The strong
is appropriate as it appears to be an important notice. An alert
role (rather than status
) would be more appropriate to be applied to the #error
element according to the W3C.
Using a strong tag is appropriate.
Strong tags signify something is of bigger importance, and the password being incorrect is important, as it blocks the user from proceeding.
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