Font Awesome Build Awesome
Try SSR Server-side rendering (SSR) generates component HTML on the server before the page loads, improving SEO and initial load time. Use the switch to see Web Awesome components render with and without SSR.
Search this website ⌘KCtrl+K Light Dark System Docs Select Color Scheme Default Awesome Shoelace Active Brutalist Glossy Matter Mellow Playful Premium Tailspin Docs Select Theme View Project on GitHub Star Project on GitHub
Start Components Docs Help
Login Log into your account
Web Awesome Font Awesome Build Awesome
Search this site… /
Try SSR Server-side rendering (SSR) generates component HTML on the server before the page loads, improving SEO and initial load time. Use the switch to see Web Awesome components render with and without SSR.
Light Dark System Docs Select Color Scheme Default Awesome Shoelace Active Brutalist Glossy Matter Mellow Playful Premium Tailspin Docs Select Theme

Getting Started

  • Installation
  • Usage
  • Forms
  • Localization
  • Frameworks
  • Using with AI
  • Figma Design Kit ProThis requires access to Web Awesome Pro
  • Server Rendering

Resources

  • Accessibility
  • Browser Support
  • Contributing
  • Patterns ProPatterns require access to Web Awesome Pro
  • Migrating from Shoelace
  • Visual Tests
  • Changelog
  • Help & Support

Theming & Utilities

  • Overview
  • Built-in Themes
  • Color Palettes
  • Design Tokens
  • Customizing & Theming
  • CSS Utilities

Actions

  • Button
  • Button Group
  • Copy Button
  • Dropdown
    • Dropdown Item

Forms

  • Checkbox
  • Checkbox Group
  • Color Picker
  • Combobox ProThis requires access to Web Awesome Pro
  • Date Input ProThis requires access to Web Awesome Pro
  • Date Picker ProThis requires access to Web Awesome Pro
  • File Input ProThis requires access to Web Awesome Pro
  • Input
  • Known Date
  • Number Input
  • OTP Input
  • Radio Group
    • Radio
  • Rating
  • Select
    • Option
  • Slider
  • Switch
  • Textarea
  • Time Input

Layout

  • Accordion
    • Accordion Item
  • Card
  • Details
  • Dialog
  • Divider
  • Drawer
  • Page
  • Scroller
  • Split Panel

Navigation

  • Breadcrumb
    • Breadcrumb Item
  • Pagination
  • Tab Group
    • Tab
    • Tab Panel
  • Tree
    • Tree Item

Feedback

  • Badge
  • Callout
  • Progress Bar
  • Progress Ring
  • Skeleton
  • Spinner
  • Tag
  • Toast
    • Toast Item
  • Tooltip

Media

  • Animated Image
  • Avatar
  • Carousel
    • Carousel Item
  • Comparison
  • Icon
  • Markdown
  • QR Code
  • Video ProThis requires access to Web Awesome Pro
  • Video Playlist ProThis requires access to Web Awesome Pro
  • Zoomable Frame

Data Viz ProThis requires access to Web Awesome Pro

  • Bar Chart
  • Bubble Chart
  • Data Grid
  • Doughnut Chart
  • Line Chart
  • Pie Chart
  • Polar Area Chart
  • Radar Chart
  • Scatter Chart
  • Sparkline
  • Advanced Usage

Helpers

  • Animation
  • Format Bytes
  • Format Date
  • Format Number
  • Include
  • Intersection Observer
  • Mutation Observer
  • Popover
  • Popup
  • Random Content
  • Relative Time
  • Resize Observer

File Input

  • Examples
  • Label
  • Hint
  • Multiple
  • Accepting File Types
  • Capturing from a Camera
  • Disabled
  • Size
  • Custom Dropzone Content
  • Working with Files
  • Uploading with Forms
  • Validation
  • Custom Validity
  • Styling Validation States
  • API
  • Importing
  • Slots
  • Attributes & Properties
  • Methods
  • Events
  • Custom States
  • CSS Parts
  • Dependencies
