The label and the field are easy; we have <label>
and then the relevant input field. But what is the most semantically-correct HTML element to use for the smaller informational text that goes under the field?
Semantic HTML is the correct use of HTML to reinforce the meaning of content on a web page, rather than merely define its appearance. Semantically correct HTML helps search engines, screen readers, and other user devices determine the significance and context of web content.
Semantics in HTML In HTML, for example, the <h1> element is a semantic element, which gives the text it wraps around the role (or meaning) of "a top level heading on your page."
Yes. A semantic tag is simply an element that defines itself semanticly to the developer. Using an <article> tag is no different than using a block level element such as a <div> tag except it is semantically sound. The tag specifies independent, self-contained content.
I don't know of a specific element or attribute to connect them, but you can do so using the ARIA attribute aria-describedby
:
<label for="firstname">First Name</label>
<input type="text" id="firstname" aria-describedby="firstname-explanation" />
<p id="firstname-explanation">e.g. John</p>
But including everything in the label
seems good to me either (also gives good styling abilities, as you have a - semantic - container):
<label>
<span class="form-item-title">First Name</span>
<input type="text" id="firstname" />
<span class="form-item-description">e.g. John</span>
</label>
Or you could even mix the two.
Another approach could be to put the description in the title
(or placeholder
as suggested by @Alohci) attribute of the input
element (semantically this is the one describing it), but in this case you have to insert it to the markup through Javascript (or CSS using input:after { content : "e.g. " attr(placeholder) }
- suggested by @Alohci).
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