How to blur a photo background in your browser
A lens throws a background out of focus because of the physical width of the hole light comes through, and the hole in a phone camera is about three millimetres across. Point an 85 mm portrait lens at somebody standing two metres away and roughly six centimetres of the scene comes back sharp. Point a phone at the same person, at the same f-number, and roughly three and a half metres does. Nothing is out of focus because nothing can be. That is why phones have been computing the blur since 2016 — and why you can compute the same thing in a browser tab.
The lens genuinely cannot do it
Both cameras in that chart are set to f/1.8. The f-number is a ratio — focal length divided by aperture diameter — so the same number describes very different holes. Eighty-five divided by 1.8 is an aperture 47 mm across. Five point six divided by 1.8 is an aperture 3 mm across.
Defocus scales with that diameter, not with the ratio. A point of light that sits off the focal plane lands on the sensor as a circle, and the circle inherits the width of the aperture. Fifteen times narrower means fifteen times less blur, which in practice means none at all: from about a metre and a quarter out to nearly five metres, a phone renders everything acceptably sharp whether you want it to or not.
Apple's answer, on the iPhone 7 Plus in 2016, was to stop trying. Portrait mode does not defocus anything. It estimates which pixels belong to the subject, blurs the rest in software, and composites the two back together.
Portrait mode is a matte, not a blur
The blur is not the hard part. In a browser it is one line:
context.filter = 'blur(16px)';
context.drawImage(photo, 0, 0);
That is the entire optical effect, and it is worth being clear that it is not where the work is. What makes a picture look like portrait mode rather than like a smudge is the matte: one number per pixel, from 0 to 255, saying how much of this pixel belongs to the subject.
Everything else follows from that one array. The blurred plate is drawn first, across the whole frame. Then the original photograph goes onto a scratch canvas, the matte is written into its alpha channel, and the result is drawn over the top — so the subject lands back on the picture at full sharpness, with the softened background already sitting behind it.
One detail from the implementation is worth stealing if you ever build this yourself. A Gaussian applied at the edge of a canvas averages in the transparent pixels just outside it and leaves a pale halo around the whole frame. Background Blur runs the blur on a canvas padded by three sigma on every side and then crops back, so the edges stay as dense as the middle.
Two things give a fake away
The edge
This is where every portrait mode you have ever seen fail, failed. Hair against a busy background, the arm of a pair of glasses, the gap between an elbow and a torso, a hand held out toward the camera. Get the matte wrong by four pixels and the eye finds it immediately — either a bright halo of unblurred background clinging to the outline, or a subject that has been quietly shaved.
Two controls exist for exactly this. Edge tightness moves the threshold at which the model's confidence counts as "subject": raise it to pull the outline in and cut a halo away, lower it to let a chewed edge back out. Feather edge softens the boundary by a pixel or two, which is what stops the cut-out reading as a sticker.
The highlight
The second tell is subtler, and it is physics rather than a bug.
Real defocus is not an average. A point of light lands on the sensor as a disc the shape of the aperture, and that disc is as bright as the point was — the light is spread across more pixels, not shared out among them. That is why fairy lights behind a subject turn into big luminous circles, and it is the thing people actually mean when they say bokeh.
A Gaussian blur is a weighted average, so a bright point is divided among its neighbours and dims as it widens. Blur a night scene hard enough and the lights vanish into grey.
The practical version: on a scene with bright points behind the subject, keep the blur modest — somewhere around 10 to 20 pixels. Push it to 50 and you are not simulating a lens, you are erasing the highlights that would have been the best part of the picture.
The tool

