shadcn.io is not affiliated with official shadcn/ui
Input examples · Types
URL Input for React
A website field with a link icon and a hint to include the protocol.
URLs fail validation most often for a missing protocol. This example uses an input with type url, a LinkIcon in an InputGroupAddon, and a description under the field that says to include https:// or http://. Use it for website, portfolio and social profile fields.
Preview
Installation
FAQ
What does type url give this field?
The browser checks that the value is an absolute URL, with its protocol, when the form is submitted, and mobile keyboards show keys like / and .com.
How is the icon placed inside the field?
The field is an InputGroup: InputGroupInput is the input and InputGroupAddon holds LinkIcon. The addon comes after the input in the markup and sits at the inline start, so it is on the left in left-to-right text and on the right in right-to-left text. Clicking it focuses the input.
Is the icon read by screen readers?
No. LinkIcon has aria-hidden, because the Website label already names the field. The icon is a visual hint only.
How is Website tied to the field?
Clicking the label focuses the field, and screen readers announce it with the field.
FieldLabel sets htmlFor to url-website, the input's id.
Related
- Email InputAn email field with a mail icon inside it
- Phone InputA phone number field with a phone icon
- Profile Edit FormA profile form prefilled with a username
- Input with LabelA text input with a label above it
- Link Preview Hover CardA link inside a sentence that opens a
- Button with Text (Link)Underline on hover, no fill