Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    How to create Awesome Cool Loading Animation using HTML CSS and JS

    16 June 2025

    How to create Login and Signup Form using HTML CSS and JS

    9 June 2025

    How to create Impossible light bulb using HTML CSS and JS

    5 June 2025
    Facebook X (Twitter) Instagram YouTube Telegram Threads
    Coding StellaCoding Stella
    • Home
    • Blog
    • HTML & CSS
      • Login Form
    • JavaScript
    • Hire us!
    Coding StellaCoding Stella
    Home - JavaScript - How to make Custom File Upload Button in HTML CSS & JavaScript
    JavaScript

    How to make Custom File Upload Button in HTML CSS & JavaScript

    Coding StellaBy Coding Stella25 February 2024No Comments4 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Email WhatsApp Copy Link

    Let’s create a Custom File Upload Button using HTML, CSS, and JavaScript. This project is perfect for beginners and will help you understand how to customize form elements.

    We’ll use HTML to set up the button, CSS to style it and make it look unique, and JavaScript to handle the file upload functionality. It’s a simple project but a great way to learn some basic web development skills!

    Let’s get started on building this Custom File Upload Button. Whether you’re new to coding or looking to enhance your skills, this project is for you. Let’s dive in and create a stylish file upload button together!

    HTML :

    This HTML code creates a webpage with a custom file upload button. It includes Font Awesome icons and Google Fonts for styling. The body contains a container with an input element for file selection, a label for the custom button, a display area for the number of files chosen, and an unordered list for displaying the selected files.

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Custom File Upload Button</title>
        <!-- Font Awesome Icons -->
        <link
          rel="stylesheet"
          href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css"
        />
        <!-- Google Fonts  -->
        <link
          href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500&display=swap"
          rel="stylesheet"
        />
        <!-- Stylesheet -->
        <link rel="stylesheet" href="style.css" />
      </head>
      <body>
        <div class="container">
          <input type="file" id="file-input" multiple />
          <label for="file-input">
            <i class="fa-solid fa-arrow-up-from-bracket"></i>
              Choose Files To Upload
          </label>
          <div id="num-of-files">No Files Choosen</div>
          <ul id="files-list"></ul>
        </div>
        <!-- Script -->
        <script src="script.js"></script>
      </body>
    </html>

    CSS :

    This CSS code sets up styling for the webpage created with the HTML code. It styles the container with specific dimensions, positioning, padding, border-radius, and box-shadow. The file input is hidden, and a label is styled to act as the file upload button. The number of files selected is styled, and an unordered list is customized to display selected files with specific formatting and spacing.

    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
      font-family: "Poppins", sans-serif;
    }
    body {
      background-color: #025bee;
    }
    .container {
      background-color: #ffffff;
      width: 90%;
      max-width: 34.37em;
      position: relative;
      margin: 3.12em auto;
      padding: 3.12em 1.25em;
      border-radius: 0.43em;
      box-shadow: 0 1.25em 2.18em rgb(1, 28, 71, 0.3);
    }
    input[type="file"] {
      display: none;
    }
    label {
      display: block;
      position: relative;
      background-color: #025bee;
      color: #ffffff;
      font-size: 1.12em;
      font-weight: 500;
      text-align: center;
      width: 18.75em;
      padding: 1.12em 0;
      margin: auto;
      border-radius: 0.31em;
      cursor: pointer;
    }
    #num-of-files {
      font-weight: 400;
      text-align: center;
      margin: 1.25em 0 1.87em 0;
    }
    ul {
      list-style-type: none;
    }
    .container li {
      font-weight: 500;
      background-color: #eff5ff;
      color: #025bee;
      margin-bottom: 1em;
      padding: 1.1em 1em;
      border-radius: 0.3em;
      display: flex;
      justify-content: space-between;
    }

    JavaScript:

    This JavaScript code adds functionality to the file input element. When files are selected, it updates the display to show the number of files selected and creates a list of the selected files with their names and sizes. If a file’s size is larger than or equal to 1MB, it displays the size in megabytes instead of kilobytes.

    let fileInput = document.getElementById("file-input");
    let fileList = document.getElementById("files-list");
    let numOfFiles = document.getElementById("num-of-files");
    
    fileInput.addEventListener("change", () => {
      fileList.innerHTML = "";
      numOfFiles.textContent = `${fileInput.files.length} Files Selected`;
    
      for (i of fileInput.files) {
        let reader = new FileReader();
        let listItem = document.createElement("li");
        let fileName = i.name;
        let fileSize = (i.size / 1024).toFixed(1);
        listItem.innerHTML = `<p>${fileName}</p><p>${fileSize}KB</p>`;
        if (fileSize >= 1024) {
          fileSize = (fileSize / 1024).toFixed(1);
          listItem.innerHTML = `<p>${fileName}</p><p>${fileSize}MB</p>`;
        }
        fileList.appendChild(listItem);
      }
    });

    Creating a Custom File Upload Button in HTML, CSS, and JavaScript is a fun beginner project. It enhances skills in customizing form elements, styling with CSS, and adding functionality with JavaScript. Happy coding!

    If your project has problems, don’t worry. Just click to download the source code and face your coding challenges with excitement. Have fun coding!

    Button Upload
    Share. Copy Link Twitter Facebook LinkedIn Email WhatsApp
    Previous ArticleHow to make Ball Leaping Loader using HTML & CSS
    Next Article How to make Drawing App / Paint App in HTML CSS & JavaScript
    Coding Stella
    • Website

    Related Posts

    JavaScript

    How to create Login and Signup Form using HTML CSS and JS

    9 June 2025
    JavaScript

    How to create Impossible light bulb using HTML CSS and JS

    5 June 2025
    JavaScript

    How to create Animated Rubik Cube using HTML CSS and JS

    3 June 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Trending Post

    Master Frontend in 100 Days Ebook

    2 March 202419K Views

    How to make Modern Login Form using HTML & CSS | Glassmorphism

    11 January 202417K Views

    How to make I love you Animation in HTML CSS & JavaScript

    14 February 202415K Views

    How to make Valentine’s Day Card using HTML & CSS

    13 February 202412K Views
    Follow Us
    • Instagram
    • Facebook
    • YouTube
    • Twitter
    ads
    Featured Post

    How to make Hourglass Preloader using HTML & CSS

    9 April 2025

    Level Up Your CSS with these 50+ Resources

    26 January 2024

    How to make Old Aesthetic Calculator using HTML & CSS

    12 January 2024

    How to Create Soccer Preloader Animation using HTML & CSS

    4 January 2025
    Latest Post

    How to create Awesome Cool Loading Animation using HTML CSS and JS

    16 June 2025

    How to create Login and Signup Form using HTML CSS and JS

    9 June 2025

    How to create Impossible light bulb using HTML CSS and JS

    5 June 2025

    How to create Animated Rubik Cube using HTML CSS and JS

    3 June 2025
    Facebook X (Twitter) Instagram YouTube
    • About Us
    • Privacy Policy
    • Return and Refund Policy
    • Terms and Conditions
    • Contact Us
    • Buy me a coffee
    © 2025 Coding Stella. Made with 💙 by @coding.stella

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Looks like you're using an ad blocker. We rely on advertising to help fund our site.
    Okay! I understood