Three Ways To Customize HTML Upload Button
1. Call input.click() With Javascript
Demo at codepen
Pros
- Full freedom to customize the button;
- Widely supported by all browsers;
- I like it very much;
Cons
- Javascript is used with HTML and CSS;
- File input must be uniquely selectable by Javascript;
- Default “input element” isn’t displayed so you must add custom HTML to display uploaded/selected file;
2. Styling Label as a Button
Demo at codepen.
Pros
- Full freedom to customize the button;
- It works with just HTML and CSS;
- Widely supported by all browsers;
- Default “input element” isn’t displayed;
Cons
- Upload “button” isn’t focusable with keyboard;
- Default “input element” isn’t displayed so you must add custom HTML to display uploaded/selected file;
3. Use ::file-selector-button CSS pseudo element
Demo at codepen.
Read more at mdn.
Pros
- Part of CSS specification;
Cons
- Part of “fragile”, “unfinished” and not wiedly supported CSS specification;
- Limited browser support;
- Must use browser-specific pseudo-classes to support different browsers;
- Limited ability to style “input element” next to the button;
- Don’t like it at all;