Create Image Resize App using Tailwind CSS Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Image Resizer is an application that is used to resize an uploaded image by providing new dimensions in the form of width and height. This application contains two numbered input fields to get the number input for width and height from the user. It also contains a file input field to upload an image file. It allows you to download the resized image as well. Approach:First, we make a folder where we put an HTML file and a JavaScript file. In the HTML file, we include a link to integrate Tailwind CSS.Now use Tailwind CSS classes to style the Image Resize app. We add input fields to set the width and height and also the one button through which we can see the preview of the image.In the JavaScript file, we write the logic. like the width which is set by user same implemented on the image and also the download button to download the image in one click.Example: The below code example will help you in creating a image resizer app using Tailwind CSS. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content= "width=device-width, initial-scale=1.0"> <link rel="stylesheet" href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css"> <title>Image Resizer</title> </head> <body class="bg-gray-100 p-8"> <div class="max-w-md mx-auto bg-white p-8 rounded shadow-md"> <h2 class="text-2xl font-bold mb-4"> Image Resizer </h2> <form id="resizeForm"> <div class="mb-4"> <label for="width" class= "block text-sm font-medium text-gray-600"> Width (in pixels) </label> <input type="number" id="width" name="width" class="mt-1 p-2 w-full border rounded"> </div> <div class="mb-4"> <label for="height" class="block text-sm font-medium text-gray-600"> Height (in pixels) </label> <input type="number" id="height" name="height" class="mt-1 p-2 w-full border rounded"> </div> <div class="mb-4"> <label for="image" class="block text-sm font-medium text-gray-600"> Upload Image </label> <input type="file" id="image" name="image" accept=".jpg, .jpeg, .png, .TIFF, .RAW" class="mt-1" onchange="displayImage()"> </div> <button type="button" onclick="resizeImage()" class="bg-blue-500 text-white p-2 rounded"> Resize Image </button> </form> <div class="mt-8" id="previewContainer" style="display:none;"> <h3 class="text-lg font-semibold mb-2"> Preview </h3> <img id="previewImage" alt="Resized Image" class="max-w-full"> <div class="mt-4"> <a id="downloadLink" download="resized_image.jpg" style="display:none;" class="bg-green-500 text-white p-2 rounded" href="#"> Download Resized Image </a> </div> </div> </div> <script src="./script.js"></script> </body> </html> JavaScript //script.js function displayImage() { const fileInput = document.getElementById('image'); const previewContainer = document.getElementById('previewContainer'); const previewImage = document.getElementById('previewImage'); const reader = new FileReader(); reader.onload = function (e) { previewImage.src = e.target.result; previewContainer.style.display = 'block'; }; reader.readAsDataURL(fileInput.files[0]); } function resizeImage() { const width = document.getElementById('width').value; const height = document.getElementById('height').value; const fileInput = document.getElementById('image'); const downloadLink = document.getElementById('downloadLink'); if (!width || !height || !fileInput.files[0]) { alert('Please fill in all the fields and upload an image.'); return; } const reader = new FileReader(); reader.onload = function (e) { const img = new Image(); img.src = e.target.result; img.onload = function () { const canvas = document.createElement('canvas'); canvas.width = width; canvas.height = height; const ctx = canvas.getContext('2d'); ctx.drawImage(img, 0, 0, width, height); const previewImage = document.getElementById('previewImage'); previewImage.src = canvas.toDataURL('image/jpeg'); downloadLink.href = canvas.toDataURL('image/jpeg'); downloadLink.style.display = 'inline-block'; }; }; reader.readAsDataURL(fileInput.files[0]); } Output: Comment More infoAdvertise with us Next Article Can I Create Masonry Layout using Tailwind CSS Utility Classes ? K kasoti2002 Follow Improve Article Tags : CSS Similar Reads How to resize SVG icon using Tailwind CSS ? SVG stands for Scalable Vector Graphics and is an XML-based ( can be edited ) vector image format. SVG is commonly used for icons, animations, interactive charts, graphs, and other dynamic graphics in the browser. As it is XML-based, you can easily resize the SVG icon using Tailwind. Approach: You c 3 min read How to Code Pixel Perfect Design using Tailwind CSS ? Pixel-perfect design refers to the ability to create designs that are accurate down to the pixel level. Tailwind CSS is a popular utility-first CSS framework that can help developers to create pixel-perfect designs quickly and efficiently. In this article, we'll discuss how to code pixel-perfect des 5 min read Tailwind CSS Resize This class accepts lots of value in tailwind CSS in which all the properties are covered as a class form. This class is used to resize the element according to user requirements. It does not apply to inline elements or to block elements where overflow is visible. In CSS, we do that by using the CSS 1 min read Can I Create Masonry Layout using Tailwind CSS Utility Classes ? Yes, you can create a Masonry layout using Tailwind CSS utility classes. A Masonry layout is a popular design pattern used for displaying images or other elements in a grid-like structure where each item is of varying height and width. This layout creates a visually appealing and dynamic design that 3 min read How to create fixed/sticky footer on the bottom using Tailwind CSS ? In this article, we are going to create a fixed/sticky footer on the bottom using Tailwind CSS. Tailwind CSS is a highly customizable, utility-first CSS framework from which we can use utility classes to build any design. With Tailwind CSS we can create a design by simply adding classes. Installatio 2 min read How to apply background image with linear gradient using Tailwind CSS ? In this article, we will see how to apply background images with a linear gradient using Tailwind CSS. Tailwind CSS is a highly customizable, utility-first CSS framework from which we can use utility classes to build any design. To apply background images with linear gradients we use the background 2 min read Like