Skip to content

Ribbon

The Ribbon component provides a stylish, ribbon-shaped label that can be positioned on elements. It’s commonly used to highlight special features, promotions, or status indicators on cards, images, or containers.

  • Metro UI Core CSS
<!-- Basic ribbon -->
<div style="position: relative; width: 300px; height: 200px; background-color: #f0f0f0;">
<span class="ribbon">New</span>
Content with a ribbon label
</div>
<!-- Right-positioned ribbon -->
<div style="position: relative; width: 300px; height: 200px; background-color: #f0f0f0;">
<span class="ribbon right">Featured</span>
Content with a right-positioned ribbon
</div>
<!-- Ribbon with icon -->
<div style="position: relative; width: 300px; height: 200px; background-color: #f0f0f0;">
<span class="ribbon">
<span class="icon mif-star-full"></span>
Featured
</span>
Content with an icon in the ribbon
</div>
<!-- Red ribbon -->
<div style="position: relative; width: 300px; height: 200px; background-color: #f0f0f0;">
<span class="ribbon ribbon-red">Sale</span>
Content with a red ribbon
</div>
<!-- Green ribbon -->
<div style="position: relative; width: 300px; height: 200px; background-color: #f0f0f0;">
<span class="ribbon ribbon-green">Success</span>
Content with a green ribbon
</div>
<!-- Blue ribbon -->
<div style="position: relative; width: 300px; height: 200px; background-color: #f0f0f0;">
<span class="ribbon ribbon-blue">Info</span>
Content with a blue ribbon
</div>
<!-- Yellow ribbon -->
<div style="position: relative; width: 300px; height: 200px; background-color: #f0f0f0;">
<span class="ribbon ribbon-yellow">Warning</span>
Content with a yellow ribbon
</div>

The Ribbon component can be styled using the following CSS variables:

VariableDefault (Light)Dark ModeDescription
--ribbon-backgroundrgb(117, 117, 117)rgba(117, 117, 117, 0.32)Background color of the ribbon
--ribbon-color#ffffff#ffffffText color of the ribbon
/* Custom styling for a specific ribbon */
.custom-ribbon {
--ribbon-background: #3498db;
--ribbon-color: #ffffff;
font-size: 14px;
padding: 8px 16px;
top: 30px;
}
.custom-ribbon::before {
color: #2980b9;
}
<div style="position: relative; width: 300px; height: 200px; background-color: #f0f0f0;">
<span class="ribbon custom-ribbon">
<span class="icon mif-gift"></span>
Special Offer
</span>
Content with a custom styled ribbon
</div>
  • .ribbon - The base class for the ribbon component
  • .right - Positions the ribbon on the right side of the element
  • .ribbon-red - Red ribbon
  • .ribbon-green - Green ribbon
  • .ribbon-blue - Blue ribbon
  • .ribbon-yellow - Yellow ribbon
  • .ribbon-orange - Orange ribbon
  • .ribbon-purple - Purple ribbon
  • .ribbon-lime - Lime ribbon
  • And other standard Metro UI colors

The Ribbon component has the following structure:

<span class="ribbon [position] [color-variant]">
<!-- Optional icon -->
<span class="icon [icon-class]"></span>
<!-- Ribbon text -->
Ribbon text
</span>
<div class="card" style="position: relative; width: 300px;">
<div class="card-header">
<span class="ribbon ribbon-red">20% OFF</span>
<img src="product-image.jpg" alt="Product">
</div>
<div class="card-content">
<h3>Product Name</h3>
<p>Product description goes here.</p>
<div class="price">$79.99</div>
</div>
<div class="card-footer">
<button class="button primary">Add to Cart</button>
</div>
</div>
<div class="image-gallery">
<div class="image-item" style="position: relative;">
<span class="ribbon ribbon-yellow">Featured</span>
<img src="image1.jpg" alt="Image 1">
<div class="caption">Image 1</div>
</div>
<div class="image-item" style="position: relative;">
<img src="image2.jpg" alt="Image 2">
<div class="caption">Image 2</div>
</div>
<div class="image-item" style="position: relative;">
<span class="ribbon ribbon-blue right">New</span>
<img src="image3.jpg" alt="Image 3">
<div class="caption">Image 3</div>
</div>
</div>
  1. The parent element must have position: relative (or absolute/fixed) for the ribbon to be positioned correctly
  2. The ribbon is positioned absolutely at the top-left (or top-right) of the parent element
  3. The ribbon has a z-index value that places it above most elements but below fixed elements
  4. The ribbon includes a shadow effect for depth
  1. Use ribbons sparingly to highlight truly important information
  2. Choose ribbon colors that contrast well with the background they appear on
  3. Keep ribbon text short and concise for better readability
  4. Consider using icons to enhance visual recognition
  5. Ensure the ribbon doesn’t obscure important content in the parent element
  6. For accessibility, ensure sufficient color contrast between the ribbon and its text