Shadows & Border Effects
Box-shadow, border-radius โ add depth and polish to any element. Shadows make UI feel 3D and professional.
The box-shadow property adds shadows to elements. It's one of the most effective ways to add depth and visual hierarchy to your designs.
/* Syntax: offset-x offset-y blur-radius spread-radius color inset */
.card {
box-shadow: 2px 4px 8px rgba(0, 0, 0, 0.15);
}
offset-xHorizontal shadow position. Negative = left.offset-yVertical shadow position. Negative = up.blur-radiusHow blurry the shadow is. Higher = softer.spread-radiusHow large the shadow is. Positive = larger.colorShadow color. Use rgba/hsla for transparency.insetMakes shadow go inside the element instead of outside.Box-shadow has five parameters that give you precise control:
/* Basic shadow โ subtle depth */
.card { box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
/* Large blur โ soft, spread out */
.card { box-shadow: 0 10px 30px rgba(0,0,0,0.15); }
/* Spread radius โ extends shadow edge */
.card { box-shadow: 0 4px 6px 2px rgba(0,0,0,0.1); }
/* Inset shadow โ shadow inside element */
.card { box-shadow: inset 0 2px 4px rgba(0,0,0,0.1); }
/* Multiple shadows โ comma separated */
.card { box-shadow: 0 4px 6px rgba(0,0,0,0.1), 0 10px 20px rgba(0,0,0,0.05); }
/* No offset โ even glow */
.glow { box-shadow: 0 0 20px rgba(249,115,22,0.4); }The border-radius property rounds the corners of elements. It's the simplest way to make UI feel softer and more modern.
/* All corners same */
.box { border-radius: 8px; }
/* Individual corners */
.box { border-top-left-radius: 8px; border-top-right-radius: 4px; border-bottom-right-radius: 8px; border-bottom-left-radius: 4px; }
/* Shorthand: top-left top-right bottom-right bottom-left */
.box { border-radius: 10px 20px 30px 40px; }
/* Circle โ use 50% on a square */
.circle { border-radius: 50%; width: 100px; height: 100px; }
/* Pill shape */
.pill { border-radius: 9999px; padding: 8px 24px; }
/* Only top corners */
.box { border-radius: 12px 12px 0 0; }Real-world patterns combining shadows and border-radius:
/* Card with subtle shadow */
.card { background: white; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.05), 0 10px 20px rgba(0,0,0,0.1); }
/* Floating button */
.btn-float { box-shadow: 0 6px 12px rgba(0,0,0,0.15); border-radius: 50%; }
/* Image with hover shadow */
.img:hover { box-shadow: 0 10px 20px rgba(0,0,0,0.2); }
/* Avatar circle */
.avatar { border-radius: 50%; width: 48px; height: 48px; object-fit: cover; }Practice shadows and border-radius below.
Try these experiments:
Done โ Key Points:
- โ
box-shadow: offset-x offset-y blur spread colorโ 5 parameters for precise control. - โ
border-radiusrounds corners.50%makes a circle,9999pxmakes a pill. - โ
Use
rgba()for shadow colors โ transparency makes shadows look natural. - โ Multiple shadows can be applied by comma-separating them.
- โ
insetcreates an inner shadow. Useful for pressed/sunken effects.
Want to track your progress?
Log in to save your place and pick up where you left off.
Progress track karna chahte ho?
Login karo apni progress save karne ke liye aur jahan chhoda tha wahan se shuru karo.
Login