CSS Reference ยท Pseudo-elements
The ::file-selector-button pseudo-element
Reference for the CSS ::file-selector-button pseudo-element: style the Browse button of a file input, with hover states, spacing and accessibility advice.
The ::file-selector-button pseudo-element selects the button inside an <input type="file">, the part that opens the file picker. The text next to it ("No file chosen") is not part of the button and is styled through the input itself.
Because it is the real native button, keyboard focus, drag-and-drop and screen reader behavior stay intact, which is why it is preferred over hiding the input and faking a button.
input[type="file"]::file-selector-button { background: #1c7ed6; color: #fff; }
Try it
Syntax
input[type="file"]::file-selector-button { }
| Property | Value |
|---|---|
| Applies to | The button of <input type="file"> |
| Inherited | Inherits from the input |
| Animatable | Its properties follow their own animation rules |
Values
The pseudo-element takes no arguments. It accepts the usual button styling:
| Group | Examples |
|---|---|
| Box | padding, margin, border, border-radius, width |
| Color | background, color |
| Text | font, letter-spacing, text-transform |
| Interaction | cursor, transition |
Usage notes
- Hover and active states. Write
input:hover::file-selector-buttonandinput:active::file-selector-button; the pseudo-element itself cannot take:hoverin every browser. - Fonts are not inherited by default. Add
font: inheritto the button if you want it to match the page. - You can't change its label. The text (such as "Choose File") comes from the browser and language. To show other text, use a
<label>styled as a button and visually hide the input, but keep it focusable. - The status text. "No file chosen" is styled with
colorandfonton the input. - Focus. Keep a visible focus style on the input using
:focus-visible. - Old prefix.
::-webkit-file-upload-buttonwas the earlier name. Do not put both selectors in one list.
Browser support
Supported in all current browsers. Very old releases only know the -webkit- prefixed form.
Related
::placeholderappearancecursor- Lesson: Styling forms