File input
Examples
To render a file input, apply the class chi-file-input
to an input type="file"
and add a label next to it.
Base #
This HTML Blueprint requires JavaScript to update the label content once a file or files have been selected. You may use your own JavaScript solution, or use Chi's example below.
Disabled #
This HTML Blueprint requires JavaScript to update the label content once a file or files have been selected. You may use your own JavaScript solution, or use Chi's example below.
Sizes #
File inputs support sizes:-xs
,-sm
,-md
,-lg
,-xl
. The default size is -md
.
Web Component
Properties
Accessibility
Keyboard Navigation
Key | Function |
---|---|
Tab | Moves focus to the next focusable element |
Shift + Tab | Moves focus to the previous focusable element |
Enter or Space | Opens the file picker dialog when the file input is focused |
For comprehensive details on keyboard support for input fields, refer to our Keyboard Control Guide.
Visit WebAIM for keyboard techniques.
Find live examples in the A11y style guide.
Roles and attributes
WAI-ARIA provides a grouping role that functions similarly to fieldset and legend.
Role | Element | Usage |
---|---|---|
group | div | Identifies the div element as a group container for the file inputs. |
Resources
- A11y Style Guide: Gives core recommendations for accessible forms.
- W3C Forms Tutorial: Provides guidance on creating accessible forms.
- Mozilla Developer Guides: Find technical summary for the file inputs.
Other recommendations
Explore additional accessibility tips in the general Accessibility Guide.
WCAG 2.2 Guidelines
- Non-text Content: All non-text content that is presented to the user has a text alternative that serves the equivalent purpose. (Level A)
- Info and Relationships: Information, structure, and relationships conveyed through presentation can be programmatically determined or are available in text. (Level A)
- Headings and Labels: Headings and labels describe topic or purpose. (Level AA)
- Labels or Instructions: Labels or instructions are provided when content requires user input. (Level A)
- Name, Role, Value: For all user interface components (including but not limited to: form elements, links and components generated by scripts), the name and role can be programmatically determined; states, properties, and values that can be set by the user can be programmatically set; and notification of changes to these items is available to user agents, including assistive technologies. (Level A)