HTML & CSS · Beginner · 15 min
Label a form clearly
Associate a visible label with an input and use the right button type.
Connect a label to its input
The label’s "for" value must match the input’s id. A visible label stays available after someone types. A placeholder is a hint, not a replacement for a label. Use an appropriate input type, such as email for an email address.
<label for="email">Email</label>
<input id="email" name="email" type="email">Expected appearance
Make required fields clear
The required attribute enables the browser’s check when a real form submits. Include a visible required indication too. Use a button for an action and specify its type. This course previews form controls but does not submit or send their values anywhere.
<form>
<label for="email">Email (required)</label>
<input id="email" name="email" type="email" required>
<button type="submit">Send</button>
</form>Expected appearance
Email (required) Send
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
Build a form with a label reading Email (required), an input with id="email", type="email", and required, and a submit button reading Send.
Use for="email" on the label, type="email" and required on the input, and type="submit" on the button.
Show worked solution
<form>
<label for="email">Email (required)</label>
<input id="email" name="email" type="email" required>
<button type="submit">Send</button>
</form>Use for="email" on the label, type="email" and required on the input, and type="submit" on the button.
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
- Click the visible label and confirm that the input receives focus.
- Use Tab to reach the input and button without a mouse.