Skip to content

Bootstrap 4 File Input

I am struggling with bootstrap 4 file browser. If I use custom-file-control I will see Choose file value all the time.

I would like to change the value of choose file after the file has been chosen. This value is actually hidden in css .custom-file-control:lang(en)::after and I do not know how to access and change it in javascript. I can get the value of chosen file like this:


not I need to change

.custom-file-control:lang(en)::after {
    content: "Choose file...";





Updated 2021

Bootstrap 5

Custom file input no longer exists so to change Choose file... you’d need to use JS or some CSS like this.

Bootstrap 4.4

Displaying the selected filename can also be done with plain JavaScript. Here’s an example that assumes the standard custom-file-input with label that is the next sibling element to the input…

  var fileName = document.getElementById("myInput").files[0].name;
  var nextSibling =
  nextSibling.innerText = fileName

Bootstrap 4.1+

Now in Bootstrap 4.1 the “Choose file…” placeholder text is set in the custom-file-label:

<div class="custom-file" id="customFile" lang="es">
        <input type="file" class="custom-file-input" id="exampleInputFile" aria-describedby="fileHelp">
        <label class="custom-file-label" for="exampleInputFile">
           Select file...

Changing the “Browse” button text requires a little extra CSS or SASS. Also notice how language translation works using the lang="" attribute.

.custom-file-input ~ .custom-file-label::after {
    content: "Button Text";
} (CSS) (SASS)

Another Bootstrap 4.1 Option

Alternatively you can use this custom file input plugin

Bootstrap 4 Alpha 6 (Original Answer)

I think there are 2 separate issues here..

<label class="custom-file" id="customFile">
        <input type="file" class="custom-file-input">
        <span class="custom-file-control form-control-file"></span>

1 – How the change the initial placeholder and button text

In Bootstrap 4, the initial placeholder value is set on the custom-file-control with a CSS pseudo ::after element based on the HTML language. The initial file button (which isn’t really a button but looks like one) is set with a CSS pseudo ::before element. These values can be overridden with CSS..

#customFile .custom-file-control:lang(en)::after {
  content: "Select file...";

#customFile .custom-file-control:lang(en)::before {
  content: "Click me";

2 – How to get the selected filename value, and update the input to show the value.

Once a file is selected, the value can be obtained using JavaScript/jQuery.

    var fileName = $(this).val();

However, since the placeholder text for the input is a pseudo element, there’s no easy way to manipulate this with Js/jQuery. You can however, have a another CSS class that hides the pseudo content once the file is selected…

.custom-file-control.selected:lang(en)::after {
  content: "" !important;

Use jQuery to toggle the .selected class on the .custom-file-control once the file is selected. This will hide the initial placeholder value. Then put the filename value in the .form-control-file span…

  var fileName = $(this).val();

You can then handle the file upload or re-selection as needed.

Demo on Codeply (alpha 6)

User contributions licensed under: CC BY-SA
8 People found this is helpful