EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

CSS Drop Shadow

By Priya PedamkarPriya Pedamkar

Home » Software Development » Software Development Tutorials » CSS Tutorial » CSS Drop Shadow

CSS-Drop-Shadow

Introduction to CSS Drop Shadow

CSS treats each element as a box. It provides various features to style each element. But as far as the rendering of the elements in a page and overall layout is concerned, the box-model is the most important feature that CSS offers. In addition to this, CSS offers another feature where, while treating the element as a box, we can give it a shadow effect. This feature is commonly called box-shadow, but can also be addressed as drop-shadow.

How to Create Drop-Shadow?

Syntax:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

The syntax  for a drop shadow or box-shadow is as follows:

box-shadow: horizontal-offset vertical-offset blur-radius spread-radius(option) color

Here, horizontal offset refers to the shadow towards left or right. If the value is positive, then the shadow will be towards the right and the shadow will be towards left for a negative value. Vertical offset refers to the top or bottom shadow. If the value is positive, the shadow will be at the bottom or below the box and in case of negative value the shadow will be on top or above the box. Blur decides the sharpness of the shadow. The higher the blur radius, the less sharp the shadow will appear. Spread-radius is an optional parameter which decides the size of the shadow. While a positive value means larger size, negative means vice versa. Colour is a parameter, which decides the color of the shadow.

box-shadow: none|inset|initial|inherit

Given above are some of the values that can be used with box-shadow property. None will give no shadow for the box. Inset will give an inner shadow instead of an outer shadow. This property is optional. initial will set all the values of the box-shadow property to the initial state. And finally, inheritance will take the property values of the parent element and use the same for styling the current element.

Examples of CSS Drop Shadow

Let us have a look at some of the examples to understand how drop-shadow property work in CSS:

Example #1

Demonstration of basic box-shadow property through external CSS.

  • We will be implementing this example through external CSS. So first and foremost, we will create a CSS file.
  • Since the box-shadow can be used as a part of box-model also, we will create a box-model style for the heading element <h2>. The code should be:

Code:

h2{
width: 500px;
font-size: 18px;
padding: 20px 50px;
border: 10px dotted pink;
margin: 10px 50px;
box-shadow: 5px 5px 10px purple;
background-color: lightcoral;
text-align: center;
}

Popular Course in this category
CSS Training (9 Courses, 9+ Projects)9 Online Courses | 9 Hands-on Projects | 61+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,429 ratings)
Course Price

View Course

Related Courses
Bootstrap Training (2 Courses, 6+ Projects)jQuery Training (8 Courses, 5 Projects)
  • Similarly, we will create another styling for the paragraph element <p>. the code should be as follows:

Code:

p{
height: 50px;
width: 300px;
padding: 10px;
border: 15px double lightskyblue;
margin: 10px 60px;
box-shadow: -10px 10px 15px 15px grey;
background-color: lightslategrey;
color: white;
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
}

  • The CSS file, after combining the above two snippets should look like this:

Code:

h2{
width: 500px;
font-size: 18px;
padding: 20px 50px;
border: 10px dotted pink;
margin: 10px 50px;
box-shadow: 5px 5px 10px purple;
background-color: lightcoral;
text-align: center;
}
p{
height: 50px;
width: 300px;
padding: 10px;
border: 15px double lightskyblue;
margin: 10px 60px;
box-shadow: -10px 10px 15px 15px grey;
background-color: lightslategrey;
color: white;
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
}

  • Next, we will create an HTML page. Since this is an external CSS, we will call the CSS file in the head section.
  • We will use both elements <h2> and <p>, such that we can see the final results of the styling.
  • The final HTML code should be similar to this:

Code:

<html>
<head>
<title>Testing Box Shadow</title>
<link rel = "stylesheet" href = "box.css">
</head>
<body>
<h2>This is test for box-shadow or drop-shadow</h2>
<p>This is the box model style testing for paragraph element</p>
</body>
</html>

  • Once this file is saved, it can be opened through a browser. The final result should be similar to the below image:

CSS Drop Shadow 1

Example #2

Demonstrating the ‘inset’ feature through External CSS.

  • By default, box-shadow will produce an outer shadow for the element. However, if one wants to display an inner shadow, the optional feature inset can be used.
  • Like the previous example, we will create a CSS file first.
  • We will style the paragraph element and make use of the inset feature to display an inner border.
  • The final CSS code should be similar to this snippet:

Code:

p{
height: 100px;
width: 400px;
padding: 15px;
border: 5px dotted lightskyblue;
margin: 20px 60px;
box-shadow: inset 10px 10px 15px 15px grey;
color: blue;
font-size: 20px;
font-family: fantasy;
}

  • Now that the CSS file is finalized, we will move on to code the HTML page. We will use paragraph element <p> so that we can see how the inset feature works for the box-shadow. The HTML code can be:

Code:

<html>
<head>
<title>Testing Box Shadow</title>
<link rel = "stylesheet" href = "box.css">
</head>
<body>
<p>This is the box shadow inset style testing for paragraph element</p>
<p>This is second test for the inset box-shadow</p>
</body>
</html>

  • Saving this HTML file and opening through any browser should give an output similar to this:

inset style testing

Example #3

Demonstrating drop-shadow through inline CSS.

  • Since we are using Inline CSS in this example, we can directly code the HTML page.
  • We will add the styling using the style parameter for the paragraph element <p>.
  • The HTML code should be as follows:

Code:

<html>
<head>
<title>Testing Drop Shadow</title>
</head>
<body>
<p style="height: 100px; width: 400px; box-shadow: 10px 10px 5px grey; border: 2px dotted lightblue;">Testing drop-shadow through inline CSS</p>
</body>
</html>

  • Save this HTML page and open through a browser to see the following output:

CSS Drop Shadow 3

The above example demonstrated the use of drop shadow. This is a feature that can be used to give a three-dimensional impact to an element. It can be tried with various combinations in the box-model or separately as well.

Recommended Articles

This is a guide to CSS Drop Shadow. Here we discuss a brief overview, how to create drop shadow with different examples along with its code implementation. You can also go through our other suggested articles to learn more –

  1. CSS Commands
  2. CSS Interview Questions
  3. CSS Inner Border
  4. CSS Lists

CSS Training (9 Courses, 9+ Projects)

9 Online Courses

9 Hands-on Projects

61+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
CSS Tutorial
  • CSS
    • Introduction To CSS
    • What is CSS?
    • Uses Of CSS
    • Advantages of CSS
    • Career In CSS
    • CSS Commands
    • Is Css Case Sensitive
    • CSS object-fit
    • Types of CSS Selectors
    • CSS Radio Button
    • CSS Attribute Selector
    • CSS first child of class
    • CSS Selector nth Child
    • CSS Parent Selector
    • CSS Child Selector
    • CSS Not Selector
    • CSS Descendant Selector
    • CSS Inline Style
    • Checkbox CSS
    • CSS Appearance
    • CSS Font Properties
    • CSS font-variant
    • CSS Pagination
    • CSS Table Styling
    • CSS Table Cell Padding
    • CSS Padding Color
    • CSS Text Formatting
    • CSS for Text-Shadow
    • CSS text-stroke
    • CSS text-indent
    • CSS Rotate Text
    • CSS Text Color
    • CSS Center Div
    • CSS Arrow
    • CSS Arrow Down
    • CSS offset
    • CSS Cursor
    • CSS Layout
    • CSS Grid Layout
    • Button in CSS
    • CSS Button Border
    • text-align in CSS
    • CSS Horizontal Align
    • CSS Position
    • CSS Box Sizing
    • CSS box-shadow
    • CSS Text Underline
    • CSS Text Outline
    • CSS Blinking Text
    • Text Decoration CSS
    • CSS Vertical Align
    • CSS Word Wrap
    • CSS Padding
    • CSS Font Color
    • CSS Color Generator
    • CSS Margin Right
    • CSS Margin Color
    • CSS Color Codes
    • CSS Color Transparent
    • CSS Color Chart
    • CSS Link Color
    • CSS z-index
    • CSS Curved Border
    • CSS Border Left
    • CSS left
    • CSS Gradient Generator
    • Radial Gradient in CSS
    • CSS Shape Generator
    • CSS Triangle Generator
    • CSS background-color
    • CSS Background Image
    • CSS background-clip
    • CSS background-blend-mode
    • CSS Drop Shadow
    • CSS line height
    • CSS line break
    • Sticky Footer CSS
    • CSS Header Design
    • CSS Border Style
    • CSS Border Generator
    • Sticky Sidebar CSS
    • CSS Transparent Border
    • CSS Border Radius
    • CSS translate
    • CSS transform
    • CSS 3D Transforms
    • CSS Text Transform
    • CSS Transition Effects
    • CSS Transition Property
    • CSS Animation Transition
    • Negative Margin CSS
    • CSS Navigation Bar
    • CSS Overflow
    • CSS overflow-wrap
    • CSS Lists
    • CSS list-style
    • CSS Order
    • CSS Box Model
    • CSS Inner Border
    • CSS Icon
    • Menu Icon CSS
    • CSS Multiple Borders
    • Opacity in CSS
    • CSS Float Right
    • CSS Clear Float
    • CSS clip
    • CSS disabled
    • CSS Border Padding
    • Border Images in CSS
    • CSS Visibility
    • CSS Validator
    • CSS Clearfix
    • CSS Counter
    • CSS Letter Spacing
    • CSS root
    • CSS zoom
    • CSS calc()
    • CSS.supports()
    • CSS Loader
    • Media Query CSS
    • CSS @keyframes
    • CSS @bottom
    • CSS page-break-after Property
    • CSS page-break
    • CSS Position Fixed
    • CSS skew()
    • CSS Row
    • CSS Masking
    • CSS Scrollbar
    • CSS Overlay
    • CSS Important
    • CSS Cursor Hand
    • CSS Inherit
    • CSS Position Relative
    • CSS Compressor
    • CSS tricks
    • CSS Outline Property
    • CSS Flexbox Properties
    • CSS flex-direction
    • CSS content property
    • CSS Typography
    • CSS Formatter
    • CSS nowrap
    • CSS Column
    • GridView CSS
    • CSS Viewport
    • CSS Minify
    • CSS Combinators
    • CSS in React
    • CSS Matrix 
    • CSS Pseudo Elements
    • CSS Pseudo Classes
    • CSS Pointer Events
    • CSS Resize
    • CSS Inheritance
    • CSS Interview Questions
    • Cheat Sheet CSS
  • CSS3
    • What is CSS3?
    • CSS3 Interview Questions
    • Cheat sheet CSS3
  • sass
    • How to Install SASS
    • SASS Interview Questions
    • What is Sass
    • SASS Comments
    • Sass Variables
    • SASS Import
    • SASS if else
    • SASS Nesting
    • SASS @each
    • SASS @at-root
    • SASS @extend
    • SASS @media
    • SASS @for
    • SASS Map
    • SASS Selectors
    • SASS Color Functions
    • SASS Mixins

Related Courses

CSS Training Course

Bootstrap Training Course

JQuery Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - CSS Training (9 Courses, 9+ Projects) Learn More