![CSS Selectors](https://codetofun.com/wp-content/themes/codetofun/images/large/css-selectors.webp)
CSS Properties
CSS mask-size Property
![CSS mask-size Property](https://codetofun.com/wp-content/themes/codetofun/images/large/css-mask-size.webp)
Photo Credit to CodeToFun
🙋 Introduction
The mask-size
property in CSS is used to define the size of an element's mask image. Masks are used to hide or reveal parts of an element by using an image or another graphical representation.
By setting the size of the mask, you can control how the image fits the element and how it affects the visibility of the underlying content.
💡 Syntax
The syntax for the mask-size
property is as follows:
element {
mask-size: value;
}
🎛️ Default Value
The default value of the mask-size
property is auto, which means the mask image is displayed at its intrinsic size or scaled to fit the element, depending on the mask-repeat property.
🏠 Property Values
Value | Description |
---|---|
auto | The mask image is displayed at its intrinsic size. |
length | Specifies the width and height of the mask image using a length value (e.g., 100px, 50%). |
percentage | Specifies the width and height of the mask image using a percentage of the element's size. |
cover | The mask image is scaled to be as large as possible while maintaining its aspect ratio. The image will cover the entire element, and some parts may be clipped. |
contain | The mask image is scaled to fit within the element while maintaining its aspect ratio. The image will be fully visible, but may not cover the entire element. |
📄 Example
In this example, we'll use a mask image on a div element and set the size to cover the entire element.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS mask-size Example</title>
<style>
.masked-element {
width: 300px;
height: 300px;
background-color: lightblue;
mask-image: url('mask.png');
mask-size: cover;
}
</style>
</head>
<body>
<h1>Div with Mask Image and Custom Size</h1>
<div class="masked-element"></div>
</body>
</html>
🖥️ Browser Compatibility
The mask-size
property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.
🎉 Conclusion
The mask-size
property is a versatile tool for web developers looking to create intricate designs and effects.
By controlling the size of a mask image, you can precisely determine how it interacts with the content it covers. Experimenting with different mask sizes can lead to unique and visually appealing results that enhance the user experience on your website.
👨💻 Join our Community:
Author
![author](https://codetofun.com/wp-content/themes/codetofun/images/mari-selvan-400.webp)
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (CSS mask-size Property), please comment here. I will help you immediately.