Forbes India Leader Recognition
e.preventDefault(); // Prevent form submission input.blur(); // remove focus input.value = ""; // optional: clear the input

Style file upload and browse button

Style file upload and browse button

Featured Image

Developers often find it difficult to make file upload appear same across the browsers OR to style the nasty browse button to match the overall layout of the website.

This article would take help of simple JQuery, CSS and HTML to achieve a fully customized file upload UI that actually looks same across the browsers. Moreover you can also customize that nasty Browse button to merge with the overall styling of your site.

HTML code for custom file upload:

We wrap a ‘html input file’ with ‘html input text’ and simple html button. Notice the classes in the following code.

<input type="text" class="file_input_textbox" readonly="readonly" value='No File Selected'>
<div class="file_input_div">
    <input type="button" value="Browse" class="file_input_button" />
    <input type="file" name="uploaded_file" class="file_input_hidden"/>
</div>

CSS classes for above components

These CSS properties have main role to play while customize UI of our file upload. We do 3 main things using css here:

  • Hide actual file input using class ‘file_input_hidden’
  • Adjust custom browse button using class ‘file_input_button’ and add effect to it using class ‘file_input_button_hover’
  • Adjust text box properties using class ‘file_input_textbox’
<style type="text/css">

.file_input_textbox {height:25px; width:200px; float:left; }

.file_input_div {position: relative; width:80px; height:26px; overflow: hidden; }

.file_input_button {width: 80px; position:absolute; top:0px; border:1px solid #F0F0EE;padding:2px 8px 2px 8px; font-weight:bold; height:25px; margin:0px; margin-right:5px; }

.file_input_button_hover{width:80px;position:absolute;top:0px; border:1px solid #0A246A; background-color:#B2BBD0;padding:2px 8px 2px 8px; height:25px; margin:0px; font-weight:bold; margin-right:5px; }

.file_input_hidden {font-size:45px;position:absolute;right:0px;top:0px;cursor:pointer; opacity:0; filter:alpha(opacity=0); -ms-filter:"alpha(opacity=0)"; -khtml-opacity:0; -moz-opacity:0; }

</style>

You can try following with changes in CSS.

  • Different size for input text box and button
  • Change button background color, background image.
  • Increase text box and button gap, change/remove border for them.
  • Altogether different look by adding/removing browser specific CSS.

JQuery code to add/remove CSS classes on mouseover events.

You can put custom validation code in following Jquery code.
For example onChange() event, we are replacing ‘fakepath’ prefix which is applied by chrome browser.

<script type="text/javascript" src="jquery-1.8.2.min.js"></script>

<script type="text/javascript">

$(document).ready(function() {

  $('.file_input_button').mouseover(function(){
          $(this).addClass('file_input_button_hover');
    });

  $('.file_input_button').mouseout(function(){
        $(this).removeClass('file_input_button_hover');
    });

  $('.file_input_hidden').change(function(){

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

        fileInputVal = fileInputVal.replace("C:\fakepath\", "");

        $(this).parent().prev().val(fileInputVal);

    });
});

</script>

Examples:

Put above code together in one html file and check with your browser. We have tested it with Firefox and Chrome.
Don’t forget to put jquery-1.8.2.min.js in same folder of your html file or load JQuery using Google CDN.
By tweaking CSS elements you can make your File upload look like:

browse button
 
browse button
 
browse button

Related Posts

Latest Posts

  • All Posts
  • AI Powered Knowledge
  • ai/ml
  • CEO India Magazine
  • CMMI level 5 Certification
  • e-learning
  • Fintech
  • gaming
  • Generative AI
  • healthcare
  • manufacturing
  • News
  • OTT
  • Portfolio
  • supply chain
  • travel and hospitality
  • Tudip's AI Hackathon
  • Voxlearn Enterprises
    •   Back
    • Android
    • iOS
    • Java
    • PHP
    • MEAN
    • Ruby
    • DotNet
    • IoT
    • Cloud
    • Testing
    • Roku
    • CMS
    • Python
The Future of Workplace Learning: AI-Powered Knowledge on Demand

The Future of Workplace Learning: AI-Powered Knowledge on Demand

June 12, 2026

A few months ago, I was sitting in a meeting with a team lead who looked genuinely frustrated. Not because…

Read More
We Built VoXlearn Because Enterprise Training Was Broken: Here’s What We Did About It

We Built VoXlearn Because Enterprise Training Was Broken: Here’s What We Did About It

June 12, 2026

If you’ve ever sat through an end-of-quarter training report and thought, “We spent all that time and money, and this…

Read More
We Did It Again: Tudip Successfully Renews Its CMMI Level 5 Certification

We Did It Again: Tudip Successfully Renews Its CMMI Level 5 Certification

June 9, 2026

Nobody around here needed a memo to know something worth celebrating had happened. The message from the CMMI Institute said…

Read More

India

Plot No. 11/2, Phase 3, Hinjewadi Rajiv Gandhi Infotech Park, Pune, India – 411057.
info@tudip.com
+91-96-8990-0537

United States

1999 S. Bascom Ave Suite 700, Campbell CA. 95008, USA.
info@tudip.com
+1-408-216-8162

Canada

64 Caracas Road North York, Toronto Ontario M2K 1B1, Canada.
info@tudip.com

Mexico

Calle Amado Nervo #785 Interior B Colonia Ladron De Guevara 44600 Guadalajara, Jalisco, Mexico.
info@tudip.com

Singapore

77 High Street, #10-12B High Street Plaza, Singapore 179433.
info@tudip.com

Colombia

Cra. 9 # 113-53 Of. 1405 Bogotá D.C., Colombia.
info@tudip.com

UAE

Tudip Information Technologies L.L.C Office No 109, ABU HAIL BUILDING 13, Abu Hail, Dubai, UAE.
info@tudip.com

Nigeria

22 Kumasi Crescent, Wuse 2, Abuja, Nigeria.
info@tudip.com