Add CSS style to input type=file | Custom file input
Short tutorial to add css styles to input type=file field on a website using : :file-selector-button pseudo selector for **Webkit/Blink** browsers.
In this article, we will see how we can create a custom file input by styling the input field of type='file' using CSS.
To build a button/field to upload files and images we most commonly use the input field and set the type attribute to file.
<input type="file">
We get an output like this on our webpage.

Next, we will style the input field using CSS to make it look like a button.
To hide the default "choose file" button, we will use the ::file-selector-button pseudo selector.
input::file-selector-button { visibility: hidden; } /* Chrome, Edge & Safari */ input::-webkit-file-upload-button { visibility: hidden; }
The ::file-selector-button pseudo selector is used for representing an input field with type="file".
Note: If you are using an older version of WebKit browsers like chrome, opera, or safari, you have to use a non-standard pseudo-element
::webkit-file-upload-button.
Now once that is done, we can add a class to the input field and add some CSS styles
input::file-selector-button { visibility: hidden; } .input-upload { color: transparent; } .input-upload::before { content: "Select some files"; display: inline-block; background: yellowgreen; border: 1px solid #999; border-radius: 3px; padding: 5px 8px; cursor: pointer; color: black; }
So the result of the CSS will be like this

DEMO CODE:
<a href="https://codesandbox.io/s/input-styling-tficc0?fontsize=14&hidenavigation=1&theme=dark"> <img alt="Edit input-styling" src="https://codesandbox.io/static/img/play-codesandbox.svg"> </a>So, this is how you can create a custom file input for your HTML form using CSS styling.
Related Posts
How to create a horizontal list using HTML and CSS
Find out different ways to create horizontal list using inline-block and flex-box in CSS for your navigation bar on your website.
How to use calc() in tailwind CSS
Learn the use of calc() in tailwind CSS class. The calc() CSS function allows complex calculations to determine element sizes responsively.
Vertically Center Align a div in Tailwind CSS
Learn how to vertically center align a div in Tailwind CSS using Flexbox and absolute positioning and make your web development more efficient and fast.
Create a vertical line using Html and Css
Learn with step-by-step instruction on how to add vertical line in HTML using CSS border, transform and pseudo classes.
