Photography and Imagery · Step 5 · 5 min read
Masks, clip paths and scrims
Showing only part of a photo, without cutting the file: clip paths for hard shapes, masks for soft fades, and scrims so text can sit on an image and still pass contrast. With the CSS for each and the checks that keep them honest.
The best crop is the one you never saved. When a photo has to fit a circle, fade into the page or carry a headline, you can cut a new file for each case, or leave the file whole and let the layout decide what shows. The second way keeps the photo for the next layout, and the next screen size. It's what masks, clip paths and scrims are for.
What you'll be able to do after reading:
- Choose between a clip path, a mask and a scrim
- Write each one in CSS
- Put text on a photo and keep it readable
- Check the result on the image's worst spot, not its best
1. Three ways to show part of a photo, and one to write on it
Circle: clip-pathA hard shape
Rounded inset: clip-pathA frame inside the photo
Fade: mask-imageA soft edgeAll three tiles use the same file. The differences, and the fourth tool:
- A clip path cuts a hard shape: a circle, a rounded box, any polygon. Everything outside is gone (MDN, clip-path).
- A mask uses an image or a gradient to decide how visible each pixel is, so it can fade softly (MDN, mask-image).
- A scrim doesn't hide anything. It's a dark (or light) gradient laid over the photo, so text placed on it has something steady to stand on. It has its own figure in section 3.
.circle img { clip-path: circle(36% at 50% 50%); }
.inset img { clip-path: inset(7% round 1.5rem); }
.fade img { mask-image: linear-gradient(to bottom, #000 45%, transparent 95%); }
.scrim::after { content: ""; position: absolute; inset: 0;
background: linear-gradient(to top, rgb(10 10 12 / .78), transparent 65%); }
2. Shapes have a meaning
A circle around a photo says "person": it's the shape of avatars everywhere. A rounded rectangle says "card" or "thing". A torn or irregular shape says "editorial", "playful", sometimes "cheap". Pick the shape for what it says, and keep it consistent: a product with circles, hexagons and blobs looks like three products.
And remember Crop and aspect ratio: a clip path is a crop. The subject still needs to be inside it, at every size. A circle on a photo whose subject sits on the left third cuts the subject in half.
3. Text on a photo
Text on a photo is the hardest case, because the photo changes under the letters: light sky behind one word, dark trees behind the next. WCAG asks for a contrast of at least 4.5 to 1 for normal text, and 3 to 1 for large text, and that applies to text over images too (W3C, Understanding contrast (minimum)).
Three ways to get there, from best to worst:
- Put the text in the photo's empty space, like the headline in the sky in Composition. If the photo has the space, you need no treatment.
- Add a scrim under the text, strong enough that the lightest spot of the photo behind the text still passes.
No scrim: 1.7 to 1
With a scrim: over 7 to 1- Put a solid box behind the text. Always readable, and the least elegant.
Check contrast at the worst spot under the text, not on average. And check every photo the component will ever carry, not just the one in the mockup: a scrim tuned for a dark forest fails on a white beach. The next step, from Measuring contrast on a photo, goes deeper.
4. Keeping it honest
- Hiding is not removing. A clipped or masked part of a photo is still in the file and still downloaded. Don't use a mask to hide something that shouldn't be published.
- Alt text describes what people see. If a mask shows only the face, the alt text describes the face, not the full photo.
- Masks on product photos can hide the part a buyer wanted to check. The rule from What an image does in a product holds: the job comes first.
5. Common mistakes
- A clip path that cuts the subject at some screen sizes.
- A scrim tested on one photo and reused on all of them.
- Text in a blend mode, or with a text shadow as the only help, over a busy photo.
- Five different mask shapes in one product.
6. Vocabulary
| Term | Meaning |
|---|---|
| Clip path | A shape that shows the part of an element inside it and hides the rest |
| Mask | An image or gradient that sets how visible each part of an element is |
| Scrim | A gradient or tint over a photo that gives text a steady background |
| Contrast ratio | How different two colours are in lightness, from 1:1 to 21:1 |
7. Try it (no tools needed)
- Find three product pages with text on a photo.
- For each, find the spot where the text is hardest to read.
- Decide which of the three fixes would solve it: empty space, scrim or a box.
Reflection questions: Did the designer plan for the worst photo, or only the best one? How would you write the rule so the next photo works too?
8. If you already practise
- Make the scrim part of the image component, with its strength as a token, not something each designer draws.
- Test text-on-image components with your lightest and busiest real photos before you ship.
- Write the approved mask shapes into the image style guide, next to the grade and the grain.
Checklist
Learn more
Related
Crop and aspect ratio · Composition · Texture, grain and noise · Treatment with a purpose