Dropzone

A box that takes files dropped on it or chosen with a click

Drop images here or click to choose

A name on the input sends the files with the form

Drop attachments here or click to choose

In a field, with a size limit, a type list and help text

Drop a PNG or SVG here, or click to choose
One file, up to 1 MB.

A tile beside existing images

Headphones Mug

A preview of the chosen images, drawn by your own script

Drop images here or click to choose

data-dragging="true" shows the drag-over state

Release to add the images

Disabled, and invalid with an error message

Uploads are turned off
Drop a PNG or SVG here, or click to choose
Add a logo to continue.

Reading change for accepted files and rejected for refused ones

PNG or JPG, up to 200 KB each
Nothing chosen yet.

In a form, FormData.getAll returns the files

Drop photos here or click to choose
Nothing sent yet.

Events

The dropzone never uploads and draws no previews. Its form sends the files. Read them from the input.

Event On Description
input, change input[type=file], bubbles Fired after a pick or a drop. event.target.files holds the accepted files only.
rejected .dropzone, bubbles Fired when a dropped or picked file is refused. event.detail.rejected is a list of { file, reason }, where reason is "type" or "size". Refused files are left off the input. A drop with no accepted file leaves the files already on the input unchanged.

Keyboard

Key Description
Tab Moves focus to the input. The box shows an accent focus ring.
Enter, Space Opens the file picker.

Accessibility

  • The input is the control: give it an aria-label, or a label with for in a field.
  • The upload icon is decoration: keep aria-hidden="true" on it. A tile has no text, so its aria-label is the only name.
  • Link help text with aria-describedby.
  • Set aria-invalid="true" on the input for the invalid look. In a .field[data-invalid] the error text shows; give it role="alert".
  • Dragging is a convenience only. Everything also works by click and keyboard.

Attributes

Attribute / element Values Description
.dropzone The dashed box. It holds the input, an optional icon and a span of text.
data-size tile A 96px square with the icon only, to sit beside thumbnails.
data-max-size bytes The largest file accepted, on .dropzone. Larger files are rejected with reason size.
data-dragging true Set by the script while files are dragged over the box. Write it by hand to show the state.
> input[type=file] name Covers the box. A click opens the picker and the form sends its files.
accept .png, image/png, image/* Comma separated. Checked on dropped and picked files; a mismatch is rejected with reason type.
multiple present Allows several files. Without it only the first dropped file is taken.
disabled present Dims the box. It takes no files.
aria-invalid true Draws the border in the danger colour.
> .icon Decoration, e.g. icon-upload. Keep aria-hidden="true".