
- 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-position Property
CSS mask-position property is used to specify the positioning of a mask image within an element. The mask image is typically defined using the mask-image property, and mask-position allows you to control where the mask image is placed within the element's box, relative to the mask position layer set by mask-origin property.
Syntax
mask-position: top | right | bottom | left | center | length | percentage | initial | inherit;
Property Values
Value | Description |
---|---|
|
The position of the mask is set using the keywords: left, right, top, bottom, center. If single value is provided, the other value is center. |
length (xpos, ypos) | The first value sets the horizontal distance and second value sets the vertical distance. Top left top corner is 0 0 . Any length units can be used (e.g. px, em, rem etc.). If single value is provided the other value is 50%. |
percentage (x%, y%) | The first value sets the horizontal distance and second value sets the vertical distance. Top left top corner is 0% 0% and right bottom corner is 100% 100%. If single value is provided the other value is 50%. Default: 0% 0% |
initial | It sets the property to its default value. |
inherit | It inherits the property from the parent element. |
Examples of CSS Mask Position Property
The following examples explain the mask-position property with different values.
Mask Position Property with Keyword Values
To set the position of the mask, we can use the keyword values: left, right, top, center and bottom. Upto two values are accepted. If two values are specified, the first value sets the horizontal distance and the second value sets the vertical distance. If single value is given, the other value is taken as center. These are shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { border: 2px solid; height: 400px; width: 450px; } .mask { -webkit-mask-image: url(/css/images/logo.png); mask-image: url(/css/images/logo.png); mask-size: 50%; mask-repeat: no-repeat; } .ex1 { mask-position: left center; } .ex2 { mask-position: center; } .ex3 { mask-position: right top; } </style> </head> <body> <h2> CSS mask-position Property </h2> <h4> mask-position: left center (two values- define x position and y position repectively) </h4> <div class="container"> <div class="mask ex1"> <img src="/css/images/scenery.jpg" alt="img" width="600" height="400"> </div> </div> <h4> mask-position: center (single value, the second value is also center) </h4> <div class="container"> <div class="mask ex2"> <img src="/css/images/scenery.jpg" alt="img" width="600" height="400"> </div> </div> <h4> mask-position: right top (two values- define x position and y position repectively) </h4> <div class="container"> <div class="mask ex3"> <img src="/css/images/scenery.jpg" alt="img" width="600" height="400"> </div> </div> </body> </html>
Mask Position Property with Length Values
To set the position of a mask, we can specify the position using length units (e.g. px, em, rem etc.). Upto two values are accepted. If two values are specified, the first value sets the horizontal distance and the second value sets the vertical distance. If single value is given, the other value is taken as 50%. These are shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { border: 2px solid; height: 400px; width: 450px; } .mask { -webkit-mask-image: url(/css/images/logo.png); mask-image: url(/css/images/logo.png); mask-size: 50%; mask-repeat: no-repeat; } .ex1 { mask-position: 70px 90px; } .ex2 { mask-position: 7em 14em; } </style> </head> <body> <h2> CSS mask-position Property </h2> <h4> mask-position: 70px 90px (70px from left edge and 90px from top edge) </h4> <div class="container"> <div class="mask ex1"> <img src="/css/images/scenery.jpg" alt="img" width="600" height="400"> </div> </div> <h4> mask-position: 7em 14em (7em from the left edge and 14em from top edge) </h4> <div class="container"> <div class="mask ex2"> <img src="/css/images/scenery.jpg" alt="img" width="600" height="400"> </div> </div> </body> </html>
Mask Position Property with Percentage Values
To set the position of a mask, we can specify the position using percentage values (e.g. 10%) relative to the size of the container. Upto two values are accepted. If two values are specified, the first value sets the horizontal distance and the second value sets the vertical distance. If single value is given, the other value is taken as 50%. These are shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { border: 2px solid; height: 400px; width: 450px; } .mask { -webkit-mask-image: url(/css/images/logo.png); mask-image: url(/css/images/logo.png); mask-size: 50%; mask-repeat: no-repeat; } .ex1 { mask-position: 70% 30%; } .ex2 { mask-position: 50%; } </style> </head> <body> <h2> CSS mask-position Property </h2> <h4> mask-position: 70% 30% (70% from left edge and 30% from the top edge relative to the container height and width) </h4> <div class="container"> <div class="mask ex1"> <img src="/css/images/scenery.jpg" alt="img" width="600" height="400"> </div> </div> <h4> mask-position: 50% ( second value is also 50%, 50% from the left edge and 50% from the top edge relative to the container height and width) </h4> <div class="container"> <div class="mask ex2"> <img src="/css/images/scenery.jpg" alt="img" width="600" height="400"> </div> </div> </body> </html>
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
mask-position | 120 | 120 | 53 | 15.4 | 106 |