32

I can't seem to figure out any way to remove the "No file selected" text that shows up next to inputs of type "file".

Do you guys know any way how to remove this text?

enter image description here

Andreas
  • 5,393
  • 9
  • 44
  • 53
Peter
  • 2,276
  • 4
  • 32
  • 40
  • 3
    adding this to the input seemed to work in webkit.... style="width: 80px; height: 25px; overflow: hidden;" – Peter May 24 '11 at 02:55
  • Possible duplicate: http://stackoverflow.com/questions/1084925/input-type-file-show-only-button – Thom Smith May 24 '11 at 05:26

9 Answers9

46
input[type='file'] {
  color: transparent;
}

Enjoy

Ajey
  • 7,924
  • 12
  • 62
  • 86
  • 1
    Mouseover or cursor-change is still there. – MERose Feb 17 '16 at 22:29
  • I just spent an hour trying half a dozen different techniques off stackexchange to do this - all more complicated and not one of them worked on late model Firefox on Linux. Your method is simple, elegant and works perfectly. Thank you. – jkcunningham Jan 31 '22 at 03:29
14

There is no cross-browser way to do this. The "no file selected" text is in the implementation-defined part of the widget, and I don't believe that most browsers offer much in the way of browser-specific customization. On the other hand, you could simply use CSS to cover the text with something when the value attribute is empty.

Thom Smith
  • 13,916
  • 6
  • 45
  • 91
9

You can do this by defining a width to the input and hiding the exceeding content (the undesired "No file selected" text).

input {
    width: 132px;
    overflow:hidden;
}

Here is the demonstration on jsfiddle.

Beware: each language has its own default text and it may render different input sizes. In brazilian portuguese that 132px width is fine!

My answer was based on this similar question on stackoverflow.

Community
  • 1
  • 1
LuAmbros
  • 181
  • 2
  • 14
2

You can replace the file field with a button with the answer to this question: file upload button without input field?

Community
  • 1
  • 1
BrightIntelDusk
  • 4,577
  • 2
  • 25
  • 34
1

This is a really good hack and its a lot cleaner.

HTML

<div id="file_info' style='display:inline;'>Browse</div>
<input type="file" name='file[]' multiple style='opacity: 0;' onchange='displayFileName()'/>

JS

function displayFileName() {
    var files = $('input[type="file"]')[0].files;
    document.getElementById('file_info').innerHTML = files.length + " images to upload";`
}
AlexB
  • 7,302
  • 12
  • 56
  • 74
Carlos Pliego
  • 859
  • 1
  • 8
  • 19
1
CSS
<style>
#image_file{
   position: relative;
   width: 188px;
   border: 1px solid #BBB;
   margin: 1px;
   cursor: pointer;
   float: left;
  }
</style>

HTML
<input id="image_file" onclick="getFile()" onfocus="this.blur()" value=""/>
<div style='height: 0px;width: 0px; overflow:hidden;'>
    <input type="file" id="PinSpot_file">
</div>
<input type="button" onclick="getFile()" style="background-color: #DDD;" value="Browser" >


JAVASCRIPT
function getFile(){
   document.getElementById("PinSpot_file").click();
 }

// Event when change fields
$('#PinSpot_file').live('change', function(e) {     
  var file = this.value;
  var fileName = file.split("\\");
  document.getElementById("image_file").value = fileName[fileName.length-1];

   //AJAX
}
Luan Dang
  • 629
  • 5
  • 2
1

Well, since there is no way to completely disable the text, I'd suggest either placing an element over the text or try the following solution..

CSS

input[type="file"] {
width: 90px; /* Keep it under 100px in order to hide the unwanted text. */
}

and add an html inline-title attribute to the element to hide the "No File Chosen" hover text.

HTML

<input type="file" id="FileId" title="">

or, you could do it all with JavaScript.

JS

document.addEventListener('DOMContentLoad', myFunction);

function myFunction() {
const FilePicker = document.getElementById('FileId');
FilePicker.style.width = "90px";
FilePicker.title = ""; // Leave This Empty
}
Seth M.
  • 11
  • 4
0

I think you cannot. you can using css to hide that label "No File Choosen" by decreasing width of input file control. I have used below code to do it for myself

Css Code

input[type=file] {
    width: 93%;
}
Heemanshu Bhalla
  • 3,603
  • 1
  • 27
  • 53
-2

You can try this. Its work for me firefox browser

<style type="">
    input[type='file'] {
       color: transparent;
    }
</style>
Madhuka Dilhan
  • 1,396
  • 1
  • 14
  • 21