On This Page...
  • Examples
  • Label
  • Hint
  • Multiple
  • Accepting File Types
  • Capturing from a Camera
  • Disabled
  • Size
  • Custom Dropzone Content
  • Working with Files
  • Uploading with Forms
  • Validation
  • Custom Validity
  • Styling Validation States
  • API
  • Importing
  • Slots
  • Attributes & Properties
  • Methods
  • Events
  • Custom States
  • CSS Parts
  • Dependencies

File Input

<wa-file-input>
ProIncluded with Web Awesome Pro Stable Forms Since 3.2

File inputs allow users to select files from their device.

Get File Input with Web Awesome Pro! Subscribing to Web Awesome Pro gives you every Pro component, plus premium themes, color tools, team collaboration, and more.
  • Pro Components
  • Responsive Layout Tools
  • Ever-Growing Pattern Library
  • Unlimited Hosted Projects
  • Pre-Built Pro Themes
  • Pro Theme Builder
  • Pro Color Tools
  • Official Figma Design Kit Newer additions to Web Awesome, like <wa-toast>, aren't included in the currently available kit, but a new version is in the works.
    Track its progress on GitHub.
  • WA Pro Perpetual License
  • Actual Human™ Support
Get Web Awesome Pro + File Input!

Already have Pro? Log in

File inputs allow users to select one or more files from their device using a dropzone that supports both click and drag-and-drop interactions.

<wa-file-input label="Select a file"></wa-file-input>
<wa-file-input label="Profile photo" hint="PNG or JPG, up to 5 MB."></wa-file-input>

This component works with standard <form> elements. Please refer to the section on form controls to learn more about form submission and client-side validation.

Examples

Link to This Section

Label

Link to This Section

Use the label attribute to give the file input an accessible label. For labels that contain HTML, use the label slot instead.

<wa-file-input label="Upload your resume"></wa-file-input>

Hint

Link to This Section

Add a descriptive hint with the hint attribute. For hints that contain HTML, use the hint slot instead.

<wa-file-input label="Profile photo" hint="Upload a photo to personalize your account."></wa-file-input>

Multiple

Link to This Section

Add the multiple attribute to allow the file input to accept more than one file. If the user drops a folder, all files within it will be added to the file input.

<wa-file-input label="Upload documents" hint="You can select multiple files at once." multiple></wa-file-input>

Accepting File Types

Link to This Section

Use the accept attribute to limit the file input to certain file types. Set it to a comma-separated string of unique file type specifiers.

<wa-file-input
  label="Upload an image"
  hint="Only JPEG, PNG, GIF, and WebP images are allowed."
  accept="image/jpeg, image/png, image/gif, image/webp"
></wa-file-input>

You can also use file extensions such as accept="pdf, .doc, .docx".

<wa-file-input label="Upload a document" hint="PDF and Word documents only." accept=".pdf, .doc, .docx"></wa-file-input>

Capturing from a Camera

Link to This Section

On mobile devices, use the capture attribute to capture media directly from the device's camera or microphone instead of selecting an existing file. Set it to user for the front-facing camera or environment for the rear-facing one.

The capture attribute is only used when accept includes an image, video, or audio type. On desktop browsers and devices without the corresponding hardware, it is ignored and the file input behaves normally.

<wa-file-input
  label="Take a photo"
  hint="Opens the rear-facing camera on supported mobile devices."
  accept="image/*"
  capture="environment"
></wa-file-input>

Disabled

Link to This Section

Use the disabled attribute to disable the file input.

<wa-file-input label="Upload disabled" disabled></wa-file-input>

Size

Link to This Section

Use the size attribute to change the file input's size.





<wa-file-input label="Extra Small" size="xs"></wa-file-input>
<br />
<wa-file-input label="Small" size="s"></wa-file-input>
<br />
<wa-file-input label="Medium" size="m"></wa-file-input>
<br />
<wa-file-input label="Large" size="l"></wa-file-input>
<br />
<wa-file-input label="Extra Large" size="xl"></wa-file-input>

