
- 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 - box-shadow Property
CSS box-shadow property adds a shadow effect around an element. One or more shadow effects can be added, separated by commas. The box shadow is described by horizontal and vertical offsets relative to the element, blur, spread radius and color.
Syntax
box-shadow: none | h-offset v-offset blur spread color | inset | initial | inherit;
Property Values
Value | Description |
---|---|
none | This value does not show any shadow. Default |
h-offset | It defines the horizontal offset. Positive values place the shadow to the right of box, negative values place the shadow to the left of box. Required. |
v-offset | It defines the vertical offset. Positive values place the shadow below the box, negative values place the shadow above the box. Required |
blur | It defines the blur radius. Higher values have higher blur. Optional. |
spread | It defines the spread radius. Positive values increases size of shadow, negative values decreases size of shadow. Optional |
color | It defines the color of the shadow. Different formats of color can be used. Default is color of text. Optional |
inset | It changes the outer shadow to inner shadow. |
initial | It sets the property to its default value. |
inherit | It inherits the property from the parent element. |
Examples of CSS Box Shadow Property
The following examples explain the box-shadow property with different values.
Box Shadow Property with Box Shadow
To set a shadow to a box, we require to specify atleast two values, one for the horizontal offset and the other for the vertical offset. Depending on the signs of the values, the position of the shadow changes accordingly. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { display: grid; justify-content: center; align-items: center; gap: 30px; } .boxes { padding: 50px; text-align: center; font-weight: bold; } .first { background-color: lightcoral; box-shadow: 10px 10px; } .second { background-color: lightblue; box-shadow: 10px -10px; } .third { background-color: lightgreen; box-shadow: -10px 10px; } .fourth { background-color: lightgrey; box-shadow: -10px -10px; } </style> </head> <body> <h2> CSS box-shadow property </h2> <p> Positive horizontal offset places the shadow to the right of box and negative horizotal offset places the shadow to the left of box. </p> <p> Positive vertical offset places the shadow below the box and negative values places it above the box. </p> <div class="container"> <p class="first boxes"> box-shadow: 10px 10px </p> <p class="second boxes"> box-shadow: 10px -10px </p> <p class="third boxes"> box-shadow: -10px 10px </p> <p class="fourth boxes"> box-shadow: -10px -10px </p> </div> </body> </html>
Box Shadow Property with Blur
To set a blur to the shadow of a box, we require to specify three values. The first two values are the horizontal and vertical offsets while the third value is for the blur, higher the third value greter will be the blur. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { display: grid; justify-content: center; align-items: center; gap: 30px; } .boxes { padding: 50px; text-align: center; font-weight: bold; } .first { background-color: lightcoral; box-shadow: 10px 10px 10px; } .second { background-color: lightcoral; box-shadow: 10px 10px 20px; } .third { background-color: lightcoral; box-shadow: 10px 10px 40px; } </style> </head> <body> <h2> CSS box-shadow property </h2> <p> The third value decides the blur, greater the value more is the blur. </p> <div class="container"> <p class="first boxes"> box-shadow: 10px 10px 10px </p> <p class="second boxes"> box-shadow: 10px -10px 20px </p> <p class="third boxes"> box-shadow: -10px 10px 40px </p> </div> </body> </html>
Box Shadow Property with Spread Value
To set the size of the shadow of a box, we require to specify four values. The first two values are the horizontal and vertical offsets while the third value is for the blur, the fourth value decides the size of the shadow, positive values result in larger shadows while negative values result in smaller shadows. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { display: grid; justify-content: center; align-items: center; gap: 30px; } .boxes { padding: 50px; text-align: center; font-weight: bold; } .first { background-color: lightblue; box-shadow: 10px 10px 10px 5px; } .second { background-color: lightblue; box-shadow: 10px 10px 20px 15px; } .third { background-color: lightblue; box-shadow: 10px 10px 40px -5px; } </style> </head> <body> <h2> CSS box-shadow property </h2> <p> The fourth value decides the size of the shadow, positive value results in larger shadow while negative value results in smaller shadow. </p> <div class="container"> <p class="first boxes"> box-shadow: 10px 10px 10px 5px </p> <p class="second boxes"> box-shadow: 10px -10px 20px 14px </p> <p class="third boxes"> box-shadow: -10px 10px 40px -5px </p> </div> </body> </html>
Box Shadow Property with Color Value
To set a color to the shadow of a box, we require to specify atleast three values. The first two values are the horizontal and vertical offsets while the third value is for the color, the color can be specified along with blur and spread as well. The color can be specified in different format (eg. color names, hexadecimal values, rgb values etc.). This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { display: grid; justify-content: center; align-items: center; gap: 30px; } .boxes { padding: 50px; text-align: center; font-weight: bold; } .first { background-color: lightcoral; box-shadow: 10px -10px grey; } .second { background-color: lightcoral; box-shadow: 10px 10px 20px rgb(51, 204, 0); } .third { background-color: lightcoral; box-shadow: 10px 10px 40px -5px hsl(225, 100%, 50%); } </style> </head> <body> <h2> CSS box-shadow property </h2> <p> The color can be specified as third parameter, fourth parameter of even fifth parameter. The specified color will be applied to the shadow. </p> <div class="container"> <p class="first boxes"> box-shadow: 10px -10px grey </p> <p class="second boxes"> box-shadow: 10px 10px 20px rgb(51, 204, 0) </p> <p class="third boxes"> box-shadow: 10px 10px 40px -5px hsl(225, 100%, 50%) </p> </div> </body> </html>
Box Shadow Property with Inset Value
To let the box shadow appear inside the element and not outside the element, we use the inset value. This is shown in the following example
Example
<!DOCTYPE html> <html> <head> <style> .container { display: grid; justify-content: center; align-items: center; gap: 30px; } .boxes { padding: 50px; text-align: center; font-weight: bold; } .first { background-color: lightgreen; box-shadow: 10px -10px red inset; } .second { background-color: lightgreen; box-shadow: 10px 10px 20px rgb(51, 204, 0) inset; } </style> </head> <body> <h2> CSS box-shadow property </h2> <p> The inset value places the shadow within the elment. </p> <div class="container"> <p class="first boxes"> box-shadow: 10px -10px red inset </p> <p class="second boxes"> box-shadow: 10px 10px 20px rgb(51, 204, 0) inset </p> </div> </body> </html>
Box Shadow Property with Multiple Shadows
To have multiple shadows for a box, each style must be comma separated. The shadows will appear in the order specified in box-shadow property. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { display: grid; justify-content: center; align-items: center; gap: 30px; } .boxes { padding: 50px; text-align: center; font-weight: bold; } .first { background-color: lightcoral; box-shadow: 10px -10px grey, 15px -15px black, 20px -20px brown; } .second { background-color: lightgreen; box-shadow: 5px 5px red, 10px 10px blue, 15px 15px green; } </style> </head> <body> <h2> CSS box-shadow property </h2> <p> Number of shadows can be altered by specifying the different styles and separating them by commas. </p> <div class="container"> <p class="first boxes"> box-shadow: multiple shadows </p> <p class="second boxes"> box-shadow: multiple shadows </p> </div> </body> </html>
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
box-shadow | 10.0 | 9.0 | 4.0 | 5.1 | 10.5 |