Histogram & Exposure
A live histogram beside a scene while you change exposure, with clipping warnings at both ends.
AI prompt
Educational diagram of a photograph of a mountain lake next to its luminance histogram: three versions in a row, underexposed with the graph piled against the left wall, correctly exposed with a smooth hill across the whole width, and overexposed with a tall spike against the right wall, small labels Shadows, Midtones and Highlights under the graph, red clipping triangles at the edges, flat clean style. Negative: colour channels, noise, text errors, decorative frames. Reduced motion: static diagram.About this pattern
Definition
A histogram plots how many pixels are dark, mid or bright. A well exposed picture fills the graph without piling against either wall. Mass crushed against the right means blown highlights, against the left means crushed shadows; both lose detail that cannot be recovered.
When to use it
- Left of the graph is shadow, middle is mid-tone, right is highlight.
- A spike touching the right edge is clipped white; touching the left is clipped black.
- Exposure shifts the whole graph by stops; contrast changes how wide it is.
What the controls do
- An Exposure slider from minus three to plus three stops with the histogram and clipping readouts.
Motion & timing
- Updates follow the slider directly.
- Reduced motion: nothing animates.
Tips & variations
- Judge by the graph and by your eyes; a high-key scene legitimately sits right.
- Fix highlights first; blown whites are the hardest loss to hide.
Code of this live preview
<div class="bx"><div class="row3"><div class="sc" id="sc"><i class="sk"></i><i class="mt"></i><i class="lk"></i></div><canvas id="hg" width="150" height="90" aria-label="Histogram"></canvas></div><label class="rw">Exposure <b id="ev">0.0 EV</b><input id="ex" type="range" min="-30" max="30" value="0"></label><p class="out" id="out"></p></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}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.row3{display:grid;grid-template-columns:1fr 150px;gap:10px;align-items:start}.sc{height:90px;border-radius:10px;position:relative;overflow:hidden;filter:brightness(var(--b))}.sc i{position:absolute;display:block}.sk{inset:0 0 50% 0;background:linear-gradient(#7fa7d9,#d6e6f7)}.mt{left:-5%;right:-5%;bottom:30%;height:40%;background:#52606d;clip-path:polygon(0 100%,0 60%,25% 20%,45% 55%,70% 10%,100% 60%,100% 100%)}.lk{left:0;right:0;bottom:0;height:34%;background:linear-gradient(#5d86a8,#34536d)}
canvas{width:150px;height:90px;border:1px solid var(--line);border-radius:8px;background:#fff}.out{font-size:12px;color:var(--muted);min-height:34px}.out b{color:var(--text)}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const ex=document.getElementById('ex'),sc=document.getElementById('sc'),cv=document.getElementById('hg'),x=cv.getContext('2d');let sd=9;const rnd=()=>(sd=(sd*1664525+1013904223)%4294967296)/4294967296,g=()=>{let s=0;for(let i=0;i<6;i++)s+=rnd();return s/6;};
const S=[];for(let i=0;i<4000;i++){const r=rnd();S.push(r<.35?.2+g()*.35:r<.8?.4+g()*.45:.1+g()*.2);}
function up(){const e=ex.value/10,f=Math.pow(2,e),bins=new Array(30).fill(0);let clipH=0,clipS=0;S.forEach(v=>{let y=v*f;if(y>=1){clipH++;y=.999;}if(y<.07)clipS++;bins[Math.min(29,Math.max(0,Math.floor(y*30)))]++;});
x.clearRect(0,0,150,90);const mx=Math.max(...bins.slice(1,29),1),w=150/30;bins.forEach((c,i)=>{const h=Math.min(86,c/mx*80);x.fillStyle=(i===29&&c>0)||(i===0&&c>0)?'#e5484d':'#555';x.fillRect(i*w+.5,90-h,w-1,h);});
sc.style.setProperty('--b',Math.max(.15,f).toFixed(2));document.getElementById('ev').textContent=(e>0?'+':'')+e.toFixed(1)+' EV';const ph=Math.round(clipH/S.length*100),ps=Math.round(clipS/S.length*100);
document.getElementById('out').innerHTML=ph>3?'<b>Highlights clipped:</b> '+ph+'% of pixels are pure white and cannot be recovered.':ps>3?'<b>Shadows clipped:</b> '+ps+'% of pixels are pure black.':'<b>Well balanced:</b> the graph sits inside the edges.';}
ex.addEventListener('input',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>Histogram & Exposure — 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}}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.row3{display:grid;grid-template-columns:1fr 150px;gap:10px;align-items:start}.sc{height:90px;border-radius:10px;position:relative;overflow:hidden;filter:brightness(var(--b))}.sc i{position:absolute;display:block}.sk{inset:0 0 50% 0;background:linear-gradient(#7fa7d9,#d6e6f7)}.mt{left:-5%;right:-5%;bottom:30%;height:40%;background:#52606d;clip-path:polygon(0 100%,0 60%,25% 20%,45% 55%,70% 10%,100% 60%,100% 100%)}.lk{left:0;right:0;bottom:0;height:34%;background:linear-gradient(#5d86a8,#34536d)}
canvas{width:150px;height:90px;border:1px solid var(--line);border-radius:8px;background:#fff}.out{font-size:12px;color:var(--muted);min-height:34px}.out b{color:var(--text)}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="row3"><div class="sc" id="sc"><i class="sk"></i><i class="mt"></i><i class="lk"></i></div><canvas id="hg" width="150" height="90" aria-label="Histogram"></canvas></div><label class="rw">Exposure <b id="ev">0.0 EV</b><input id="ex" type="range" min="-30" max="30" value="0"></label><p class="out" id="out"></p></div>
</div>
<script>
const ex=document.getElementById('ex'),sc=document.getElementById('sc'),cv=document.getElementById('hg'),x=cv.getContext('2d');let sd=9;const rnd=()=>(sd=(sd*1664525+1013904223)%4294967296)/4294967296,g=()=>{let s=0;for(let i=0;i<6;i++)s+=rnd();return s/6;};
const S=[];for(let i=0;i<4000;i++){const r=rnd();S.push(r<.35?.2+g()*.35:r<.8?.4+g()*.45:.1+g()*.2);}
function up(){const e=ex.value/10,f=Math.pow(2,e),bins=new Array(30).fill(0);let clipH=0,clipS=0;S.forEach(v=>{let y=v*f;if(y>=1){clipH++;y=.999;}if(y<.07)clipS++;bins[Math.min(29,Math.max(0,Math.floor(y*30)))]++;});
x.clearRect(0,0,150,90);const mx=Math.max(...bins.slice(1,29),1),w=150/30;bins.forEach((c,i)=>{const h=Math.min(86,c/mx*80);x.fillStyle=(i===29&&c>0)||(i===0&&c>0)?'#e5484d':'#555';x.fillRect(i*w+.5,90-h,w-1,h);});
sc.style.setProperty('--b',Math.max(.15,f).toFixed(2));document.getElementById('ev').textContent=(e>0?'+':'')+e.toFixed(1)+' EV';const ph=Math.round(clipH/S.length*100),ps=Math.round(clipS/S.length*100);
document.getElementById('out').innerHTML=ph>3?'<b>Highlights clipped:</b> '+ph+'% of pixels are pure white and cannot be recovered.':ps>3?'<b>Shadows clipped:</b> '+ps+'% of pixels are pure black.':'<b>Well balanced:</b> the graph sits inside the edges.';}
ex.addEventListener('input',up);up();
</script>
</body></html>