Drop a photo in and there is one decision to make: how the tool should know what to keep sharp.
Detected subject
The default runs a segmentation model over the picture and uses its output as the matte. There are two of them, and which you are offered depends on the browser:
| Fast | Maximum quality | |
|---|---|---|
| Model | MODNet | BiRefNet-lite |
| Download | 24.7 MB | 109 MB |
| Runs on | WebAssembly — anywhere | WebGPU only |
| Best at | People and clearly separated subjects | Products, animals, hair detail |
| Licence | Apache-2.0 | MIT |
Maximum quality only appears when the browser really has WebGPU behind it, and that is a stricter test than it sounds. Safari reports a perfectly real navigator.gpu, but the ONNX Runtime build it is handed has no WebGPU provider compiled in, so it is quietly given the fast model instead of an error. BiRefNet needs the GPU for a second reason too: at its fixed 1024×1024 input the WebAssembly backend exhausts its heap and dies partway through.
Either model downloads once and is then served from the browser's cache, so reruns are instant. The weights come down from a CDN; the photograph goes nowhere at all.
Manual area
The other option skips the model entirely. Pick an ellipse, a rectangle or a band, click anywhere on the preview to move it, and size it with four sliders. There is nothing to download and nothing to wait for.
It is the right choice more often than you would expect. Any subject a matte struggles with — a group, a plate of food, something behind glass — is usually easier to draw a shape around than to argue with a model about. And the band is not a fallback at all: a horizontal strip of sharpness across a wide shot is the tilt-shift effect, which is how you make a real street look like a model railway.
The controls, and what each is for

- Blur strength, 0–60 px. Twelve to twenty reads as a lens. Past about thirty it reads as a filter.
- Darken background, 0–60%. Brightens the subject by comparison without touching a single pixel of it. Ten to fifteen per cent is usually enough.
- Vignette, 0–80%. Darkens the corners the way a lens does, which pulls the eye inward. Easy to overdo; twenty is plenty.
- Feather edge, 0–8 px. The most important control on the panel for realism. One or two pixels on a normal photo, more when the outline is complicated.
- Edge tightness, 5–95%, on the detected subject only. Reach for it when there is a halo or a nibbled edge, and leave it alone otherwise.
- Export as JPEG, WebP or PNG, with a quality slider on the two lossy ones. PNG is only worth it if the result is going into more editing.
Hold to compare shows the untouched original for as long as the button is held, which is the fastest way to tell whether the blur is helping or merely softening.
Three starting points:
- Portrait — detected subject, blur 14, feather 2, tightness 55, darken 12, vignette 20.
- Product on a cluttered desk — maximum quality if it is offered, blur 24, feather 1, tightness 45.
- Miniature street — manual area, band, height around 25%, softness 35, blur 30.
What it will not do
Worth knowing before you reach for it.
It has no depth map. A phone estimates distance and blurs progressively, so a wall five metres back comes out softer than a chair two metres back. This is binary: subject sharp, everything else blurred by the same amount. On a scene with a lot of depth in it that reads slightly flat, and the honest fix is to shoot with the background further away.
Hair against a busy background is where every matte in existence struggles, this one included. So are chain-link, glass, and a hand held out toward the camera — anything where the true answer for a pixel is "both".
Images are worked on at up to 2400 px on the longest edge, with a 30 MB ceiling on the file. Anything larger is scaled to fit before the rest happens, so this is a tool for a picture that is going to be looked at rather than printed.
And if the detector simply gets it wrong, the manual area is always there and always works.
The rest of the toolbox
Remove Background uses subject detection to cut the subject out completely instead of softening what is behind it. Blur Face blurs or pixelates faces and any region you draw, which is the privacy job rather than the aesthetic one. Object Remover paints something out of a picture altogether.
For a transparent product-photo background, follow the separate product cut-out walkthrough. It covers AI versus Flat backdrop, Erase/Restore corrections, transparent PNG export and difficult edges. See Product Photo Studio when you also need marketplace sizes or a logo.
Around them: Image Crop for the framing, Image Compressor for the file size afterwards, Watermark Image for a signature across a batch, and Social Media Image Resizer for every size a platform asks for.
They are all in the full tool directory, and every one of them runs on your own machine.
0 comments
No comments yet. Be the first to say something.