COLOR / 053

Color mixing

CSSで色を混ぜる
二つの色を、指定した色空間と比率で混ぜます。

実際のHTML・CSSで描かれた見本です。

ラボで詳しく試す ↗

ひとつ試すなら

どこが変わるかを観察して、似た表現と見比べてみよう。

こんなときに

ブランドカラーから淡い背景色をつくるとき。

仕組みと使い方

混ぜる色空間によって、中間色は変わります。

color-mix混色パレット中間色
実装コードを見る
<style>
.sample{width:100%;height:100%;min-height:190px;display:grid;place-items:center;position:relative;overflow:hidden;box-sizing:border-box;font-family:Arial,'Hiragino Kaku Gothic ProN',Meiryo,sans-serif;color:#20211d;background:#f1f0e9;padding:22px}.sample *{box-sizing:border-box}.sample button,.sample input,.sample summary{font:inherit}.sample button,.sample summary,.sample label{touch-action:manipulation}.sample :focus-visible{outline:3px solid #6050bf;outline-offset:5px}.sample small{font-size:10px;line-height:1.5}.sample .editable{margin:0}.sample svg{max-width:100%;height:auto}
.sample .mix{display:flex;align-items:center;gap:10px}.sample i{width:58px;height:58px;border-radius:50%;display:grid;place-items:center;font:11px monospace;background:var(--accent,#c9f537)}.sample i:nth-of-type(2){background:color-mix(in oklab,var(--accent,#c9f537) 50%,white)}.sample i:nth-of-type(3){background:color-mix(in oklab,var(--accent,#c9f537) 20%,white)}.sample b{font-weight:400}
</style>
<div class="sample">
<div class="mix"><i>100</i><b>+</b><i>50</i><b>+</b><i>20</i></div>
</div>