Create an Image Background Remover App Using HTML CSS & JavaScript Last Updated : 23 Jul, 2024 Comments Improve Suggest changes Like Article Like Report Building an Image Background Remover using HTML, CSS, and JavaScript demonstrates the power of combining these technologies to create interactive and user-friendly applications. The clean design and intuitive features make this tool not only functional but also enjoyable for users to interact with. The goal of our project is to provide users with a simple and intuitive interface for removing backgrounds from images. Approach: Start with a basic HTML structure that includes elements for image input, previews, and action buttons.In the CSS file, we've defined styles for the container, input file, image previews, and action buttons. The design focuses on clean lines, easy-to-read fonts, and interactive buttons.In the JavaScript file, we've implemented logic for handling image input, sending requests to the remove.bg API for background removal, and displaying the results. The user can also download the processed image with a single click.Example: The below code example illustrates the creation of image background remover app using HTML, CSS, and JavaScript. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content= "width=device-width, initial-scale=1.0"> <title> Image Background Remover </title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="container"> <h1>Image Background Remover</h1> <div class="input-file"> <label for="userImg" class="info_text"> Select a File </label> <input type="file" id="userImg" class="form-control-file" required> </div> <div class="d-flex mb-4"> <div id="imagePreview" class="image-preview"></div> <div id="bgRemove" class="image-preview"></div> </div> <a id="downloadButton" class="btn btn-download" style="display: none;"> Download </a> <div> <button id="removeBackground" class="btn btn-primary"> Remove Background </button> </div> </div> <script src="script.js"></script> </body> </html> CSS /* Center content vertically and horizontally */ .container { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 80vh; padding: 20px; border: 1px solid #0e0c0c; border-radius: 10px; max-width: 600px; margin: 0 auto; background-color: #e3f7f7; } /* Title styles */ h1 { text-align: center; margin-bottom: 20px; } /* Style input file button */ .input-file { margin-bottom: 20px; } /* Style image previews */ .image-preview { border: 2px solid #ccc; border-radius: 5px; margin-right: 10px; overflow: hidden; width: 200px; height: 200px; display: inline-block; } .image-preview img { width: 100%; height: 100%; } /* Style remove background button */ .btn-remove-bg { background-color: #007bff; color: #fff; border: none; border-radius: 5px; padding: 10px 20px; font-size: 16px; cursor: pointer; } .btn-remove-bg:hover { background-color: #0056b3; } JavaScript document.addEventListener('DOMContentLoaded', function () { const inputField = document.getElementById('userImg'); const removeBackgroundButton = document.getElementById('removeBackground'); const imagePreview = document.getElementById('imagePreview'); const bgRemove = document.getElementById('bgRemove'); const downloadButton = document.getElementById('downloadButton'); inputField.addEventListener('change', function () { const file = this.files[0]; const reader = new FileReader(); reader.onload = function (e) { const img = document.createElement('img'); img.src = e.target.result; imagePreview.innerHTML = ''; imagePreview.appendChild(img); } reader.readAsDataURL(file); }); removeBackgroundButton.addEventListener('click', async function () { const file = inputField.files[0]; const formData = new FormData(); formData.append('image_file', file); try { const response = await fetch('https://api.remove.bg/v1.0/removebg', { method: 'POST', headers: { 'X-Api-Key': '39nH2XMTcoAxnogxmqVBuAXH', }, body: formData, }); const result = await response.blob(); const imgUrl = URL.createObjectURL(result); bgRemove.innerHTML = `<img src="${imgUrl}" alt="Removed Background">`; downloadButton.href = imgUrl; downloadButton.download = 'background_removed_image.png'; downloadButton.style.display = 'inline-block'; } catch (error) { console.error('Error removing background:', error); } }); }); Output: Comment More infoAdvertise with us Next Article Create an Image Background Remover App Using HTML CSS & JavaScript A aakashya4h46 Follow Improve Article Tags : Project JavaScript Web Technologies Dev Scripter JavaScript-Projects Dev Scripter 2024 +2 More Similar Reads JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav 11 min read Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De 5 min read React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications 15+ min read JavaScript Interview Questions and Answers JavaScript (JS) is the most popular lightweight, scripting, and interpreted programming language. JavaScript is well-known as a scripting language for web pages, mobile apps, web servers, and many other platforms. Both front-end and back-end developers need to have a strong command of JavaScript, as 15+ min read React Tutorial React is a JavaScript Library known for front-end development (or user interface). It is popular due to its component-based architecture, Single Page Applications (SPAs), and Virtual DOM for building web applications that are fast, efficient, and scalable.Applications are built using reusable compon 8 min read Domain Name System (DNS) DNS is a hierarchical and distributed naming system that translates domain names into IP addresses. When you type a domain name like www.geeksforgeeks.org into your browser, DNS ensures that the request reaches the correct server by resolving the domain to its corresponding IP address.Without DNS, w 8 min read Sequence Diagrams - Unified Modeling Language (UML) A Sequence Diagram is a key component of Unified Modeling Language (UML) used to visualize the interaction between objects in a sequential order. It focuses on how objects communicate with each other over time, making it an essential tool for modeling dynamic behavior in a system. Sequence diagrams 11 min read NodeJS Interview Questions and Answers NodeJS is one of the most popular runtime environments, known for its efficiency, scalability, and ability to handle asynchronous operations. It is built on Chromeâs V8 JavaScript engine for executing JavaScript code outside of a browser. It is extensively used by top companies such as LinkedIn, Net 15+ min read HTML Interview Questions and Answers HTML (HyperText Markup Language) is the foundational language for creating web pages and web applications. Whether you're a fresher or an experienced professional, preparing for an HTML interview requires a solid understanding of both basic and advanced concepts. Below is a curated list of 50+ HTML 14 min read What is an API (Application Programming Interface) In the tech world, APIs (Application Programming Interfaces) are crucial. If you're interested in becoming a web developer or want to understand how websites work, you'll need to familiarize yourself with APIs. Let's break down the concept of an API in simple terms.What is an API?An API is a set of 10 min read Like