HTML & CSS · Beginner · 15 min
Connect a form hint to its field
Keep a visible label and associate a separate instruction with the input it describes.
Give the field a name and a useful hint
Use a visible <label> to name the field. A separate hint can tell readers what to enter. Keep the hint visible near the field so readers can refer to it while typing.
<label for="badge-name">Name on badge</label>
<input type="text" id="badge-name" name="badge-name">
<p>You can use a first name or a nickname.</p>Expected appearance
Name on badge [ ] You can use a first name or a nickname.
Connect the hint by its ID
Give the hint a unique id="badge-hint". Add aria-describedby="badge-hint" to the input. This lets assistive technology present the hint as the field’s description. Keep the label association so the field still has a clear name.
<label for="badge-name">Name on badge</label>
<input type="text" id="badge-name" name="badge-name" aria-describedby="badge-hint">
<p id="badge-hint">You can use a first name or a nickname.</p>Expected appearance
Field name: Name on badge Description: You can use a first name or a nickname.
Try it yourself
Code runs on this device. When you are signed in, drafts sync to your account.
Edit the page content and include CSS in a style element. The preview supports a limited set of HTML elements. Scripts, external resources, navigation to other sites, and form submission are disabled.
Build and check
Keep the label and the text input in .badge-form. Keep for="badge-name" on the label and id="badge-name" on the input. Give the hint paragraph id="badge-hint". Add aria-describedby="badge-hint" to the input. Keep the hint visible.
Put id="badge-hint" on the paragraph that contains the hint. Use aria-describedby="badge-hint" on the input, with the same ID and no # prefix.
Show worked solution
<style>
.badge-form { max-width: 28rem; margin: 1rem auto; font-family: sans-serif; line-height: 1.5; }
.badge-form label { display: block; font-weight: 600; }
.badge-form input { box-sizing: border-box; width: 100%; padding: 0.5rem; }
.badge-form input:focus-visible { outline: 3px solid #1d4ed8; outline-offset: 3px; }
</style>
<main>
<h1>Library workshop badge</h1>
<form class="badge-form">
<label for="badge-name">Name on badge</label>
<input type="text" id="badge-name" name="badge-name" aria-describedby="badge-hint">
<p id="badge-hint">You can use a first name or a nickname.</p>
</form>
</main>The label names the input through for="badge-name". The separate aria-describedby="badge-hint" association supplies its description.
Page preview
Run to preview your page. Check tests the task requirements, including the requested screen widths. Check results do not replace keyboard and visual review.
Try it yourself
- Preview the form and use Tab to focus the field. Type a sample name and check that the hint stays visible.
- Compare the two connections in your code. The label points to the input ID, and the input points to the hint ID.