Detected form widget file upload field accessibility: fix guide

Keep your file upload accessible after the Detected Form widget connects your form: label the input, validate type and size, then test with a keyboard.

James HollowayWeb Development Lead9 min read

Before you connect your existing HTML form to the Detected Form widget, check the file upload field. The widget links the form you already run to WidgetJar, but it does not redesign your markup or replace the native <input type="file">. That means detected form widget file upload field accessibility is still your responsibility, and a few targeted fixes before and after the embed will keep the field usable for keyboard and screen reader visitors.

This guide walks through a practical diagnosis: map the upload field, write a clear label and hint, add validation visitors can act on, repeat the check on the receiving endpoint, and run a keyboard and screen reader test before launch. It assumes you have a working contact or application form and are about to install the embed script on your registered domain.

What the widget changes and what stays yours

The Detected Form widget connects an existing HTML form to WidgetJar. Your file input stays in the form, and the browser still opens the native file picker when a visitor activates the control. What changes is the surrounding submission flow, so the risk is not the file control itself but the assumptions you made about how the form sends data.

File uploads are a special case in HTML forms. According to MDN's guide to sending and retrieving form data, to send files you need three extra steps: set the form's method to POST, set enctype to multipart/form-data, and include one or more file inputs. Binary content cannot travel as URL parameters, so GET is not an option. Confirm that your form still posts to a handler that reads the file, not just the text fields.

If your handler is a third-party form service or a serverless function, treat the file field exactly as you would without the widget: it must arrive at an endpoint you control or at a service that explicitly accepts file parts. The Netlify form walkthrough shows why preserving the original handler attributes matters, and the same discipline applies here.

Map the upload field before you touch the markup

Write down four facts about the field before editing. First, does it have a name attribute? A file input without a name is not submitted at all. Second, is it marked required, and does a visible marker tell sighted users so? Third, what tokens does the accept attribute list, and are those the same formats your handler will store? Fourth, where does the form post, and does that endpoint read multipart bodies?

The accept attribute is a convenience, not a guarantee. It filters the picker dialog in supporting browsers, but a visitor can still choose another file through the "All files" option or by dragging a file in. That is one reason the endpoint check later in this guide exists. Keep the attribute narrow and accurate instead of listing dozens of formats you never process.

Keep the native input in the DOM. If your design calls for a styled "Choose file" button, the reliable pattern is a visible <label> tied to a visually hidden native input, not a div with a click handler. Hiding the input with display: none removes it from the tab order and from the accessibility tree, which breaks keyboard users even if mouse users are fine.

Write the label and hint so the field explains itself

Every file input needs a programmatically associated label. Use <label for="resume"> with a matching id on the input, exactly as you would for a text field. The HTML form labels guide covers wording and pairing in more depth; for uploads the label should name the document, not the action, for example "Portfolio PDF" or "Proof of address".

Then add a hint that states three things in plain text: the accepted formats, any size limit, and whether the document is optional. Do not bury the size limit in an accept attribute or in a tooltip. If the accepted formats are PDF and JPG, write "PDF or JPG, up to 5 MB" in visible text. Tie the hint to the input with aria-describedby so screen reader users hear it when the field receives focus, rather than discovering it only after choosing the wrong file.

A short worked example of the markup pattern:

<div class="field">
  <label for="portfolio">Portfolio PDF</label>
  <p id="portfolio-hint" class="hint">PDF only, up to 5 MB.</p>
  <input
    type="file"
    id="portfolio"
    name="portfolio"
    accept="application/pdf"
    aria-describedby="portfolio-hint"
    required
  >
  <p id="portfolio-error" class="error" role="alert" hidden></p>
</div>

Note the empty error paragraph. It stays empty and hidden until there is something to announce, which avoids a screen reader hearing an error container with no content on page load.

Set validation that visitors can act on

Client-side validation is an initial check that lets visitors fix a problem immediately instead of waiting for a server round trip, as MDN explains in its form validation overview. It is also explicitly not an exhaustive security measure, because client-side checks are easy to bypass. Treat the browser check as courtesy and the endpoint check as enforcement.

For a file input, the browser gives you the required attribute for free: if the visitor submits without choosing a file, the browser blocks submission, focuses the invalid control and shows its own message. That behavior is worth keeping. What the browser does not do for you is reject a file whose size exceeds your limit, so add a short script that inspects the selected file and writes a message into the error paragraph when the file is too large or the wrong type. Clear the message when a new file is chosen, so a stale error does not sit on screen after the visitor fixes it.

