CSS Ribbon Generator
Generate a diagonal corner ribbon for a card using one pseudo-element and a rotation, with the text in a data attribute and nothing to download.
Loading tool…
The CSS is generated by JavaScript in your browser and never leaves the page. There is nothing to upload and nothing is stored.
What the CSS Ribbon Generator does
The CSS ribbon generator on this page will generate a diagonal corner ribbon for a card using one pseudo-element and a rotation, with the text in a data attribute and nothing to download. Everything runs inside this page, so the work happens on your own device rather than on a server. It is most often used for a "new", "sale" or "beta" flag on a product or feature card. If you want to cross-check the result, there is another CSS ribbon generator on FreeToolsWorld.org.
How to use it
- Pick the corner the ribbon should sit on.
- Type the ribbon text and choose the colours.
- Adjust the band width and its distance from the corner until the ends disappear cleanly.
- Copy the rules, add class="ribbon-card" to the card and data-ribbon="NEW" for the text.
How it works
A corner ribbon is one pseudo-element, rotated 45 degrees and positioned so that it crosses the corner, with the card clipping whatever hangs over. The clipping is the whole effect: the band is deliberately wider than the corner it crosses, and overflow: hidden on the card is what makes its ends vanish into the edges instead of sticking out as two stubs. Take the overflow away and the illusion disappears immediately — which is a quick way to see what the rule is actually doing.
The rotation direction is the detail that is easy to get wrong. A ribbon on the top-right or bottom-left corner rotates +45 degrees; on the top-left or bottom-right it rotates −45. Rotate the wrong way and the band runs across the corner in the wrong diagonal, so it is parallel to the edge it should be cutting. The four options here set it correctly for each corner, and the offset moves the band along the diagonal towards or away from the point.
Band width and offset interact, and the relationship is not obvious. Making the band wider pushes more of it beyond the card on both sides, which is fine — it is clipped — but it also means the visible middle section is longer, so the text sits in more space. Moving the band closer to the corner shortens the diagonal it has to cross, so a wide band at a small offset will have its ends cut off abruptly rather than tapering into the edges. The generator flags a band narrow enough to leave a gap at one end.
The text comes from a data-ribbon attribute via content: attr(), for the same reason the tooltip does: a string in the markup can be translated and edited, and one buried in a stylesheet cannot. It is still generated content, which means a screen reader may well skip it — so a ribbon saying "SOLD OUT" should not be the only place that information appears. Put it in the card text too, and let the ribbon be the visual emphasis rather than the only source.
pointer-events: none is on the pseudo-element deliberately. A ribbon across the corner of a card sits on top of whatever is underneath it, and without that declaration it will swallow clicks on a link or a button in that corner. It is one line and it prevents a bug that is genuinely hard to track down, because the element you are clicking looks perfectly normal in the inspector.
When to use it
- A "new", "sale" or "beta" flag on a product or feature card.
- Marking one plan in a pricing grid as recommended.
- A status band on a dashboard tile.
- Flagging a sold-out or unavailable item.
- Any corner badge where an image would be more weight than the decoration deserves.
Common mistakes to avoid
- Leaving overflow: hidden off the card, so the band’s ends stick out past the corners.
- Rotating the wrong way for the corner, which runs the band parallel to the edge instead of across it.
- Forgetting pointer-events: none, so the ribbon swallows clicks on anything beneath it.
- Using a band too narrow to reach both edges, which leaves a visible gap at one end.
- Relying on the ribbon alone to convey something important, since generated content may not be announced.
- Putting the text in the stylesheet rather than a data attribute, which makes it untranslatable.
Frequently asked questions
How does a CSS corner ribbon work?
A pseudo-element is rotated 45 degrees and positioned across the corner of the card, and the card clips it with overflow: hidden. The band is wider than the corner, so its ends run off the card and are hidden, which is what makes it look like a ribbon rather than a floating bar.
Which way should the ribbon rotate?
Plus 45 degrees on the top-right and bottom-left corners, minus 45 on the top-left and bottom-right. Rotating the wrong way puts the band parallel to the nearest edge instead of diagonally across the corner.
Why are the ends of my ribbon sticking out?
The card is missing overflow: hidden. The band is intentionally wider than the corner it crosses, and clipping is what hides the excess. Without it you see the full rotated rectangle.
Why can I not click the link under the ribbon?
Because the pseudo-element is on top of it and is intercepting the click. Add pointer-events: none to the ribbon, which makes it visual only and lets clicks pass through to whatever is beneath.
Can I put the ribbon text in the CSS?
You can, with content: "NEW", but it is better in a data attribute. Text in a stylesheet cannot be translated, is invisible to anyone editing the content, and means a separate CSS rule for every different label.
Will a screen reader read the ribbon?
Possibly not. CSS-generated content is treated as decorative by many assistive technologies. If the ribbon conveys something that matters — sold out, unavailable, recommended — make sure it also appears in the card’s real text.