Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Topics

CSS box-shadow Property

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

Photo Credit to CodeToFun

🙋 Introduction

The box-shadow property in CSS allows you to add shadow effects to elements. You can create multiple shadows separated by commas, and it supports options for color, blur radius, spread radius, and horizontal and vertical offsets.

This property is versatile and can be used to enhance the visual appeal of your website by adding depth and dimension to elements.

💡 Syntax

The syntax for the box-shadow property includes several parameters, but not all are required. The most basic usage only requires the horizontal and vertical offsets.

Syntax
Copied
Copy To Clipboard
element {
  box-shadow: h-offset v-offset blur-radius spread-radius color;
}

🎛️ Default Value

The default value for the box-shadow property is none, meaning no shadow will be applied.

🏠 Property Values

ValueDescription
h-offsetA length value specifying the horizontal shadow offset.
v-offsetA length value specifying the vertical shadow offset.
blur-radiusA length value specifying the blur radius. (Optional)
spread-radiusA length value specifying the spread radius. (Optional)
colorA color value specifying the color of the shadow. (Optional)
insetIf specified, the shadow is drawn inside the element, making it appear as an inner shadow.

📄 Example

In this example, we'll add a simple shadow to a box.

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-shadow Example</title>
  <style>
    .box {
      width: 200px;
      height: 200px;
      background-color: lightblue;
      box-shadow: 10px 10px 5px gray;
    }
  </style>
</head>
<body>
  <h1>Box with Shadow</h1>
  <div class="box"></div>
</body>
</html>

🖥️ Browser Compatibility

The box-shadow 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 box-shadow property is a powerful tool for web developers looking to add depth and dimension to web elements. By experimenting with different values for offsets, blur, spread, and color, you can create a variety of shadow effects to enhance the visual appeal of your web projects. Use this property to highlight important sections, create a sense of layering, or simply add a touch of elegance to your 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