How you can style the input file type in forms using CSS
Ordinary input of type file in webpages comes with a default style and the caption, “Choose file”. The good news is that we can style and tweak it to what we want.
<input type="file" accept="image/png, image/jpg, image/gif, image/jpeg"/>
Styling the input file type
There are three steps to styling the input file in forms:
- Wrap the
<input>element with thetype="file"attribute inside a<label>element. Also, we can add more elements or icons within a<label>element.
<label for="inputTag">Select Image<input id="inputTag" type="file"/></label>
- Change the display of the
input[type="file"]tag tononein CSS:
input[type="file"]{display: none;}
- Style the
labelelement:
label{cursor: pointer;}
Code
Conclusion
We have looked at how to style the input file type that normally appears in a default “Choose file” format. One of these ways is to set the display to none. This way, we can style the label and add some icons.