Favorites

How to Create a Corner Ribbon

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

What is a corner ribbon?

A corner ribbon is a diagonal banner that wraps around the corner of a card or box, like a sash on a gift. It's a classic way to make something stand out, such as a "Popular" pricing plan, a "New" product or a "Sale" item.

In this tutorial we'll build one using pure CSS, with no images. Along the way we'll use the position, transform and box-shadow properties. If you'd rather design one visually, try our CSS Ribbon Generator.

Here's what we'll build:

Results
Popular
Pro plan$12 per month
Sale
Desk lampNow $39
New
Version 2.0Just released

Step 1: the HTML

The ribbon sits inside the box it decorates. We'll call that box a card:

<div class="card">
  <div class="ribbon"><span>Popular</span></div>
  <h3>Pro plan</h3>
  <p>$12 per month</p>
</div>

There are two parts to the ribbon: an outer .ribbon element that acts as a frame, and an inner <span> that becomes the diagonal band with the text on it. You'll see why we need both in the next step.

The card itself only needs one important rule:

.card {
  position: relative;
}

position: relative makes the card the reference point for positioning, so the ribbon can be placed in the card's corner rather than the corner of the page.

Step 2: the ribbon's frame

The outer .ribbon element is an invisible square in the top-right corner. Its job is to hide the ends of the band, so we only see a neat diagonal slice:

.ribbon {
  position: absolute;
  top: -6px;
  right: -6px;
  z-index: 1;
  width: 90px;
  height: 90px;
  overflow: hidden;
  pointer-events: none;
}
LineWhat it does
position: absolute;Takes the frame out of the normal flow so it can sit in the corner
top: -6px; right: -6px;Pushes the frame 6px outside the card, which leaves room for the folded ends
z-index: 1;Keeps the ribbon on top of the card's content
width, heightThe size of the corner area the ribbon covers
overflow: hidden;Clips anything outside the square. This is the key line.
pointer-events: none;Lets clicks pass through the ribbon to anything underneath, such as a link in the card

Here's the same ribbon with overflow switched off and the frame outlined in orange. You can see the band is much longer than it looks, and the frame trims it to fit the corner:

Results
Popular
Pro plan$12 per month

Step 3: the diagonal band

Now the <span> inside the frame. It's a wide, thin strip, rotated 45 degrees and positioned so it runs across the corner:

.ribbon span {
  position: absolute;
  top: 22px;
  right: -27px;
  display: block;
  width: 124px;
  padding: 6px 0;
  font: 700 12px/1 system-ui, sans-serif;
  letter-spacing: 0.05em;
  text-align: center;
  text-transform: uppercase;
  color: #ffffff;
  background: #15803d;
  box-shadow: 0 3px 10px -5px rgb(0 0 0 / 0.8);
  rotate: 45deg;
}
  • rotate: 45deg tilts the strip so it runs diagonally. (You can also write transform: rotate(45deg); both work in every modern browser.)
  • top and right place the strip so its centre crosses the corner. The negative right value lets it hang off the edge of the frame, where it's trimmed.
  • width: 124px makes the strip long enough to reach right across the frame at an angle.
  • text-transform: uppercase and a little letter-spacing give the label a bold, banner-like look.
  • box-shadow adds a soft shadow underneath, lifting the ribbon off the card. The negative spread (-5px) keeps it subtle.
Results
Popular
Pro plan$12 per month

Tip: if you change the frame size, adjust the band's top, right and width by the same proportion. For example, a frame 20% bigger needs values about 20% bigger too. Keep the label short, such as "New" or "Sale", so it fits comfortably across the corner.

Step 4: the folded ends

The finishing touch is two tiny dark triangles where the ribbon meets the card's edges. They make it look like the ribbon wraps around behind the card, giving a 3D effect. Look closely at the first example: they peek out just below each end of the band.

We draw them with the ::before and ::after pseudo-elements, extra boxes added with CSS, using the classic border triangle trick. An element with no width or height, and borders on each side, draws each border as a triangle. Make some borders transparent, and you're left with just the triangle you want:

.ribbon span::before,
.ribbon span::after {
  content: "";
  position: absolute;
  top: 100%;
  z-index: -1;
  border: 3px solid transparent;
  border-top-color: #14532d;
}

.ribbon span::before {
  left: 0;
  border-left-color: #14532d;
}

.ribbon span::after {
  right: 0;
  border-right-color: #14532d;
}
  • top: 100% places each triangle just below the band.
  • left: 0 and right: 0 put one at each end.
  • Two coloured borders, top and one side, form a small triangle. The colour is a darker shade of the ribbon, like the shadowed underside of a fold.

Why 3px and 6px? The two 3px borders make a triangle 6px across, matching the 6px the frame hangs outside the card in step 2. That's what lines the folds up exactly with the card's edges. If you change one, change the other to match.

Changing colours

The original version of this tutorial needed three separate rules for every colour: one for the band and one for each fold. With custom properties (CSS variables), you only need one line.

First, set two variables on the ribbon and use them in place of the fixed colours:

.ribbon {
  --ribbon-color: #15803d;
  --ribbon-fold: color-mix(in srgb, var(--ribbon-color) 60%, black);
  /* ...the rest of the frame styles... */
}

.ribbon span {
  background: linear-gradient(var(--ribbon-color), var(--ribbon-fold));
  /* ... */
}

.ribbon span::before,
.ribbon span::after {
  border-top-color: var(--ribbon-fold);
  /* ... */
}
.ribbon span::before { border-left-color: var(--ribbon-fold); }
.ribbon span::after  { border-right-color: var(--ribbon-fold); }

