Opacity Stack Colour Mixing
Two translucent circles over white: change the alpha and the stacking order to see how the overlap colour changes.
AI prompt
Clean illustration of two large overlapping circles, one translucent blue and one translucent orange, on a white background, the lens-shaped overlap showing a muted brownish blend, below it a second pair of circles with the order reversed and a slightly different overlap colour, small hex labels on each region, flat vector style, no outlines. Negative: gradients, shadows, clutter, text errors. Reduced motion: static illustration.About this pattern
Definition
When translucent colours overlap on screen, the result depends on opacity and on which layer is on top. With normal alpha blending each layer replaces part of what is below it, so order matters. The overlap is a weighted mix: result equals top times alpha plus below times one minus alpha.
When to use it
- Opacity 100 percent hides what is below; 50 percent mixes evenly.
- Swapping the order changes the overlap unless both alphas are the same.
- Layers over a white page look lighter; over black they look darker.
- Use blend modes like multiply when you want subtractive mixing instead.
What the controls do
- Order buttons and an Opacity slider; the mixed hex is shown.
Motion & timing
- Updates are immediate.
- Reduced motion: nothing animates.
Tips & variations
- Text on translucent colours needs a contrast check against the mixed result.
- Many stacked layers are expensive to paint.
Code of this live preview
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Order"><button data-p="0" aria-pressed="true">Blue over orange</button><button data-p="1" aria-pressed="false">Orange over blue</button></div><div class="sc" id="sc"><i class="a" id="ca"></i><i class="b" id="cb"></i></div><label class="rw">Opacity <b id="av">60%</b><input id="as" type="range" min="20" max="100" value="60"></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}
.sc{position:relative;height:120px;border-radius:12px;background:#fff;border:1px solid var(--line);overflow:hidden}.sc i{position:absolute;top:14px;width:92px;height:92px;border-radius:50%}.a{left:calc(50% - 80px);background:#2f6bff;opacity:var(--al,.6);z-index:var(--za,2)}.b{left:calc(50% - 12px);background:#ff8a1f;opacity:var(--al,.6);z-index:var(--zb,1)}.out{font-size:12px;color:var(--muted);min-height:16px;margin:0}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const as=document.getElementById('as'),sc=document.getElementById('sc'),bs=[...document.querySelectorAll('#pre button')];let p=0;const A=[47,107,255],B=[255,138,31],W=[255,255,255];
const hx=c=>'#'+c.map(v=>Math.round(v).toString(16).padStart(2,'0')).join('');const mix=(t,b,a)=>t.map((v,i)=>v*a+b[i]*(1-a));
function up(){const a=as.value/100;sc.style.setProperty('--al',a);sc.style.setProperty('--za',p===0?2:1);sc.style.setProperty('--zb',p===0?1:2);document.getElementById('av').textContent=as.value+'%';
const top=p===0?A:B,bot=p===0?B:A,botW=mix(bot,W,a),ov=mix(top,botW,a);document.getElementById('out').textContent='Overlap '+hx(ov)+' \u00b7 top alone '+hx(mix(top,W,a))+' \u00b7 bottom alone '+hx(botW);bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;up();}));as.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>Opacity Stack Colour Mixing — 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}
.sc{position:relative;height:120px;border-radius:12px;background:#fff;border:1px solid var(--line);overflow:hidden}.sc i{position:absolute;top:14px;width:92px;height:92px;border-radius:50%}.a{left:calc(50% - 80px);background:#2f6bff;opacity:var(--al,.6);z-index:var(--za,2)}.b{left:calc(50% - 12px);background:#ff8a1f;opacity:var(--al,.6);z-index:var(--zb,1)}.out{font-size:12px;color:var(--muted);min-height:16px;margin:0}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Order"><button data-p="0" aria-pressed="true">Blue over orange</button><button data-p="1" aria-pressed="false">Orange over blue</button></div><div class="sc" id="sc"><i class="a" id="ca"></i><i class="b" id="cb"></i></div><label class="rw">Opacity <b id="av">60%</b><input id="as" type="range" min="20" max="100" value="60"></label><p class="out" id="out"></p></div>
</div>
<script>
const as=document.getElementById('as'),sc=document.getElementById('sc'),bs=[...document.querySelectorAll('#pre button')];let p=0;const A=[47,107,255],B=[255,138,31],W=[255,255,255];
const hx=c=>'#'+c.map(v=>Math.round(v).toString(16).padStart(2,'0')).join('');const mix=(t,b,a)=>t.map((v,i)=>v*a+b[i]*(1-a));
function up(){const a=as.value/100;sc.style.setProperty('--al',a);sc.style.setProperty('--za',p===0?2:1);sc.style.setProperty('--zb',p===0?1:2);document.getElementById('av').textContent=as.value+'%';
const top=p===0?A:B,bot=p===0?B:A,botW=mix(bot,W,a),ov=mix(top,botW,a);document.getElementById('out').textContent='Overlap '+hx(ov)+' \u00b7 top alone '+hx(mix(top,W,a))+' \u00b7 bottom alone '+hx(botW);bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;up();}));as.addEventListener('input',up);up();
</script>
</body></html>