Custom Dropzone Content

Link to This Section

Use the dropzone slot to customize what appears inside the dropzone area.

Drag and drop your files here or click to browse
<wa-file-input label="Upload files" multiple>
  <div slot="dropzone" style="display: flex; flex-direction: column; align-items: center; gap: 0.5rem;">
    <wa-icon name="cloud-arrow-up" style="font-size: 2.5rem;"></wa-icon>
    <strong>Drag and drop your files here</strong>
    <span style="color: var(--wa-color-neutral-on-quiet);">or click to browse</span>
  </div>
</wa-file-input>

Working with Files

Link to This Section

The files property gives you access to an array of selected files. Unlike the native file input's FileList, this is a standard JavaScript array, making it easier to manipulate.

Reverse Order Clear All Log Files
<div>
  <wa-file-input
    id="file-input-demo"
    label="Select some files"
    hint="Try the buttons below after selecting files."
    multiple
  ></wa-file-input>

  <wa-divider></wa-divider>

  <div class="wa-cluster">
    <wa-button id="reverse-btn" appearance="filled">Reverse Order</wa-button>
    <wa-button id="clear-btn" appearance="filled">Clear All</wa-button>
    <wa-button id="log-btn" appearance="filled">Log Files</wa-button>
  </div>
</div>

<script>
  const fileInput = document.getElementById('file-input-demo');
  const reverseBtn = document.getElementById('reverse-btn');
  const clearBtn = document.getElementById('clear-btn');
  const logBtn = document.getElementById('log-btn');

  reverseBtn.addEventListener('click', () => {
    fileInput.files = fileInput.files.toReversed();
  });

  clearBtn.addEventListener('click', () => {
    fileInput.files = [];
  });

  logBtn.addEventListener('click', () => {
    console.log('Selected files:', fileInput.files);
  });
</script>

The files property must be reassigned, not mutated! Avoid using functions that mutate the array, such as reverse() and sort(), because they won't trigger an update. Use non-mutating alternatives like toReversed() and toSorted() instead.

Uploading with Forms

Link to This Section

When uploading files from a form, add method="post" and enctype="multipart/form-data" to the form so files are sent correctly to the server.


Upload
<form id="upload-form" method="post" enctype="multipart/form-data" action="about:blank">
  <wa-file-input name="documents" label="Select files to upload" multiple></wa-file-input>
  <br />
  <wa-button appearance="filled" type="submit" variant="brand">Upload</wa-button>
</form>

<script>
  const form = document.getElementById('upload-form');

  form.addEventListener('submit', event => {
    event.preventDefault();
    const formData = new FormData(form);
    console.log('Files to upload:', [...formData.getAll('documents')]);
  });
</script>

Validation

Link to This Section

Add the required attribute to make file selection mandatory. Form submission will be blocked until a file is selected.


Submit Reset
<form id="required-form" action="about:blank" method="get">
  <wa-file-input name="file" label="Required file" hint="You must select a file to submit." required></wa-file-input>
  <br />
  <wa-button appearance="filled" type="submit" variant="brand">Submit</wa-button>
  <wa-button type="reset" appearance="filled">Reset</wa-button>
</form>

Custom Validity

Link to This Section

Use the setCustomValidity() method to set a custom error message. This will override standard validation and prevent form submission. Clear the error by passing an empty string.


Submit Reset
<form id="custom-validation-form" action="about:blank" method="get">
  <wa-file-input
    id="custom-file-input"
    name="file"
    label="Upload a small file"
    hint="Files must be smaller than 500 KB."
  ></wa-file-input>
  <br />
  <wa-button appearance="filled" type="submit" variant="brand">Submit</wa-button>
  <wa-button type="reset" appearance="filled">Reset</wa-button>
</form>

