Aperture & Depth of Field
Drag the aperture from f/1.4 to f/16 and choose which object is in focus.
AI prompt
Portrait of [subject] holding a small lantern, shot at f/1.4 on an 85mm lens, razor-thin focus plane on the eyes, foreground leaves softly blurred, background lights turned into large creamy bokeh circles, warm evening light, shallow depth of field, photographic realism. Variation: f/8 with the whole scene sharp from the lantern to the distant street, deep focus. Focus variants: focus on the near leaf with the subject soft, focus on the far lights with the subject soft. Negative: flat uniform blur, fake tilt-shift look, double edges, blurry subject when sharp focus is requested.About this pattern
Definition
Depth of field is how much of the scene looks sharp. A wide aperture (small f-number such as f/1.4) gives a thin sharp zone and creamy blur; a narrow aperture (f/11 to f/16) keeps almost everything sharp.
When to use it
- Shallow focus isolates a subject for portraits and product shots; deep focus suits landscapes and architecture.
- Pick the focus plane (near, middle, far) to steer attention; the other planes blur in proportion to their distance from it.
- State both the f-number and what is in focus.
What the controls do
- Aperture slider from f/1.4 to f/16; three buttons set the focus plane to Near, Middle or Far.
Motion & timing
- Blur updates live with the slider and eases 200ms when the focus plane changes.
- Reduced motion: it changes instantly.
Tips & variations
- Blur amounts scale with image size; check the result at the final display size.
- In prompts, pair the aperture with the focal length for the most predictable look.
Code of this live preview
<div class="bx"><div class="st" id="st"><div class="o far" data-z="2"><i></i><i></i><i></i></div><div class="o mid" data-z="1"></div><div class="o near" data-z="0"></div></div>
<label class="ctl">Aperture <b id="fv">f/2.8</b><input id="f" type="range" min="0" max="100" value="25"></label>
<div class="pre" id="pre" role="group" aria-label="Focus plane"><button data-z="0">Near</button><button data-z="1" aria-pressed="true">Middle</button><button data-z="2">Far</button></div></div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
.bx{width:min(300px,100%);display:grid;gap:8px}
.st{position:relative;height:140px;border-radius:12px;overflow:hidden;background:linear-gradient(#e9e2d0,#cfc3a6)}
.o{position:absolute;transition:filter .2s}
.near{left:14px;bottom:16px;width:40px;height:90px;border-radius:20px 20px 4px 4px;background:#4d6b3a}
.mid{left:50%;bottom:22px;width:46px;height:70px;margin-left:-23px;border-radius:50% 50% 8px 8px;background:#b4583a}
.far{right:10px;top:12px;width:120px;height:60px}.far i{position:absolute;width:26px;height:26px;border-radius:50%;background:#f3c969}.far i:nth-child(1){left:0;top:20px}.far i:nth-child(2){left:42px;top:0}.far i:nth-child(3){left:80px;top:24px;background:#f08a5a}
.ctl{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.ctl b{color:var(--text)}
input[type=range]{width:100%;accent-color:#171717}
.pre{display:flex;gap:5px}.pre button{flex:1;height:28px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font:inherit;font-size:11.5px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){.o{transition:none}}const F=[1.4,2,2.8,4,5.6,8,11,16],f=document.getElementById('f'),fv=document.getElementById('fv'),os=[...document.querySelectorAll('.o')],bs=[...document.querySelectorAll('#pre button')];let focus=1;
function up(){const v=+f.value/100*(F.length-1),i=Math.floor(v),a=F[i]*Math.pow(F[Math.min(i+1,F.length-1)]/F[i],v-i);fv.textContent='f/'+a.toFixed(1);
os.forEach(o=>{const d=Math.abs(+o.dataset.z-focus),px=d*(9/a)*(+o.dataset.z===2?1.4:1);o.style.filter='blur('+px.toFixed(2)+'px)';});
bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.z===focus)));}
f.addEventListener('input',up);bs.forEach(b=>b.addEventListener('click',()=>{focus=+b.dataset.z;up();}));up();One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Aperture & Depth of Field — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
.bx{width:min(300px,100%);display:grid;gap:8px}
.st{position:relative;height:140px;border-radius:12px;overflow:hidden;background:linear-gradient(#e9e2d0,#cfc3a6)}
.o{position:absolute;transition:filter .2s}
.near{left:14px;bottom:16px;width:40px;height:90px;border-radius:20px 20px 4px 4px;background:#4d6b3a}
.mid{left:50%;bottom:22px;width:46px;height:70px;margin-left:-23px;border-radius:50% 50% 8px 8px;background:#b4583a}
.far{right:10px;top:12px;width:120px;height:60px}.far i{position:absolute;width:26px;height:26px;border-radius:50%;background:#f3c969}.far i:nth-child(1){left:0;top:20px}.far i:nth-child(2){left:42px;top:0}.far i:nth-child(3){left:80px;top:24px;background:#f08a5a}
.ctl{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.ctl b{color:var(--text)}
input[type=range]{width:100%;accent-color:#171717}
.pre{display:flex;gap:5px}.pre button{flex:1;height:28px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font:inherit;font-size:11.5px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){.o{transition:none}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="st" id="st"><div class="o far" data-z="2"><i></i><i></i><i></i></div><div class="o mid" data-z="1"></div><div class="o near" data-z="0"></div></div>
<label class="ctl">Aperture <b id="fv">f/2.8</b><input id="f" type="range" min="0" max="100" value="25"></label>
<div class="pre" id="pre" role="group" aria-label="Focus plane"><button data-z="0">Near</button><button data-z="1" aria-pressed="true">Middle</button><button data-z="2">Far</button></div></div>
</div>
<script>
const F=[1.4,2,2.8,4,5.6,8,11,16],f=document.getElementById('f'),fv=document.getElementById('fv'),os=[...document.querySelectorAll('.o')],bs=[...document.querySelectorAll('#pre button')];let focus=1;
function up(){const v=+f.value/100*(F.length-1),i=Math.floor(v),a=F[i]*Math.pow(F[Math.min(i+1,F.length-1)]/F[i],v-i);fv.textContent='f/'+a.toFixed(1);
os.forEach(o=>{const d=Math.abs(+o.dataset.z-focus),px=d*(9/a)*(+o.dataset.z===2?1.4:1);o.style.filter='blur('+px.toFixed(2)+'px)';});
bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.z===focus)));}
f.addEventListener('input',up);bs.forEach(b=>b.addEventListener('click',()=>{focus=+b.dataset.z;up();}));up();
</script>
</body></html>