Open source background removal in the browser (2027 guide)
Bria.ai

Updated 2026-12-01
TL;DR
Short answer: Install Transformers.js and call its
background-removalpipeline with an open source model. The library docs say the browser runs it on the CPU through WASM by default, and the WebGPU guide showsdevice: 'webgpu'(checked 2026-12-02). For hard images, the Bria API runs RMBG 3.0 at $0.018 per image (checked 2026-12-02).Smallest start: MODNet is Apache-2.0 and its ONNX file is 25.9 MB, down to 6.6 MB quantized. It targets portraits.
Larger model: BiRefNet lite in ONNX is MIT licensed and 224.0 MB in FP32, or 114.5 MB in FP16.
License check:
@imgly/background-removalis free under the AGPL, and its README points to the vendor for other licensing.Where Bria fits: RMBG 3.0's card lists GPU memory of 32 GB or more and publishes no browser build, so this guide does not cover running it client side. Use the Bria API from your server.
How do you remove a background in the browser with open source?
Load a background removal model in Transformers.js, run it on the image in the page, and combine the resulting mask with the original image.
Running in the browser means the model executes on the visitor's device, with no server in the loop for inference. Transformers.js is a JavaScript library that runs Hugging Face models in the browser through ONNX Runtime, and its task list includes background removal. This guide covers three options, the exact setup from the model cards, the file sizes you will download and when an API is the better route. Bria wrote it and it gives no legal advice.
For quality on hard images, see Bria's benchmark, which combines blind votes from professional and casual users with a VLM side-by-side comparison at full resolution: RMBG 3.0 ranked first of 6 models with an average rank of 1.51 across 234 hard images (method and leaderboard).
Which open source options run in the browser?
Three open source options run client side, and each has a different license, file size and job.
Option: MODNet via Transformers.js; How it runs: ONNX in the browser; License: Apache-2.0; Download size: 25.9 MB (FP32); Best for: Portraits
Option: BiRefNet lite via Transformers.js; How it runs: ONNX in the browser; License: MIT; Download size: 224.0 MB (FP32); Best for: General segmentation
Option: @imgly/background-removal; How it runs: npm package for browser and Node.js; License: AGPL-3.0; Download size: not found; Best for: A ready package
Option: RMBG 3.0 via Bria API; How it runs: Server call, not in the browser; License: CC BY-NC 4.0 weights, commercial API; Download size: Not a browser download; Best for: Hard images
Source: the Xenova/modnet and onnx-community/BiRefNet_lite-ONNX model cards and file lists, and the imgly repository, checked 2026-12-02. The imgly README gives no model file size. The RMBG 3.0 row is from its model card.
How do you set it up with Transformers.js?
Install `@huggingface/transformers`, create the pipeline with a model id, and pass it an image URL.
Install the library with
npm i @huggingface/transformers.Pick a model id. The MODNet card uses
Xenova/modnet.Create the pipeline and run it, as the card shows:
import { pipeline } from '@huggingface/transformers';
const segmenter = await pipeline('background-removal', 'Xenova/modnet', { dtype: 'fp32' });
const url = 'https://images.pexels.com/photos/5965592/pexels-photo-5965592.jpeg?auto=compress&cs=tinysrgb&w=1024';
const output = await segmenter(url);
output[0].save('mask.png');Read the result. The card saves
output[0]asmask.pngand says you can also useoutput[0].toCanvas()orawait output[0].toBlob()to access it without saving.Check what you get on your own image. The cards stop at the mask, so confirm in your page whether you have a cutout or a mask, and combine the mask with the original if you need transparency.
Source: Xenova/modnet model card, checked 2026-12-02. The library's documentation lists background removal as a supported task.
How large are the model files?
The MODNet ONNX files run from 6.6 MB to 25.9 MB, and BiRefNet lite runs from 114.5 MB to 224.0 MB.
Model: MODNet; File: model.onnx (FP32); Size: 25.9 MB
Model: MODNet; File: model_q4.onnx; Size: 23.1 MB
Model: MODNet; File: model_fp16.onnx; Size: 13.0 MB
Model: MODNet; File: model_q4f16.onnx; Size: 11.8 MB
Model: MODNet; File: model_quantized.onnx and model_uint8.onnx; Size: 6.6 MB each
Model: BiRefNet lite; File: model.onnx (FP32); Size: 224.0 MB
Model: BiRefNet lite; File: model_fp16.onnx; Size: 114.5 MB
Source: Hugging Face file listings for Xenova/modnet and onnx-community/BiRefNet_lite-ONNX, checked 2026-12-02. The cards show dtype: 'fp32' in their code. We did not test the smaller files, so compare their output on your own images.
How do you run it on the GPU with WebGPU?
Set `device: 'webgpu'` in the pipeline options, because the browser default is the CPU through WASM.
The Transformers.js library documentation states that in the browser the model runs on your CPU via WASM by default. The WebGPU guide shows setting device: 'webgpu' when loading a model. Its example uses a text model, not a background removal model. We did not run this option with the models above, so test it before you rely on it.
Which model should you start with?
Start with MODNet for portraits and BiRefNet lite for other subjects, and weigh download size against edge quality on your own files.
MODNet is the smallest download in this guide. Its README says it targets portrait matting from RGB input, with no trimap.
BiRefNet lite is MIT licensed, and its card tags it for dichotomous image segmentation and salient object detection. The FP16 download is 114.5 MB.
Benchmark: MODNet was not benchmarked by Bria, and no rank is given here for BiRefNet lite. BiRefNet ranked sixth of 6 in Bria's benchmark.
What does the AGPL on @imgly/background-removal mean?
The package's README says it is free to use under the AGPL, and it points other licensing questions to the vendor.
The repository states that @imgly/background-removal runs in the browser and @imgly/background-removal-node runs in Node.js. It says "The software is free for use under the AGPL License" and asks you to contact support@img.ly about other licensing options. GitHub lists the license as AGPL-3.0. Read the AGPL terms with your own counsel before you ship it in a product.
Can RMBG 3.0 run in the browser?
This guide does not cover it: the RMBG 3.0 card lists GPU memory of 32 GB or more and publishes no browser build, so use the Bria API.
RMBG 1.4, an earlier Bria model with 44,075,590 parameters, carries a transformers.js tag on Hugging Face. Its license is a Creative Commons license for non-commercial use, and commercial use is subject to a commercial agreement with Bria. RMBG 3.0 is a different case: its weights are CC BY-NC 4.0, so they are not open source.
A server call to the Bria API runs it on Bria's side, listed at $0.018 per image (checked 2026-12-02, see pricing). The quickstart shows a first call. Make that call from your server so the API key is not exposed in page code.
When should you use a browser model, and when an API?
Use a browser model when images must stay on the visitor's device and portraits or simple subjects are enough, and use an API when edge quality on hard images matters.
Choose MODNet in the browser for portraits and the smallest download.
Choose BiRefNet lite in the browser for non-portrait subjects and an MIT license.
Choose imgly's package if you want a ready npm package and the AGPL fits your project.
Choose the Bria API for hard images or commercial use of RMBG 3.0.





