
- CSS - Home
- CSS - Roadmap
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Types
- CSS - Measurement Units
- CSS - Selectors
- 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 - Cascading
- CSS - Universal Selectors
- CSS - ID Selectors
- CSS - Group Selectors
- CSS - Class Selectors
- CSS - Child Selectors
- CSS - Element Selectors
- CSS - Descendant Selectors
- CSS - General Sibling Selectors
- CSS - Adjacent Sibling Selectors
- 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 Advanced Features
- 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 Interview Questions
- CSS Online Quiz
- CSS Online Test
- CSS Mock Test
- CSS - Quick Guide
- CSS - Cheatsheet
- CSS - Properties References
- CSS - Functions References
- CSS - Color References
- CSS - Web Browser References
- CSS - Web Safe Fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS - mask-size Property
CSS mask-size property in CSS is used to specify the size of a mask image applied to an element using the mask-image property. It allows you to control the dimensions of the mask, determining how it is scaled or displayed within the element.
Syntax
mask-size: auto | size | contain | cover | initial | inherit;
Property Values
Value | Description |
---|---|
auto | The auto value adjusts the mask image sizes proportionally in both the horizontal and vertical directions while maintaining its intrinsic proportions. |
length | The length value adjusts the mask image to the specified dimensions. Negative lengths are not allowed. |
percentage | The percentage value adjusts the mask image based on a percentage of the mask positioning area defined by the mask-origin property. Negative percentages are not allowed. |
contain | It resizes the image to its maximum size while maintaining the original aspect ratio without getting stretched or squished. |
cover | This value scales the image to its maximum size while preserving the aspect ratio, clipping it if necessary when dimensions differ from the container. |
initial | It sets the property to its default value. |
inherit | It inherits the property from the parent element. |
Examples of CSS Mask Size Property
The following examples explain the mask-size property with different values.
Mask Size Property with Contain Value
To scale the mask image to fit within the elements dimensions, preserving the image's aspect ratio, we use the contain value. The entire image will be visible, but there may be empty space around the edges of the element. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { -webkit-mask-image: url(/css/images/logo.png); mask-image: url(/css/images/logo.png); mask-size: contain; mask-repeat: no-repeat; } </style> </head> <body> <h2> CSS mask-size Property </h2> <h4> mask-size: contain </h4> <div class="container"> <img src="/css/images/scenery.jpg" alt="img" width="500" height="300"> </div> <h4> image used: </h4> <img src="/css/images/scenery.jpg" alt="img" width="200" height="150"> </body> </html>
Mask Size Property with Cover Value
To scale the mask image to cover the entire area of the element, ensuring that the image covers the element completely without stretching, but potentially cropping the image, we use the cover value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { -webkit-mask-image: url(/css/images/logo.png); mask-image: url(/css/images/logo.png); mask-size: cover; mask-repeat: no-repeat; } </style> </head> <body> <h2> CSS mask-size Property </h2> <h4> mask-size: cover </h4> <div class="container"> <img src="/css/images/scenery.jpg" alt="img" width="500" height="400"> </div> <h4> image used: </h4> <img src="/css/images/scenery.jpg" alt="img" width="200" height="150"> </body> </html>
Mask Size Property with Length Values
To set the size of the mask image, we can specify the size in length units (e.g. px, em, rem etc.). This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { -webkit-mask-image: url(/css/images/logo.png); mask-image: url(/css/images/logo.png); mask-repeat: no-repeat; } .ex1 { mask-size: 350px; } .ex2 { mask-size: 500px; } </style> </head> <body> <h2> CSS mask-size Property </h2> <h4> mask-size: 350px </h4> <div class="container ex1"> <img src="/css/images/scenery.jpg" alt="img" width="500" height="200"> </div> <h4> mask-size: 500px </h4> <div class="container ex2"> <img src="/css/images/scenery.jpg" alt="img" width="500" height="200"> </div> <h4> image used: </h4> <img src="/css/images/scenery.jpg" alt="img" width="200" height="150"> </body> </html>
Mask Size Property with Percentage Values
To set the size of the mask image, we can specify the size in percentage values (e.g. 10%) relative to the size of the containing element. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { -webkit-mask-image: url(/css/images/logo.png); mask-image: url(/css/images/logo.png); mask-repeat: no-repeat; } .ex1 { mask-size: 50%; } .ex2 { mask-size: 38%; } </style> </head> <body> <h2> CSS mask-size Property </h2> <h4> mask-size: 50% </h4> <div class="container ex1"> <img src="/css/images/scenery.jpg" alt="img" width="500" height="100"> </div> <h4> mask-size: 38% </h4> <div class="container ex2"> <img src="/css/images/scenery.jpg" alt="img" width="500" height="100"> </div> <h4> image used: </h4> <img src="/css/images/scenery.jpg" alt="img" width="200" height="150"> </body> </html>
Mask Size Property with Auto Value
To let the mask image appear at its original dimensions without any intrinsic scaling, we use the auto value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { -webkit-mask-image: url(/css/images/logo.png); mask-image: url(/css/images/logo.png); mask-size: auto; mask-repeat: no-repeat; } </style> </head> <body> <h2> CSS mask-size Property </h2> <h4> mask-size: auto </h4> <div class="container"> <img src="/css/images/scenery.jpg" alt="img" width="400" height="100"> </div> <h4> image used: </h4> <img src="/css/images/scenery.jpg" alt="img" width="200" height="150"> </body> </html>
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
mask-size | 120 | 120 | 53 | 15.4 | 106 |