How to Build Pure CSS Corner Ribbons & 3D Folded Badges
Pure CSS corner ribbons are constructed by wrapping an angled badge inside a square parent with position: absolute; overflow: hidden; pinned to the top-right corner. The ribbon badge is rotated at transform: rotate(45deg), while 3D wrap-around folds are created using triangular CSS borders on ::before and ::after pseudo-elements colored in darker shadow tones.
Step 1: The Geometric Blueprint: Parent Clipping & 45-Degree Rotation
Set the card container (or a corner wrapper box) to position: relative; overflow: hidden;. Position the ribbon strip with transform: rotate(45deg) so its ends are clipped neatly by the parent boundaries.
<div class="card-container">
<div class="corner-ribbon">POPULAR</div>
<h3>Developer Pro Plan</h3>
<p>$29 / month</p>
</div>
<style>
.card-container {
position: relative;
overflow: hidden;
border-radius: 12px;
}
.corner-ribbon {
position: absolute;
top: 18px;
right: -32px;
transform: rotate(45deg);
width: 120px;
background: var(--accent);
color: #fff;
text-align: center;
font-size: 11px;
font-weight: 800;
padding: 5px 0;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}
</style>
Step 2: Creating 3D Folded Shadows with CSS Border Triangles
To make ribbons appear as though they wrap around the edges of a physical card, generate dark folded shadow triangles on ::before and ::after pseudo-elements using zero-width border tricks.
/* 3D Fold Underneath Left Edge */
.corner-ribbon::before {
content: '';
position: absolute;
left: 0;
bottom: -6px;
border-top: 6px solid #b91c1c; /* Darker red shade */
border-left: 6px solid transparent;
}
/* 3D Fold Underneath Right Edge */
.corner-ribbon::after {
content: '';
position: absolute;
right: 0;
bottom: -6px;
border-top: 6px solid #b91c1c;
border-right: 6px solid transparent;
}
Step 3: Hanging Bookmark Badges with clip-path: polygon()
Another classic e-commerce variation is the vertical hanging bookmark ribbon. Use modern CSS clip-path: polygon() to cut a triangular swallowtail notch at the bottom.
.hanging-ribbon {
position: absolute;
top: 0;
left: 20px;
width: 36px;
height: 52px;
background: #f59e0b;
color: #000;
font-weight: 800;
font-size: 11px;
display: flex;
align-items: center;
justify-content: center;
/* Swallowtail inverted triangle notch */
clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%);
}
Step 4: Hover Scale & Accessibility Considerations
Ensure the ribbon does not obscure crucial card headings or buttons. Add pointer-events: none so user clicks reach links beneath the angled banner, and preserve heading text for screen readers.
.corner-ribbon {
pointer-events: none; /* Allows clicks to pass through */
user-select: none;
}
Next-Level Addons: Elevating Your Implementation
Take this technique further by combining it with complementary design token studios and animation tools:
A trick I use in almost every project: don't fight specificity battles with !important. Leverage modern CSS cascade layers (@layer) and CSS variables as design tokens—it makes dark/light theme switching and responsive tuning effortless.
Frequently Asked Questions
Practical answers to common implementation questions, browser quirks, and performance tips.
Why do pure CSS corner ribbons require a fixed width?
Because rotating an element with variable text length makes it difficult to align edges against the 45-degree corner. Setting a standard width (e.g. `120px` to `150px`) ensures consistent geometric placement across all cards.
How does overflow: hidden clip the ribbon edges?
The ribbon strip is wider than the corner itself. When placed inside a container with `overflow: hidden`, the browser cleanly crops off the extra ends that extend beyond the card's top and right borders.
Can I put corner ribbons on the top-left or bottom corners?
Yes! For top-left, set `top: 18px; left: -32px; transform: rotate(-45deg);`. For bottom-right, set `bottom: 18px; right: -32px; transform: rotate(-45deg);`.
Why should corner ribbons have pointer-events: none?
Because the rotated ribbon block occupies invisible bounding box space that can overlap cards, buttons, or links, blocking user clicks. Adding `pointer-events: none` lets clicks pass right through.
How do I create a ribbon with custom brand colors without hardcoding fold shadows?
Use modern CSS `color-mix()`: define `--ribbon-bg: #ef4444` and set `--fold-shadow: color-mix(in srgb, var(--ribbon-bg) 70%, black);` for the triangular fold borders.