CSS

CSS Overview Selectors Declarations Rule Sets Comments Reset/Normalize Origin Importance Order Specificity Inheritance Cascade Layers Inline Styles Internal Styles External Styles @import Absolute Units Relative Units Dynamic Viewport Angle Units Time Units Frequency Units: Resolution Units Keywords Color Formats Color Functions & Spaces Background Color Background Image Background Repeat Background Position Background Size Background Attachment Background Shorthand Multiple Backgrounds Linear Gradients Radial Gradients Conic Gradients Font Family Font Size Font Weight Font Style Line Height Text Align Text Decoration Text Transform Letter Spacing Word Spacing Text Shadow Text Wrap Variable Fonts Content Box Padding Box Border Box Margin Box Box Sizing Property Margin Padding Border Outline Box Shadow Block Display Inline Display Inline Block Display Static Position Relative Position Absolute Position Fixed Position Sticky Position Top Element Position Right Element Position Bottom Element Position Left Element Position Z Index Flexbox Box Layout Display Flex Flex Direction Flex Wrap Justify Content Align Items Align Content Gap, Row Gap & Column Gap Flex Grow Flex Shrink Flex Basis Flex Shorthand Order Property Align Self Practical Applications CSS Grid Layout Grid Display Grid Template Columns Grid Template Rows Grid Template Areas Justify Items Grid Auto Columns Justify Self Nested Grids Responsive Web Design Min Width Max Width Orientation Logical Operators Pointer Hover Prefers Color Scheme Fluid Images Flexible Typography Viewport Width Advanced CSS Features Defining variables Using variables Scope & Inheritance of CSS Variables Property Value Fallback Practical Applications :Hover :Active :Focus :Focus Visible :Visited :Link :First Child :Last Child :Nth Child :Nth of Type :Empty :Checked :Disabled :Enabled :Valid :Invalid :Required :Has :Not :Is :Where ::Before Pseudo Element ::After Pseudo Element ::First Letter ::First Line ::Selection ::Marker CSS 2D Transformations CSS 3D Transformations Transform Origin Transform Style Backface Visibility Transition Property Transition Duration Transition Timing Function Transition Delay Transition Shorthand Ease Timing Function Linear Timing Function Ease In Timing Function Ease Out Timing Function Ease In Out Timing Function Cubic Bezier Function Animations (@keyframes) Defining @keyframes Animation Name CSS Animation Duration Animation Timing Function CSS Animation Delay CSS Animation Iteration Count Animations Direction CSS Animation Fill Mode CSS Animation Play State CSS Filter Blur CSS Filter Brightness CSS Filter Contrast() CSS Drop Shadow CSS Grayscale CSS Hue Rotate CSS Invert CSS Opacity CSS Saturate CSS Sepia Mix Blend Mode Background Blend Mode Object Fit & Object Position Scroll Snap Type Scroll Snap Align Scroll Padding Scroll Margin Scroll Triggered Animations JS Variables

Box Shadow


The box-shadow property adds shadow effects around an element's frame. You can set multiple effects separated by commas. A box shadow is described by X and Y offsets relative to the element, blur and spread radius, and color.


Example 1: Basic Box Shadow

.basic-shadow {
  /* Applies a black shadow offset by 5px horizontally and vertically, with a 10px blur */
  box-shadow: 5px 5px 10px black;
  width: 150px;
  height: 100px;
  background-color: #f0f0f0;
}

Explanation: This code adds a simple shadow to a div. The first two values set the horizontal and vertical offsets, and the third value defines the blur radius, creating a soft, diffused shadow.


Example 2: Inset Shadow

.inset-shadow {
  /* Creates an inner shadow with a gray color, giving a pressed-in look */
  box-shadow: inset 0 0 10px #888888;
  width: 150px;
  height: 100px;
  background-color: #f0f0f0;
}

Explanation: The inset keyword changes the shadow from an outer shadow to an inner one. This makes the shadow appear inside the element's border, giving it a sunken appearance.


Example 3: Multiple Shadows

.multiple-shadows {
  /* Layering two shadows: a red one on top and a blue one underneath */
  box-shadow: 5px 5px 10px red, -5px -5px 10px blue;
  width: 150px;
  height: 100px;
  background-color: #f0f0f0;
}

Explanation: You can apply multiple shadows to a single element by separating each shadow's values with a comma. The first shadow in the list appears on top.


Example 4: Shadow with Spread Radius

.spread-shadow {
  /* A shadow with a 5px spread radius, making the shadow larger */
  box-shadow: 0 0 10px 5px #666;
  width: 150px;
  height: 100px;
  background-color: #f0f0f0;
}

Explanation: The fourth value in box-shadow is the spread radius. A positive value expands the shadow, making it larger than the element itself.


Example 5: Neumorphic Shadow Effect

.neumorphic-shadow {
  /* Creates a soft, extruded look with two shadows on opposite corners */
  box-shadow: 5px 5px 10px #bebebe, -5px -5px 10px #ffffff;
  width: 150px;
  height: 100px;
  background-color: #e0e0e0;
  border-radius: 10px;
}

Explanation: Neumorphism uses a light and a dark shadow to create a soft, UI look. The key is to have the background color sit between the two shadow colors.


Example 6: Shadow on a Pseudo-element

.pseudo-element-shadow::before {
  /* Adds a shadow to a pseudo-element for a subtle lifting effect */
  content: "";
  position: absolute;
  top: 50%;
  left: 5%;
  width: 90%;
  height: 20px;
  box-shadow: 0 15px 10px rgba(0, 0, 0, 0.4);
  z-index: -1;
  transform: rotate(-3deg);
}

Explanation: This code applies a box-shadow to a ::before pseudo-element. This technique is useful for creating more complex, non-rectangular shadow shapes.


Example 7: Glowing Effect Shadow

.glowing-shadow {
  /* Creates a vibrant blue glow around the element */
  box-shadow: 0 0 20px 5px #00aaff;
  width: 150px;
  height: 100px;
  background-color: #333;
  border-radius: 5px;
}

Explanation: By using a bright color for the shadow and a generous blur and spread radius, you can create a glowing effect. This is often used on dark backgrounds to make elements pop.