Replace input type=file by an image

This works really well for me:

.image-upload>input {
  display: none;
}
<div class="image-upload">
  <label for="file-input">
    <img src="https://icons.iconarchive.com/icons/dtafalonso/android-lollipop/128/Downloads-icon.png"/>
  </label>

  <input id="file-input" type="file" />
</div>

Basically the for attribute of the label makes it so that clicking the label is the same as clicking the specified input.

Also, the display property set to none makes it so that the file input isn’t rendered at all, hiding it nice and clean.

Tested in Chrome but according to the web should work on all major browsers. 🙂

EDIT:
Added JSFiddle here: https://jsfiddle.net/c5s42vdz/

Leave a Comment