color-mix() blends two colours together. Here it mixes 60% of the ribbon colour with 40% black, so the fold is always a matching darker shade, worked out automatically. The band also gets a gentle gradient from the main colour down to that darker shade.

Now each new colour is a single line:

.ribbon--red    { --ribbon-color: #b91c1c; }
.ribbon--blue   { --ribbon-color: #1d4ed8; }
.ribbon--purple { --ribbon-color: #7c3aed; }
Results
Green
Red
Blue
Purple

Correction: the original green (#9BC90D fading to #79A70A) and blue (#2989d8) were too light for white text, with contrast ratios between about 2 and 3.7 to 1. Small text needs at least 4.5 to 1 to be easy to read. All the colours above meet that, and the gradient only ever gets darker, so the whole band stays readable.

Other positions and styles

Top-left corner

To move the ribbon to the other corner, swap right for left and rotate the band the opposite way:

.ribbon--left {
  right: auto;
  left: -6px;
}
.ribbon--left span {
  right: auto;
  left: -27px;
  rotate: -45deg;
}
Results
Sale
Desk lampNow $39

The folds still line up, because the ::before and ::after triangles sit at the two ends of the band whichever way it's turned.

A folded side tag

For a different look, try a flat tag that sticks out from the left edge, with a notched end and a small fold underneath where it wraps behind the card:

<div class="card">
  <div class="tag"><span>Best value</span></div>
  ...
</div>
.tag {
  --ribbon-color: #1d4ed8;
  --ribbon-fold: color-mix(in srgb, var(--ribbon-color) 60%, black);
  position: absolute;
  top: 16px;
  left: -8px;
  z-index: 1;
}

.tag span {
  display: block;
  padding: 6px 22px 6px 14px;
  font: 700 12px/1 system-ui, sans-serif;
  text-transform: uppercase;
  color: #ffffff;
  background: var(--ribbon-color);
  clip-path: polygon(0 0, 100% 0, calc(100% - 10px) 50%, 100% 100%, 0 100%);
}

.tag::before {
  content: "";
  position: absolute;
  top: 100%;
  left: 0;
  border-top: 8px solid var(--ribbon-fold);
  border-left: 8px solid transparent;
}
  • left: -8px pulls the tag 8px past the card's left edge.
  • clip-path on the inner <span> cuts the label to a shape. The polygon() points trace the outline, with a V-shaped notch on the right end.
  • The ::before triangle, 8px across, matches those 8px and sits under the tag's left end, so it looks like the tag folds around the edge.
Results
Best value
Annual plan$99 per year

Why the extra span? clip-path trims everything outside its shape, including pseudo-elements. If we clipped the outer .tag, the fold hanging below it would be cut off too. Clipping only the inner <span> keeps the fold safe on the outer element.

Tips and the complete code

Ribbon tips

  • Use them sparingly. A ribbon works because it's unusual. If every card has one, none of them stand out.
  • Keep labels short. One short word fits best across a corner.
  • Don't hide key information. The ribbon's text is real text, so screen readers will read it, but it's small and angled. If a detail really matters, like a sale price, show it in the card as well.
  • Watch the card's corners. The card itself shouldn't have overflow: hidden, or it will clip the folds that hang outside it.

The complete code

.card {
  position: relative;
}

.ribbon {
  --ribbon-color: #15803d;
  --ribbon-fold: color-mix(in srgb, var(--ribbon-color) 60%, black);
  position: absolute;
  top: -6px;
  right: -6px;
  z-index: 1;
  width: 90px;
  height: 90px;
  overflow: hidden;
  pointer-events: none;
}

.ribbon span {
  position: absolute;
  top: 22px;
  right: -27px;
  display: block;
  width: 124px;
  padding: 6px 0;
  font: 700 12px/1 system-ui, sans-serif;
  letter-spacing: 0.05em;
  text-align: center;
  text-transform: uppercase;
  color: #ffffff;
  background: linear-gradient(var(--ribbon-color), var(--ribbon-fold));
  box-shadow: 0 3px 10px -5px rgb(0 0 0 / 0.8);
  rotate: 45deg;
}

.ribbon span::before,
.ribbon span::after {
  content: "";
  position: absolute;
  top: 100%;
  z-index: -1;
  border: 3px solid transparent;
  border-top-color: var(--ribbon-fold);
}
.ribbon span::before { left: 0;  border-left-color: var(--ribbon-fold); }
.ribbon span::after  { right: 0; border-right-color: var(--ribbon-fold); }

/* Colours */
.ribbon--red    { --ribbon-color: #b91c1c; }
.ribbon--blue   { --ribbon-color: #1d4ed8; }
.ribbon--purple { --ribbon-color: #7c3aed; }

/* Top-left corner */
.ribbon--left { right: auto; left: -6px; }
.ribbon--left span { right: auto; left: -27px; rotate: -45deg; }

No more prefixes: the original included -webkit-transform for Safari. Safari has supported the standard transform and rotate properties for many years, so the prefix is no longer needed.

Want to try different sizes, colours and corners without writing the code yourself? Our CSS Ribbon Generator lets you design a ribbon visually and copy the finished CSS.

Wrapping up

A corner ribbon is just two elements: a small frame with overflow: hidden, and a rotated strip inside it. Add two border triangles for the folds, store the colour in a custom property, and you can create ribbons in any colour, in either corner, with a single line of CSS.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee