0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Tells a file input which file types to offer, by extension or MIME type. It filters the picker but is only a hint; Vanilla Breeze's data-upload applies the same rules to dropped files.
Overview
accept lists the file types a file input expects. The operating system's picker uses it to filter what is shown, and on phones it decides whether to offer the camera, photo library or file browser. It does not validate: the user can usually switch the picker to "All files", and nothing stops a renamed file. Always check files on the server.
<form-field><labelfor="cv">CV</label><inputtype="file"id="cv"name="cv"accept=".pdf,.docx,application/pdf" /><outputclass="hint"for="cv">PDF or Word, up to 5 MB.</output></form-field><form-field><labelfor="photos">Project photos</label><inputtype="file"id="photos"name="photos"accept="image/*"multipledata-upload /></form-field>
Values
A comma-separated list of tokens. A file is offered if it matches any token. Matching is case-insensitive.
Token
Matches
.pdf, .docx
File names ending in that extension.
application/pdf
Files of that exact MIME type.
image/*, audio/*, video/*
Any image, audio or video file.
Absent or empty
Any file (the default).
List both the extension and the MIME type when you can (.pdf,application/pdf). Operating systems differ in which they use to filter.
Examples
Camera capture on phones
With an image or video accept, the captureattribute asks a phone to open the camera directly: environment for the rear camera, user for the front. Desktop browsers ignore it.
Inside <form-field>, a custom validity message like this one is shown in the field's output.error.
In Vanilla Breeze
data-upload wraps a file input in a drop zone. Dropped files are checked against accept with the picker's rules (.ext against the name, type/* against the MIME family, anything else as an exact MIME type); files that don't match are left out and named in a polite status line. Without multiple, only the first accepted file is kept. The zone's prompt lists the accepted types in words: .pdf and application/pdf read "PDF", image/* reads "images" (data-label-images, -audio, -video translate the wildcard words), and other MIME types show as written (src/utils/upload-init.js).
Not the same as data-accept.data-accept is a keystroke filter for text inputs (data-accept="digits", "phone", "[0-9a-f]") that also sets a matching inputmode. It has nothing to do with files.
File input styling lives in src/native-elements/input/file.css; see <input>.
Accessibility
Say which types and sizes are allowed in visible hint text. Users can't see the filter until they open the picker, and a rejected file is frustrating to discover after choosing it.
A drop zone must not be the only way in. data-upload keeps the native input as the single, focusable control, so keyboard and screen-reader users can open the picker.
Security
accept is a convenience, not a control. Check the file's real type on the server from its contents, not its name or the browser-reported MIME type, and enforce size limits there.
Treat file names as untrusted text: escape them when you display them, and don't use them as storage paths.
Be careful with image/*: it includes SVG, which can contain script. Serve uploaded SVG with a restrictive Content-Type and Content-Security-Policy, or convert it, or list the raster types you want (image/png,image/jpeg,image/webp).
Browser support
accept works in every browser. capture works only in mobile browsers: Chrome for Android 25, Safari on iOS 10, Firefox for Android 79; desktop browsers ignore it.
Gotchas
Dragging a file onto a plain file input bypasses the picker's filter in some browsers. Use data-upload, which filters drops, or check in change.
MIME types for the same file differ between systems (a .csv may be text/csv, application/vnd.ms-excel or empty). Prefer extensions for document formats.
Related
data-upload — drop zone and file list that respect accept