The ::file-selector-button pseudo-element addresses the button inside a file input. It can style that button without removing the input, its keyboard behavior, or the platform file picker. It does not style the adjacent filename text, validate the file, or upload bytes.
CSS ::file-selector-button: style the picker without replacing it
When to use it
A claims desk accepts a supporting document. The file input has a visible label and stays in the form, while the picker button gets a modest border, padding, and color that fit the surrounding controls. Keep the control's own filename display so the reviewer can see what was chosen. Test a long filename, no file chosen, multiple selected files, keyboard focus, touch selection, high zoom, and forced colors. The button text can vary by browser and locale, so do not size the button for one English phrase. The input's focus-visible outline belongs on the input as a whole; a hover color on the internal button is only an extra pointer cue. Accept is only a picker hint. The server must check type, size, and content before storing evidence. If a custom upload workflow is needed, implement it deliberately in application code instead of hiding the native input and pretending a painted span is a form control.
.evidence-upload { font: inherit; color: #173441; max-inline-size: 100%; }
.evidence-upload::file-selector-button { font: inherit; padding: .55rem .8rem; margin-inline-end: .7rem; border: 1px solid #426375; border-radius: .3rem; background: #edf4f7; color: #173441; }
.evidence-upload:focus-visible { outline: 3px solid #1c5e87; outline-offset: 3px; }Cost and verification
The style rule is cheap. The practical cost is platform testing: browser chrome around the filename and the button may differ, and file pickers remain system UI. Avoid a fixed inline width that truncates a localized button label or hides the selected filename. A native input can expose its label and chosen file without extra JavaScript; removing it often creates more work and more accessibility failures. Test the no-CSS state and verify that a file can still be selected and submitted. CSS cannot scan content, show upload progress, or recover from a rejected server response; those behaviors require a real backend and visible messages.
Common Mistakes
- Do not hide the input just to draw a button-shaped replacement.
- Do not treat accept or the button color as file validation.
- Do not clip long chosen filenames without another way to inspect them.