<script type="module">
  const form = document.getElementById('custom-validation-form');
  const fileInput = document.getElementById('custom-file-input');
  const maxSize = 500 * 1024; // 500 KB

  fileInput.addEventListener('change', () => {
    const tooLarge = fileInput.files.some(file => file.size > maxSize);

    if (tooLarge) {
      fileInput.setCustomValidity('One or more files exceed the 500 KB limit.');
    } else {
      fileInput.setCustomValidity('');
    }
  });

  // Don't actually submit in the demo
  form.addEventListener('submit', event => {
    event.preventDefault();
  });
</script>

Styling Validation States

Link to This Section

Use the :state(user-valid) and :state(user-invalid) custom states to style the file input based on its validation status. These states only apply after the user has interacted with the control or attempted to submit the form.


Submit Reset
<form id="styling-form" action="about:blank" method="get" class="validation-styles">
  <wa-file-input name="file" label="Select a file" required></wa-file-input>
  <br />
  <wa-button appearance="filled" type="submit" variant="brand">Submit</wa-button>
  <wa-button type="reset" appearance="filled">Reset</wa-button>
</form>

<style>
  .validation-styles wa-file-input:state(user-valid) {
    outline: solid 2px var(--wa-color-success-fill-loud);
    outline-offset: 0.5rem;
  }

  .validation-styles wa-file-input:state(user-invalid) {
    outline: solid 2px var(--wa-color-danger-fill-loud);
    outline-offset: 0.5rem;
  }
</style>

You can also style based on the :state(blank) and :state(dragging) states:

<wa-file-input class="drag-styles" label="Watch the border change while dragging" multiple></wa-file-input>

<style>
  .drag-styles::part(dropzone) {
    transition: transform 0.2s ease;
  }

  .drag-styles:state(dragging)::part(dropzone) {
    transform: scale(1.02);
  }
</style>

API

Link to This Section

Importing

Link to This Section

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.

CDN npm Self-Hosted React

Import this component directly from the CDN:

import 'https://ka-f.webawesome.com/[email protected]/components/file-input/file-input.js';

After installing Web Awesome via npm, import this component:

import '@awesome.me/webawesome/dist/components/file-input/file-input.js';

If you're self-hosting Web Awesome, import this component from your server:

import './webawesome/dist/components/file-input/file-input.js';

To import this component for React 18 or below, use the following code:

import WaFileInput from '@awesome.me/webawesome/dist/react/file-input/index.js';

Slots

Link to This Section

Learn more about using slots.

Name Description
dropzone Custom content to show in the dropzone.
hint Text that describes how to use the file input. Alternatively, you can use the hint attribute.
label The file input's label. Alternatively, you can use the label attribute.

Attributes & Properties

Link to This Section

Learn more about attributes and properties.

Name Description Reflects
accept
accept
A comma-separated list of acceptable file types. Must be a list of unique file type specifiers.
Type string
Default ''
capture
capture
On mobile devices, specifies which camera or microphone to use for capturing media. Use user for the front-facing camera/microphone or environment for the rear-facing one. This attribute is only used when accept includes an image, video, or audio type and may be ignored on devices that lack the corresponding hardware.
Type 'user' | 'environment'
disabled
disabled
Disables the form control.
Type boolean
Default false
dragging
Whether files are being dragged over the dropzone.
Type boolean
Default false
fileCount
The number of selected files. Used for validation.
Type number
files
The selected files.
Type File[]
Default []
form
By default, form controls are associated with the nearest containing <form> element. This attribute allows you to place the form control outside of a form and associate it with the form that has this id. The form must be in the same document or shadow root for this to work.
Type HTMLFormElement | null
hint
hint
The file input's hint. If you need to display HTML, use the hint slot instead.
Type string
Default ''
label
label
The file input's label. If you need to display HTML, use the label slot instead.
Type string
Default ''
multiple
multiple
Allows more than one file to be selected.
Type boolean
Default false
name
name
The name of the input, submitted as a name/value pair with form data.
Type string | null
Default null
required
required
Makes the file input a required field.
Type boolean
Default false
size
size
The file input's size.
Type 'xs' | 's' | 'm' | 'l' | 'xl' | 'small' | 'medium' | 'large'
Default 'm'
validationTarget
Override this to change where constraint validation popups are anchored.
Type undefined | HTMLElement
validators
Validators are static because they have observedAttributes, essentially attributes to "watch" for changes. Whenever these attributes change, we want to be notified and update the validator.
Type Validator[]
Default []
withHint
with-hint
Only required for SSR. Set to true if you're slotting in a hint element so the server-rendered markup includes the hint before the component hydrates on the client.
Type boolean
Default false
withLabel
with-label
Only required for SSR. Set to true if you're slotting in a label element so the server-rendered markup includes the label before the component hydrates on the client.
Type boolean
Default false

Methods

Link to This Section

Learn more about methods.

Name Description Arguments
blur() Removes focus from the file input.
focus() Sets focus on the file input. options: FocusOptions
formStateRestoreCallback() Called when the browser is trying to restore element’s state to state in which case reason is "restore", or when the browser is trying to fulfill autofill on behalf of user in which case reason is "autocomplete". In the case of "restore", state is a string, File, or FormData object previously set as the second argument to setFormValue. state: string | File | FormData | null, reason: 'autocomplete' | 'restore'
resetValidity() Reset validity is a way of removing manual custom errors and native validation.
setCustomValidity() Do not use this when creating a "Validator". This is intended for end users of components. We track manually defined custom errors so we don't clear them on accident in our validators. message: string

Events

Link to This Section

Learn more about events.

Name Description
blur Emitted when the dropzone loses focus.
change Emitted when files are added or removed.
focus Emitted when the dropzone gains focus.
input Emitted when file selection changes.
wa-invalid Emitted when the form control has been checked for validity and its constraints aren't satisfied.

Custom States

Link to This Section

Learn more about custom states.

Name Description CSS selector
blank No files selected. :state(blank)
dragging Files being dragged over dropzone. :state(dragging)

CSS Parts

Link to This Section

Learn more about CSS parts.

Name Description CSS selector
dropzone The drag-and-drop area. ::part(dropzone)
dropzone-icon The upload icon in the dropzone. ::part(dropzone-icon)
dropzone-text The instruction text in the dropzone. ::part(dropzone-text)
file Individual file item container. ::part(file)
file-details Container for file name and size. ::part(file-details)
file-icon The icon for non-image files. ::part(file-icon)
file-image The image element for image thumbnails. ::part(file-image)
file-input The component's outer wrapper. ::part(file-input)
file-list The container for selected files. ::part(file-list)
file-name The file name text. ::part(file-name)
file-size The file size text. ::part(file-size)
file-thumbnail The thumbnail/icon container for a file. ::part(file-thumbnail)
form-control-label The label. ::part(form-control-label)
hint The hint element. ::part(hint)
remove-button The remove button for each file. ::part(remove-button)
base Deprecated. Use the file-input part instead. ::part(base)
label Deprecated. Use the form-control-label part instead. ::part(label)

Dependencies

Link to This Section

This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.

  • <wa-button>
  • <wa-format-bytes>
  • <wa-icon>
  • <wa-spinner>
Need a hand? Report a bug Ask for help
Go Make Something Awesome
Version 3.11.0 © Fonticons, Inc.
  • Terms
  • Privacy
  • Refunds
  • Core License
  • Pro License

Quick Links

  • Components
  • CSS Utilities
  • Theming
  • Using with AI
  • Changelog
  • Help & Support

Recent Searches

    D'oh! No results for “”

    Suggest on GitHub Ask on Discord
    Navigate Select
    Close Esc

    We Have Cookies…

    We use cookies to make webawesome.com work better by storing limited information about your usage.

    We value your privacy, so we won't use them for evil or ask you to join the dark side.

    Customize
    Necessary Only Accept All
    Strictly Necessary
    Required to make the site function correctly — cannot be turned off
    Functionality Analytics
    Cancel Confirm Cookie Choices