Example

A labeled email control with native constraints

Inspect a persistent form label, email syntax checks, and the limits of browser validation.

Beginner2 min readLearn · Practice · Review

Published by HTML Code Runner · AI-assisted material · Independent editorial review pending · Editorial policy

On this page

Understand the source

The label for value and input id are both email, creating a programmatic association. The name attribute supplies the form-data key. Type email and required ask the browser to perform supported syntax and empty-value checks during ordinary interactive submission.

<form>
  <label for="email">Email address</label>
  <input id="email" name="email" type="email" autocomplete="email" required>
  <button type="submit">Subscribe</button>
</form>

Expected output

The label stays visible while you type. Activate Subscribe with the field empty or with a word that is not an email address and inspect browser feedback. A plausible value can satisfy those constraints, but it does not prove that a mailbox exists. Submissions are blocked in this isolated preview.

Make a deliberate change

Add a persistent help paragraph with id="email-help" and connect it using aria-describedby. The help should explain the newsletter frequency. Keep the label as well: descriptive help and a control name solve different problems. Then compare optional and required behavior by removing the required attribute.

Review the behavior

Do not write required="false" to disable the requirement; omit the boolean attribute. A real service also needs server validation, clear success and error handling, and an actual receiving endpoint. This preview is for control behavior and structure, not evidence that a subscription was recorded.

Read the full explanation and expected output