bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/CSS/Advanced Styling
CSS•Advanced Styling

CSS Gradient Mask Layers

CSS gradients can also be used as the mask layer image.

Linear Gradient Mask Layer

Here, we use a linear gradient mask layer for our image. This linear gradient goes from top (black) to bottom (transparent):

Example

Formatted code
.mask1 {
  -webkit-mask-image: linear-gradient(black, transparent);
  mask-image: linear-gradient(black, transparent);
}

Live preview

Here, we use a linear gradient along with text masking as the mask layer for our image:

Cinque Terre is a coastal area within Liguria, in the northwest of Italy. It lies in the west of La Spezia Province, and comprises five villages: Monterosso al Mare, Vernazza, Corniglia, Manarola, and Riomaggiore.

Example

Formatted code
.mask1 {
  max-width: 600px;
  height: 400px;
  background: url(img_5terre.jpg) no-repeat;
  -webkit-mask-image: linear-gradient(black, transparent);
  mask-image: linear-gradient (black, transparent);
}

Live preview

Radial Gradient Mask Layer - Circle

Here, we use a radial gradient (shaped as a circle) as the mask layer for our image:

Example

Formatted code
.mask2 {
  -webkit-mask-image: radial-gradient(circle, black 50%, rgba(0, 0, 0, 0.5) 50%);
  mask-image: radial-gradient(circle, black 50%, rgba(0, 0, 0, 0.5) 50%);
}

Live preview

Radial Gradient Mask Layer - Ellipse

Here, we use a radial gradient (shaped as an ellipse) as the mask layer for our image:

Example

Formatted code
.mask3 {
  -webkit-mask-image: radial-gradient(ellipse, black 50%, rgba(0, 0, 0, 0.5) 50%);
  mask-image: radial-gradient(ellipse, black 50%, rgba(0, 0, 0, 0.5) 50%);
}

Live preview

Conic Gradient Mask Layer

Here, we use a conic gradient as the mask layer for our image:

Example

Formatted code
.mask3 {
  -webkit-mask-image: conic-gradient(black 0deg, transparent 360deg);
  mask-image: conic-gradient(black 0deg, transparent
  360deg);
}

Live preview

CSS All Masking Properties

The following table lists all the CSS masking properties:

PropertyDescription
mask-clipSpecifies which area is affected by a mask image
mask-compositeSpecifies a compositing operation used on the current mask layer with the mask layers below it
mask-imageSpecifies an image to be used as a mask layer for an element
mask-modeSpecifies whether the mask layer image is treated as a luminance mask or as an alpha mask
mask-originSpecifies the origin position (the mask position area) of a mask layer image
mask-positionSets the starting position of a mask layer image (relative to the mask position area)
mask-repeatSpecifies how the mask layer image is repeated
mask-sizeSpecifies the size of a mask layer image
mask-typeSpecifies whether an SVG <mask> element is treated as a luminance mask or as an alpha mask

Previous

CSS Masking

Next

CSS SVG Mask Layers

This chapter

Overview
53

Lessons

154m

Read time

1. CSS Rounded Corners2. Sass Tutorial3. CSS Border Images4. CSS Multiple Backgrounds5. CSS Background Size6. CSS Background Origin7. CSS Background Clip8. CSS Colors9. CSS Color Keywords10. CSS Gradients11. CSS Radial Gradients12. CSS Conic Gradients13. CSS Shadow Effects14. CSS Box Shadow15. CSS Text Effects16. CSS Custom Fonts17. CSS 2D Transforms18. CSS 2D Transform Scale19. CSS 2D Transform Skew / Matrix20. CSS 3D Transforms21. CSS Transitions22. CSS Transition Timing23. CSS Animations24. CSS Animation Timing25. CSS Animation Properties26. CSS Tooltip27. CSS Tooltip Arrows28. CSS Styling Images29. CSS Image Effects30. CSS Image Hover Overlays31. CSS Responsive Modal Images32. CSS Centering Images33. CSS Image Filter Effects34. CSS Image Shapes35. CSS object-fit Property36. CSS object-position Property37. CSS Masking38. CSS Gradient Mask Layers39. CSS SVG Mask Layers40. CSS Styling Buttons41. CSS Button Hover Effects42. CSS Button Groups43. CSS Pagination Styles44. CSS Multiple Columns45. CSS Column Rules46. CSS User Interface47. CSS Variables - var() Function48. CSS Overriding Variables49. CSS Variables and JavaScript50. CSS Variables in Media Queries51. CSS @property Rule52. CSS Box Sizing53. CSS Media Queries

On this page

Linear Gradient Mask LayerRadial Gradient Mask Layer - CircleRadial Gradient Mask Layer - EllipseConic Gradient Mask LayerCSS All Masking Properties