IMAGE / 081

Grayscale filter

白黒にする
画像の彩度を取り除き、グレースケールで表示します。

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

ラボで詳しく試す ↗

ひとつ試すなら

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

こんなときに

色を抑えた写真や、色の有無を比較するとき。

仕組みと使い方

画像ファイルそのものを書き換えず、表示にフィルターを適用します。

白黒モノクロ写真grayscale
実装コードを見る
<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 svg{width:210px;border-radius:12px;filter:grayscale(1)}
</style>
<div class="sample">
<svg viewBox="0 0 240 160" role="img" aria-label="オレンジの太陽と紫の山の図形イラスト"><rect width="240" height="160" fill="#c2dfdb"/><circle cx="168" cy="46" r="29" fill="#ff7540"/><path d="M0 150 85 45 155 145 207 87 240 131V160H0Z" fill="#8c79bd"/><path d="m0 113 49-25 85 72H0Z" fill="#cedb70"/></svg>
</div>