HTML URL input: collecting links with confidence
The HTML <input type="url">
is designed for web addresses. Unlike a plain text box, it conveys intent to browsers and assistive technologies, offers a keyboard with /
and .com
shortcuts on many devices, and performs a basic format check. Whether you’re bookmarking, building a profile editor, or accepting a webhook endpoint, using the semantic URL control improves accuracy and clarity.
Attributes and hints
Add a visible label like “Website” or “Link”. Use placeholder
for an example (e.g., https://example.com
) and autocomplete
only when the browser can meaningfully suggest values. For mobile keyboards that don’t optimize automatically, consider inputmode="url"
. When accepting several URLs, use a list of fields rather than a single field with separators to preserve accessibility.
Validation approach
Native checks ensure the scheme and host look reasonable, but they don’t verify reachability. Keep client patterns lenient; an over‑restrictive regex will reject legitimate URLs (internationalized domains, uncommon schemes). On the server, normalize and validate thoroughly.
- Whitelist allowed schemes (
https:
preferred). - Strip invisible characters and trim whitespace.
- Consider DNS or application‑level checks where appropriate.
Security considerations
Treat URLs as untrusted input. When rendering user links, add rel="noopener noreferrer"
to external anchors opened in a new tab and consider link‑scanning server‑side for malicious destinations. Sanitize against JavaScript URLs if you only accept HTTP(S).
Accessibility checklist
- Use a clear label; don’t rely on placeholder alone.
- Associate error/help text via
aria-describedby
. - Ensure focus outlines remain visible around embedded icons or buttons.
Copy‑ready patterns
- Profile website: label + example placeholder +
required
(if needed). - Webhook URL: label + helper text describing method and expected endpoint.
- Multiple links: repeatable fieldset with add/remove controls.
Choosing the URL input clarifies expectations and reduces invalid submissions. Pair the semantic control with helpful labels, realistic client checks, and server‑side validation to gather links you can trust.