How to Use CSS Shadow Offset Values for Design Hierarchy
Shadow offset is one of the most powerful tools for creating visual hierarchy in web design. While blur and opacity control shadow softness, the X and Y offset values determine where the shadow appears relative to your element. Getting these right makes the difference between a card that looks like it's floating and one that looks like it's sitting flat on the page.
Understanding shadow offset is especially useful because it's the first thing you notice about a shadow. A strong Y offset immediately signals depth. A balanced X and Y offset creates directional light. An offset of zero creates a halo effect. Each approach serves a different purpose in your design system.
What Are X and Y Offsets in Box Shadow?
The CSS box-shadow property starts with two offset values:
box-shadow: X-offset Y-offset blur spread color;
The X offset moves the shadow horizontally. Positive values push it right, negative values push it left. The Y offset moves it vertically. Positive values move it down, negative values move it up.
Most UI shadows use a Y offset greater than the X offset because natural light typically comes from above, not from the side. A shadow that only goes down feels realistic. A shadow that goes significantly to one side looks artificial unless you're creating a specific directional light effect.
For example, box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.15) has zero X offset and a positive 4px Y offset. This creates a subtle shadow directly beneath the element, making it feel slightly lifted from the page.
How Offset Values Create Perceived Elevation
Offset is what makes an element feel elevated. Zero offset creates a glow around the element—it sits right on the surface. Small positive offsets (2px to 8px) make elements feel subtly above the page. Large offsets (16px to 32px) make elements feel distinctly floating.
Think about a card on a dashboard. If you use box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.10), the card looks like it's sitting flush against the background with a soft halo around it. The user doesn't perceive strong elevation.
But if you use box-shadow: 0px 8px 20px rgba(0, 0, 0, 0.15), the shadow falls clearly beneath the card. The Y offset of 8px tells the eye that the card is floating above the page. This is much more effective for creating visual hierarchy.
The relationship between offset and blur matters too. A large blur with no offset looks soft and ethereal. A small blur with a large offset looks sharp and dramatic. A balanced approach—medium offset with medium-to-high blur—works well for most modern UI.
X Offset: When and Why to Use It
Most UI shadows should use an X offset close to zero. Light rarely comes strongly from the side in interface design. A shadow with a heavy X offset looks unnatural unless you're intentionally creating a special effect.
However, there are legitimate uses for X offset:
Angled light effects
If your design has a specific light source direction (like a top-left light source), you might use a small X offset along with the Y offset.
box-shadow: 4px 8px 20px rgba(0, 0, 0, 0.12);
This creates a shadow that falls both downward and to the right, as if light comes from the upper left. Use this sparingly—most modern interfaces don't signal a specific light direction.
Directional accents
Some cards or buttons have a small offset to one side to create visual movement. This is more design-conscious than realistic.
box-shadow: 6px 0px 16px rgba(0, 0, 0, 0.10);
A purely horizontal offset signals movement or attention. Use this for hover states, featured cards, or playful interfaces.
Layered shadows
When using multiple shadows, you might offset them differently to create a complex, natural-looking shadow structure.
box-shadow:
2px 4px 8px rgba(0, 0, 0, 0.08),
0px 12px 24px rgba(0, 0, 0, 0.12);
The first shadow has slight X and Y offset for close contact. The second has only Y offset for the overall shadow drop.
For most work, keep X offset at zero or very small (0px to 2px). Your shadows will feel more professional and your interface more cohesive.
Y Offset: The Key to Vertical Hierarchy
Y offset is the most important offset value for UI design. It directly controls how much the shadow falls away from the element, which controls how elevated the element feels.
Subtle elevation (2px to 4px Y offset)
Use small Y offsets for elements that need minimal visual separation from the background, such as cards in a dense list or dashboard panels.
box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.08);
This shadow barely registers. It's just enough to separate the element from the background without creating strong depth. Paired with a light background color or subtle border, this works well for restrained, clean interfaces.
Medium elevation (8px to 12px Y offset)
Most cards and panels should use this range. The shadow is visible without being dramatic. Users immediately understand that the card is above the background.
box-shadow: 0px 8px 20px rgba(0, 0, 0, 0.12);
This is the sweet spot for feature cards, content blocks, and primary UI components. It creates clear elevation without looking overwhelming.
Strong elevation (16px to 24px Y offset)
Modals, dialogs, and important overlays should use larger Y offsets. The shadow clearly indicates that the element is above the rest of the page and demands attention.
box-shadow: 0px 20px 40px rgba(0, 0, 0, 0.20);
This is dramatic. The element clearly floats above everything else. Use it for modals, dropdown menus over important content, and command palettes.
Maximum elevation (32px+ Y offset)
Very rarely, you might use extreme Y offsets for special effects or full-screen overlays.
box-shadow: 0px 40px 80px rgba(0, 0, 0, 0.25);
This makes the element feel very far from the background. It's useful for hero overlays or dramatic UI moments, but overuse will make your interface feel cluttered.
Using Offset to Create Visual Hierarchy
The best reason to understand shadow offset is to build consistent visual hierarchy. Different elements need different elevations to signal their importance and role.
A simple elevation system
Create a consistent system with 3 to 4 elevation levels. Use offsets to distinguish them:
Level 1 – Subtle contact shadow `css box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.08); ` Use for disabled elements, inactive tabs, subtle cards, and elements at rest.
Level 2 – Standard cards `css box-shadow: 0px 8px 16px rgba(0, 0, 0, 0.12); ` Use for standard cards, panels, and interactive elements in default state.
Level 3 – Elevated interaction `css box-shadow: 0px 12px 24px rgba(0, 0, 0, 0.16); ` Use for hovered cards, hover states on buttons, and temporarily elevated elements.
Level 4 – Modals and overlays `css box-shadow: 0px 24px 48px rgba(0, 0, 0, 0.20); ` Use for modals, dialogs, dropdowns over important content, and full-screen overlays.
This creates a clear visual language. Users understand at a glance what elements are interactive, what's important, and what's temporary or secondary.
Testing Offset Values with the Shadow Generator
The shadow-generator tool makes it easy to experiment with X and Y offsets. Adjust the X offset slider and watch how the shadow moves horizontally. Then adjust the Y offset and see how the vertical positioning changes the perceived depth.
The preview shows your element against your background color, so you can see exactly how the shadow interacts with the actual surface. A shadow that looks good on white may be invisible on light grey. The preview prevents surprises.
Start with Y offset close to zero and increase it slowly. You'll see the element "lift" off the page as the offset grows. Once you find the elevation level that feels right, you can fine-tune blur and opacity.
Common Offset Mistakes to Avoid
Offset without blur
A large offset with minimal blur looks harsh and unnatural. Always pair offset with adequate blur.
/* Wrong – sharp and harsh */
box-shadow: 0px 12px 2px rgba(0, 0, 0, 0.20);
/* Right – soft and natural */
box-shadow: 0px 12px 24px rgba(0, 0, 0, 0.15);
Asymmetrical X and Y offsets
Unless you're intentionally creating directional light, keep X offset zero or very small. A shadow that goes equally down and to the side looks unintentional.
Offset inconsistency
If some cards use 4px Y offset, others use 12px, and modals use 8px, the hierarchy breaks down. Stick to your elevation system.
Offset without context
Test the shadow on the actual background and against actual content. A shadow that looks great on white might not work on your light grey background.
Trying to create shadow hierarchy without offset
If your shadows all use zero offset, you can't create elevation. You can adjust blur and opacity, but the effect will be limited. Offset is essential for perceiving depth.
Offset Values by Component Type
Different UI components need different offsets based on their role:
Cards and panels
box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.10);
Small Y offset for subtle elevation. Cards are content containers, not overlays.
Buttons (hover state)
box-shadow: 0px 6px 16px rgba(0, 0, 0, 0.12);
Medium Y offset to show the button is being interacted with. The shadow changes to signal responsiveness.
Dropdowns and menus
box-shadow: 0px 8px 20px rgba(0, 0, 0, 0.14);
Medium Y offset. Dropdowns need to feel above their surroundings but not as dramatic as modals.
Modals and dialogs
box-shadow: 0px 20px 48px rgba(0, 0, 0, 0.18);
Large Y offset. Modals demand attention and should feel distinctly above the page.
Floating action buttons
box-shadow: 0px 6px 20px rgba(0, 0, 0, 0.16);
Medium-to-large Y offset. FABs should feel floating and clickable.
Sticky headers
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.08);
Small Y offset. Headers need minimal shadow to avoid blocking content, but just enough to show they're sticky.
Advanced: Combining Offsets with Blur and Opacity
The best shadows use all three properties together. Offset creates the elevation, blur creates softness, and opacity controls intensity.
A small offset with high opacity looks harsh. Increase blur to soften it.
/* Too harsh */
box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.30);
/* Better – same offset, more blur, less opacity */
box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.12);
A large offset with low blur looks unnatural. Increase blur to match the offset distance.
/* Unnatural – large offset but sharp edge */
box-shadow: 0px 24px 4px rgba(0, 0, 0, 0.15);
/* Natural – offset matched with blur */
box-shadow: 0px 24px 32px rgba(0, 0, 0, 0.15);
The general rule: larger offsets need larger blur values. Small offsets work with small-to-medium blur. This mimics how real shadows work—a shadow close to an object is sharp, but a shadow far away is diffused.
Offset Strategy for Your Design System
Build your shadow system around your offset values first. Decide on 3 to 4 elevation levels based on Y offset. Document them:
- Level 1: 2px Y offset for subtle elements
- Level 2: 8px Y offset for standard cards
- Level 3: 12px Y offset for hovered or interactive states
- Level 4: 20px Y offset for modals and overlays
Then use the shadow-generator to fine-tune blur and opacity for each level, keeping the offsets consistent.
This approach saves time, creates visual consistency, and makes your design system feel intentional. New team members can apply shadows confidently by following your documented offset values.
Shadow offset is one of the most overlooked aspects of shadow design, but it's the foundation of depth and hierarchy. Master these values, and your UI will immediately feel more polished and organized.

