Skip to main content

Basic usage

A dashed drop area with a link-style label. The whole area opens the file picker; the real <input type="file"> is hidden but keeps the keyboard focus, so Tab, Enter and Space work. Without multiple a new file replaces the old one.

Resume

or drag and drop PDF or Word

One file. Choosing another replaces it.

Multiple images

Add multiple and the field keeps a list. Images get a thumbnail; other files get an icon. Each row has a button named “Remove” plus the file name, and a hidden status line tells a screen reader how many files are selected.

Product photos

or drag and drop JPG, PNG or WebP, up to 2 MB each, 5 photos

The first photo is the cover.

Limits and errors

A file with the wrong type, a file over maxSize and files past maxFiles are not added. The reasons are listed under the field (role="alert") and the drop area turns red with aria-invalid. The next change clears them.

Logo

or drag and drop PNG only, up to 100 KB each, 2 files

Try a JPG, a larger image or a third file to see the messages.

States

disabled turns the area off and fades it. required is native: the form will not submit until a file is chosen, because the chosen files are set on the input. error shows a message from the server and turns the area red.

Disabled

or drag and drop Not available

Invoice

or drag and drop PDF

Press Submit without a file to see the browser message.

Contract

or drag and drop PDF, up to 5 MB

The file could not be scanned. Upload it again.

Options reference

Two numbers go in x-data="fileUpload({ … })". The rest is plain HTML on the <input type="file">.

Option Type Default Description
maxFiles number 0 (no limit) Most files the field holds. Only with multiple. Files past the limit are skipped and the error is listed.
maxSize number (bytes) 0 (no limit) Largest size of one file, for example 2 * 1024 * 1024 for 2 MB.
multiple input attribute one file Several files. Without it a new file replaces the old one.
accept input attribute any file The same values as the browser: .pdf, image/png, image/*. It filters the picker and the same rule checks dropped files.
name input attribute – The chosen files are set on the input, so a form posts them under this name.
required, disabled input attributes – Native: required blocks the form until a file is chosen, disabled turns the whole field off.
upload-change event – Fires on the root after every change, with { files }: the accepted File objects.
files, errors properties – The selected items ({ id, file, name, size, url }) and the messages of the last change, for your own markup.