Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

::file-selector-button — styling the file picker button

The `::file-selector-button` pseudo-element styles the button that opens the file picker in `input[type="file"]`. It targets only that button, not the whole control or the file picker dialog.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate

Syntax

input[type="file"]::file-selector-button { /* declarations */ }

::file-selector-button represents the button that opens a file picker, if the browser renders one. It is a pseudo-element, not a pseudo-class: it targets a control part rather than a state.

The selector input[type="file"]::file-selector-button limits the rule to file-input buttons. It does not target the selected filename text or the file picker dialog itself. You do not need to add a separate button element to the document.

The specification places no restriction on which CSS properties apply to this pseudo-element. The example sets a border, padding, and colors without replacing the native control. The button wording and remaining control appearance may depend on the browser and platform.

The example code and its stated styling result were verified. To check whether activating the button opens the file picker, try the example locally. Including Chromium 152 in the entry's scope does not mean the example has been tested in it.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>File selector button</title>
<style>
  input[type="file"]::file-selector-button {
    border: 3px solid green;
    padding: 8px 12px;
    background-color: #eef7ee;
    color: #142814;
  }
</style>
<label for="attachment">Attachment</label>
<input id="attachment" type="file">
</html>

Result

The file input's picker button has a 3px solid green border, 8px vertical and 12px horizontal padding, a #eef7ee background, and #142814 text. Native button wording and remaining control appearance may vary.

The displayed code and its stated styling result were verified. Whether activating the button opens the file picker was not confirmed.

Sources