- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Selectors
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Hyphenate Character
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS Masking - mask-type
The CSS property mask-type sets an SVG <mask> element as a luminance or an alpha mask. It applies to the <mask> element itself.
The mask-mode CSS property can override this property, as it has the same effect. The only difference is, it gets applied to the element where mask is used. Rendering of alpha masks is generally faster.
Possible values
The CSS property mask-type is specifies as one of the following values:
luminance: It is a keyword that signifies that the mask image associated is a luminance mask.
alpha: It is a keyword that signifies that the mask image associated is an alpha mask. The transparency (alpha channel) values of the mask layer image are used as the mask values. Alpha value or alpha channel specifies to the opacity of the <color>.
Applies to
Applied to all the <mask> elements.
Syntax
mask-type = luminance | alpha;
CSS mask-type - alpha Value
The following example demonstrates the use of the CSS property mask-type, where a mask element with black and transparent areas is used. The element's id (#mask) is used, which places the mask on the <div> element. As the mask has black and transparent areas, the mask-type is set to alpha.
<html> <head> <style> div { width: 150px; height: 150px; background-color: purple; mask-image: url(#mask); } mask { mask-type: alpha; } </style> </head> <body> <div></div> <svg> <mask id="mask"> <path fill="black" d="M10,35 A20,20,0,0,1,50,35 A20,20,0,0,1,90,35 Q90,65,50,95 Q10,65,10,35 Z" /> </mask> </svg></body> </html>
CSS mask-type - Luminance Value
The following example demonstrates the use of the CSS property mask-type with value as luminance.
<html> <head> <style> body { display: flex; align-items: center; justify-content: center; height: 100%; margin: 0; background-color: darkgrey; overflow: hidden; } .container { display: grid; position: relative; padding: 20px; border: 2px solid black; } .box { margin: 20px; display: block; width: 200px; height: 150px; background-image: url(images/border.png); mask-type: luminance; } .overlay { position: absolute; width: 100%; height: 100%; background-color: rgb(0, 201, 0, 0.2); } </style> </head> <body> <div class="container"> <div class="box"></div> <div class="overlay"></div> </div> </body> </html>
In the above example:
The .box class represents the element with the background image that will be masked.
The .overlay class is used to add a light green overlay to the masked area for better visibility.
To Continue Learning Please Login
Login with Google