::file-selector-button CSS Pseudo Element
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
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
Tablets & Mobile
Last updated by CSSPortal on: 31st December 2025