Write the message as an instruction, not a verdict. "That file is 9 MB. Please choose a PDF under 5 MB" gives the visitor a next step. If you customize browser messages rather than writing your own, the patterns in customizing native HTML form validation messages show how to use setCustomValidity without breaking built-in behavior. Whatever route you take, keep the error inline next to the field and make sure it is announced; the techniques in contact form error messages that help visitors fix and resubmit apply directly here.

Repeat the type and size check on the receiving endpoint

The browser check is a courtesy. Enforcement belongs wherever the file finally lands. On your endpoint, verify the file size against the same limit, verify the content type and, ideally, the file signature rather than trusting the extension alone, and reject anything that fails with a clear message. If the file is stored, generate the stored name yourself instead of using the visitor's filename.

This matters more, not less, after an embed. Any integration that changes how a form submits is a place where a silent mismatch can hide: a field renamed in the panel, a handler that no longer receives a multipart part, or a validation rule that only existed in the old JavaScript. Re-run the endpoint check against a real submission after the embed is live, not only before.

If the widget adds a consent checkbox to your form, as described in the consent checkbox walkthrough, make sure the consent answer and the file arrive in the same submission. A file that lands without its consent record is harder to justify keeping.

Keyboard and screen reader test script

Run this pass on the live page after the embed is installed, with the mouse unplugged. It takes about ten minutes.

  1. Press Tab from the top of the page and count the stops until you reach the file field. The field must be reachable and must show a visible focus outline.
  2. While focused, confirm the screen reader announces the label and the hint text together, then says the control type, for example "file button".
  3. Press Enter or Space on the control and confirm the native file picker opens. Cancel it and confirm focus returns to the field, not to the top of the page.
  4. Submit with no file selected and confirm the browser focuses the field and its message is announced.
  5. Choose an oversized file and confirm your inline error is announced and readable, and that it clears when you choose a valid file.
  6. Submit a valid file and confirm the confirmation message or redirect reaches you, with the file attached on the receiving side.

If your form opens inside a popup, the surrounding dialog rules matter too. The modal dialog accessibility test script covers focus entry, Tab containment and focus return; the W3C's Dialog (Modal) Pattern explains why focus must move into the dialog on open and return to the invoking element on close. A file picker launched from inside a modal inherits those expectations.

Common breakpoints after the embed

Three failures show up repeatedly once an embed is in place. First, a lost label association: the input was wrapped or moved during a template change, and the for/id pair no longer matches. Screen readers then announce "file button" with no name. Second, a hidden native input with no accessible trigger: a styled button was wired to it with a script that mouse users can click, but the real input is out of the tab order, so keyboard users cannot open the picker. Third, errors announced too late: the message renders visually but is not in a live region or tied to the field with aria-describedby, so a screen reader user submits, waits, and never learns why nothing happened.

Each has a small fix. Re-check the for/id pair after every template change, keep the input focusable even when visually hidden, and give the error container a role that announces updates.

Pre-launch checklist before installing on your domain

  • The file input has a name attribute and sits inside a form with method="post" and enctype="multipart/form-data".
  • The accept tokens list only formats your endpoint actually stores.
  • A visible hint states formats and size limit, and is linked with aria-describedby.
  • The label is associated with the input and the required state is indicated in text, not only by color.
  • Client-side size and type checks write an announced, inline error that clears on a new selection.
  • The endpoint repeats the size and type check and has been tested with a real submission.
  • The keyboard and screen reader script above has been run on the live page.
  • The embed script is installed on the registered website domain, and the form still submits to your original handler.

Where to go next

When the upload field is labeled, validated and tested, connect the rest of the flow. Start with the Detected Form widget page to configure the widget, then run the keyboard pass again after install, because the only test that counts is the one on the page your visitors actually use.

  • detected form widget file upload field accessibility
  • detected form
  • forms
  • accessibility
  • validation

Written by

James Holloway

Web Development Lead at WidgetJar

Keep reading

Get started

Your next lead is one line away.

Pick a design, make it yours and paste a single script tag. Every widget type is included, and you do not need a credit card to start.

<script src="https://cdn.widgetjar.com/wj-assets/embed.js" defer></script>