Make Your Component Realistic
with One Utility Class
with One Utility Class
Make Your
Component Realistic
with One Utility Class
Component Realistic
with One Utility Class
How to use
In the remainder of this page I provide some tailwind custom utility classes that give your components realistic shadows.
To use them, you should make some changes to your tailwind css file.
- Add two color variables to your tailwind css file.
@import tailwindcss; ... + :root { + ... + --realistic-light: #ffffff80; /* for light mode */ + /* --realistic-light: #ffffff40; /* recommended for dark mode */ */ + --realistic-shadow: #00000030; /* recommended for light mode */ + /* --realistic-shadow: #ffffff80; /* recommended for dark mode */ */ + } - Copy and paste the utility class into your tailwind css file
@import tailwindcss; ... :root { ... } + @utility shadow-realistic-button { ... } + @utility shadow-realistic-button { + box-shadow: + inset 0px -2px 2px var(--realistic-shadow), + inset 0px 2px 2px var(--realistic-light), + 0px 2px 5px var(--realistic-shadow), + -0px -1px 1px var(--realistic-shadow); + } - Use the utility class to your components.
- Adjust the colors of the shadows to match the colors of your components. (optional)
<Button className="shadow-realistic-button">Click me</button>Tips
- Though the shadow colors I provided above suits most components, it looks even better if you adjust the colors of the shadows to match the colors of your components.
- The background color should not be too dark or too light so that both lighter and darker shadows are visible.
Button
Looks like a protrusion coming out of a hole.
@utility shadow-realistic-button {
box-shadow:
inset 0px -2px 2px var(--realistic-shadow),
inset 0px 2px 2px var(--realistic-light),
0px 2px 5px var(--realistic-shadow),
-0px -1px 1px var(--realistic-shadow);
}Examples
Button Pressed
Looks like a recessed button
@utility shadow-realistic-button-pressed {
box-shadow:
-0px -1px 1px var(--realistic-shadow),
0px 1px 1px var(--realistic-light);
}Examples
Box
Looks like a thin box with rounded edges placed on a flat surface
@utility shadow-realistic-box {
box-shadow:
inset 0px -2px 2px var(--realistic-shadow),
inset 0px 2px 2px var(--realistic-light),
0px 2px 5px var(--realistic-shadow);
}Examples
← the thumb is styled with this utility
Hole
Looks like a hole with rounded edges
@utility shadow-realistic-hole {
box-shadow:
0px 1px 1px var(--realistic-light),
-0px -1px 1px var(--realistic-shadow),
inset 0px 1px 1px var(--realistic-shadow);
}Examples
← the thumb is styled with this utility
Edge
Looks like a thin card with rounded edges placed on a flat surface
@utility shadow-realistic-edge {
box-shadow:
inset 0px 1px 1px var(--realistic-light),
inset -0px -1px 1px var(--realistic-shadow),
0px 1px 1px var(--realistic-shadow);
}Examples
This is a component with an edge
Edge Float
Looks like a floating thin card with rounded edges
@utility shadow-realistic-edge-float {
box-shadow:
inset 0px 1px 1px var(--realistic-light),
inset -0px -1px 1px var(--realistic-shadow),
0px 20px 20px -10px var(--realistic-shadow);
}Examples
Edge Float
This is a component with an edge
Depression
Looks like a hole with smooth edges
@utility shadow-realistic-depression {
box-shadow:
inset 0px -2px 2px var(--realistic-light),
inset -0px 2px 2px var(--realistic-shadow);
}Examples
Mound
Looks like a mound with smooth edges
@utility shadow-realistic-mound {
box-shadow:
0px -4px 4px var(--realistic-shadow),
0px 4px 4px var(--realistic-light);
}Examples
Apply depression to parent and apply mound to its child to create a gutter