U.S. flagA digital services project by Flexion

File Input

formUSWDS-derivedinteractive

File upload control with drag-and-drop, preview, and file type validation.

Reference: USWDS documentation ↗

Variants

Default File Input

Image Only

Select any image file (JPG, PNG, GIF)

Multiple Files

Select one or more PDF or Word documents

Contract

Class mapping

USWDSFlexNotes
usa-file-input<flex-file-input> (custom element)Container element
usa-file-input__target.flex-file-input__targetDrop zone / click target
usa-file-input__instructions.flex-file-input__instructionsInstructional text ("Drag file here or choose from folder")
usa-file-input__choose.flex-file-input__choose"choose from folder" styled link text
usa-file-input__input.flex-file-input__inputHidden native file input positioned over target
usa-file-input__preview.flex-file-input__previewIndividual file preview card
usa-file-input__target (drag active).flex-file-input__target[data-drag-active]Drag highlight state via data attribute
has-invalid-file.flex-file-input__target--errorError state when file type is invalid

Verified properties

displaymax-widthwidthborder-stylefont-sizetext-alignposition

Behavior promises

  • ✓ Drag highlight appears on dragenter/dragover
  • ✓ Drag highlight removed on dragleave/drop
  • ✓ File selection displays file name and size in preview
  • ✓ Image files show thumbnail preview
  • ✓ Remove button removes file from preview
  • ✓ Invalid file type shows error state

Source CSS