AI-Powered Background Removal for the Web
Remove backgrounds from images directly in the browser using state-of-the-art AI models. No server required - everything runs client-side with WebAssembly.
Features
Browser-Native
Runs entirely in the browser using WebAssembly. No server required.
Multiple AI Models
Support for U2Net, ISNet, and Silueta models optimized for different use cases.
Hardware Acceleration
Optional WebNN and WebGPU support for faster processing on supported devices.
Flexible Input
Accepts File, Blob, ArrayBuffer, HTMLImageElement, or HTMLCanvasElement.
Customizable
Support for custom models, post-processing, and background replacement.
Small Bundle
Optimized for size with tree-shaking support. ~8KB gzipped core library.
Quick Start
Installation
npm install @bunnio/rembg-web
# or
yarn add @bunnio/rembg-web
Basic Usage
import { remove, newSession } from '@bunnio/rembg-web';
// Basic usage
const fileInput = document.getElementById('fileInput') as HTMLInputElement;
const file = fileInput.files[0];
const result = await remove(file);
const url = URL.createObjectURL(result);
// With custom options
const result = await remove(file, {
onlyMask: true, // Return only the mask
postProcessMask: true, // Apply smoothing
bgcolor: [255, 0, 0, 255], // Red background
session: newSession('u2net_human_seg'), // Use specific model
onProgress: info => {
console.log(`${info.step}: ${info.progress}% - ${info.message}`);
},
});
CDN Usage
You can also use rembg-web directly from a CDN without installation:
<script type="module">
import { remove, newSession } from 'https://unpkg.com/@bunnio/rembg-web@latest/dist/index.js';
// Your code here
</script>
Model Setup
Download the required ONNX model files:
# Download all models
yarn fetch-models
# Or download specific models
yarn fetch-models u2net.onnx
See the Models Guide for more information about available models and their use cases.
Available Models
u2net
~176MB
General-purpose background removal (default)
u2netp
~4.7MB
Lightweight version for faster processing
u2net_human_seg
~176MB
Optimized for human subjects
u2net_cloth_seg
~176MB
Specialized for clothing segmentation
isnet-general-use
~178MB
High accuracy general purpose model
isnet-anime
~178MB
Optimized for anime-style images
silueta
~43MB
Silhouette-based background removal
Browser Support
Chrome/Edge 88+
Full support including WebNN (119+) and WebGPU (113+)
Firefox 78+
Full support (WebGPU behind flag)
Safari 14+
Full support (WebGPU in Technology Preview)
Requires WebAssembly and Web Workers support. Hardware acceleration features require modern browsers with experimental flags enabled.