CSS Portal

::file-selector-button CSS Pseudo Element

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The ::file-selector-button pseudo-class is used to style the button portion of an input element when its type attribute is set to file. This pseudo-class targets only the interactive button that triggers the file selection dialog in a file input, allowing developers to customize its appearance independently of the text field that shows the selected file name. By using ::file-selector-button, you can apply standard CSS properties like background, color, border, padding, and font to enhance the user interface in ways that were previously difficult without resorting to custom scripts or hiding the input entirely.

One important feature of ::file-selector-button is that it is considered a "replaced element" pseudo-class. This means that the styles applied to it do not affect the actual input text box that displays the chosen file name. For instance, you can change the button’s background color or border-radius without affecting the file name display area. This separation allows precise control over the button’s aesthetics while maintaining native functionality.

Here’s a practical example of using ::file-selector-button:

<input type="file" id="upload">

<style>
input[type="file"]::file-selector-button {
    background-color: #4CAF50;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
    background-color: #45a049;
}
</style>

In this example, the button portion of the file input has a green background, white text, and rounded corners. Additionally, a hover effect is applied to enhance interactivity. Developers often use ::file-selector-button in combination with other pseudo-classes like :hover to create fully interactive file input buttons. It provides a reliable way to achieve modern, visually appealing file input designs while keeping the native functionality intact.

The ::file-selector-button pseudo-class is supported in most modern browsers and offers an elegant alternative to wrapping file inputs with custom buttons or JavaScript workarounds, making it a preferred choice for contemporary web design.

Syntax

selector::file-selector-button

Example

<body>

<label for="file-upload" class="custom-label">Upload your resume:</label>
<input type="file" id="file-upload" class="modern-input">

</body>
/* Styling the container/text of the input */
.modern-input {
font-family: sans-serif;
color: #555;
padding: 10px;
border: 2px dashed #bbb;
border-radius: 8px;
background-color: #fafafa;
}

/* Targeting the specific 'Choose File' button */
.modern-input::file-selector-button {
border: none;
background: #4a90e2;
padding: 8px 16px;
border-radius: 5px;
color: white;
cursor: pointer;
transition: background .2s ease-in-out;
margin-right: 15px;
}

/* Hover state for the button */
.modern-input::file-selector-button:hover {
background: #357abd;
}

/* Active/Click state */
.modern-input::file-selector-button:active {
background: #2a5f94;
}

Browser Support

The following information will show you the current browser support for the CSS ::file-selector-button pseudo element. Hover over a browser icon to see the version that first introduced support for this CSS psuedo element.

This psuedo element is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 31st December 2025

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!