Custom File Input Styling

Chris Coyier on

If you’re interested in Webkit/Blink/Chrome specific styling, there is a proprietary pseudo element to hide, and then use an also non-standard psudeo-on-an-input:

<input class="custom-file-input" type="file">
.custom-file-input::-webkit-file-upload-button { visibility: hidden; } .custom-file-input::before { content: 'Select some files'; display: inline-block; background: linear-gradient(top, #f9f9f9, #e3e3e3); border: 1px solid #999; border-radius: 3px; padding: 5px 8px; outline: none; white-space: nowrap; -webkit-user-select: none; cursor: pointer; text-shadow: 1px 1px #fff; font-weight: 700; font-size: 10pt; } .custom-file-input:hover::before { border-color: black; } .custom-file-input:active::before { background: -webkit-linear-gradient(top, #e3e3e3, #f9f9f9); }

Demo

Fair warning: it doesn’t show you the file name selected, but you might be able to tweak it to do that. I find typically these days you’re triggering an event after file selection and snagging the data that way anyway.

WTF Forms

Always worth checking out how WTF forms does it also:

You may also be interested in how to style common form elements or form input validation at DigitalOcean.