Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS box-reflect Property

Posted in CSS Tutorial
Updated on Oct 02, 2024
By Mari Selvan
👁️ 15 - Views
⏳ 4 mins
💬 1 Comment
CSS box-reflect Property

Photo Credit to CodeToFun

🙋 Introduction

The box-reflect property in CSS is a non-standard property that allows you to create a reflection of an element.

This property is primarily supported in WebKit-based browsers such as Safari and older versions of Chrome. It can be used to create visually appealing effects by reflecting the content of an element, much like a mirror.

💡 Syntax

The syntax for the box-reflect property includes specifying the direction of the reflection and optional parameters for offset and masking.

Syntax
Copied
Copy To Clipboard
element {
  -webkit-box-reflect: direction offset mask;
}

🎛️ Default Value

The box-reflect property does not have a default value because it is a non-standard property and must be explicitly set for each element.

🏠 Property Values

ValueDescription
directionabove, below, left, right.
offsetAny valid CSS length value (e.g., 0px, 10px, 1em).
maskOptional. Can be a gradient or any other valid CSS image value used to mask the reflection.

📄 Example

In this example, we'll create a reflection of an image below the element with a 10px offset.

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 box-reflect Example</title>
  <style>
    .reflect {
      -webkit-box-reflect: below 10px;
    }
  </style>
</head>
<body>
  <h1>Image with Reflection</h1>
  <img src="example.jpg" alt="Example Image" class="reflect">
</body>
</html>

🖥️ Browser Compatibility

The box-reflect property is non-standard and is only supported in WebKit-based browsers such as Safari and older versions of Chrome. It is not supported in other major browsers like Firefox or Edge. Therefore, use this property with caution and always provide fallback styles for broader compatibility.

🎉 Conclusion

The box-reflect property can add a unique visual effect to your web elements by creating reflections. However, due to its limited browser support, it should be used sparingly and with appropriate fallbacks. Experiment with different directions, offsets, and masks to achieve the desired effect and enhance your website's design.

👨‍💻 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