pub struct Input;Expand description
The <input> element - represents a typed data field for user input.
§Purpose
The <input> element is a versatile form control for collecting user input. Its behavior
and appearance vary dramatically based on the type attribute, ranging from text fields
to buttons, checkboxes, date pickers, and more. The most commonly used form element.
§Content Categories
- Flow Content
- Phrasing Content
- If
typeis not “hidden”: Interactive Content - Palpable Content
§Permitted Content Model
- None (void element)
§Common Use Cases
- Text and password input fields
- Checkboxes and radio buttons for selections
- File uploads
- Date, time, and color pickers
- Number and range sliders
§Key Attributes
type: Input type (text, password, email, number, checkbox, radio, file, date, etc.)name: Name for form submissionvalue: Current value of the controlplaceholder: Hint text displayed when emptyrequired: Makes the field mandatorydisabled: Disables the controlreadonly: Makes the field read-onlymin,max: Minimum and maximum values (for numeric/date types)step: Increment step (for numeric types)pattern: Regular expression for validationautocomplete: Autocomplete hintmultiple: Allow multiple values (file, email)accept: File types to accept (for file inputs)checked: Pre-checked state (checkbox, radio)
§Example
<!-- Text input -->
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="Enter your name" required>
<!-- Email with validation -->
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="user@example.com" required>
<!-- Password field -->
<label for="pwd">Password:</label>
<input type="password" id="pwd" name="password" minlength="8" required>
<!-- Number with range -->
<label for="age">Age:</label>
<input type="number" id="age" name="age" min="18" max="120" step="1">
<!-- Checkbox -->
<input type="checkbox" id="subscribe" name="subscribe" value="yes" checked>
<label for="subscribe">Subscribe to newsletter</label>
<!-- Radio buttons -->
<input type="radio" id="color-red" name="color" value="red">
<label for="color-red">Red</label>
<input type="radio" id="color-blue" name="color" value="blue">
<label for="color-blue">Blue</label>
<!-- File upload -->
<label for="avatar">Profile picture:</label>
<input type="file" id="avatar" name="avatar" accept="image/*">
<!-- Date picker -->
<label for="dob">Date of birth:</label>
<input type="date" id="dob" name="dob" min="1900-01-01" max="2024-12-31">
<!-- Range slider -->
<label for="volume">Volume:</label>
<input type="range" id="volume" name="volume" min="0" max="100" value="50">
<!-- Search field -->
<input type="search" name="q" placeholder="Search..." autocomplete="off">
<!-- Color picker -->
<label for="color">Choose color:</label>
<input type="color" id="color" name="color" value="#ff0000">§Accessibility
- Always provide associated
<label>elements - Use appropriate
typeattribute for semantic meaning - Provide helpful placeholder text (but don’t rely on it alone)
- Use
aria-describedbyfor additional instructions - Ensure sufficient color contrast for visible inputs
- Make error messages clear and associated with inputs
- Use
autocompletefor common fields
§WHATWG Specification
Trait Implementations§
Source§impl HtmlElement for Input
impl HtmlElement for Input
impl FlowContent for Input
impl InteractiveContent for Input
impl PalpableContent for Input
impl PhrasingContent for Input
Auto Trait Implementations§
impl Freeze for Input
impl RefUnwindSafe for Input
impl Send for Input
impl Sync for Input
impl Unpin for Input
impl UnwindSafe for Input
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more