Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS mask-size Property

Posted in CSS Tutorial
Updated on Oct 07, 2024
By Mari Selvan
👁️ 11 - Views
⏳ 4 mins
💬 1 Comment
CSS mask-size Property

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:

Syntax
Copied
Copy To Clipboard
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

ValueDescription
autoThe mask image is displayed at its intrinsic size.
lengthSpecifies the width and height of the mask image using a length value (e.g., 100px, 50%).
percentageSpecifies the width and height of the mask image using a percentage of the element's size.
coverThe 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.
containThe 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.

index.html
Copied
Copy To Clipboard
<!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:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

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

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy