How to design custom product labels and badges | Shopify

{%- assign labels = product.metafields.custom.labels.value -%}

<div class="product-labels">
  {%- for label in labels -%}
    
    {%- assign background_color = label.color -%}
    {%- assign color_string = "" | append: background_color -%}
    {%- assign text_color = color_string | color_lighten: 100 -%}  
    
    <small class="product-label" style="background-color: {{ background_color }}; color: {{ text_color }};">
      {{ label.title }}
    </small>
    
  {%- endfor -%}
</div>
<style>
  .product-card-wrapper {
    position: relative;
  }
  
  .product-labels {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: end;
    gap: 5px;
    
  }
  .product-label {
    padding: 2px 5px;
    text-transform: uppercase;
    text-align: center;
    font-weight: bold;
    width: fit-content;
  }
</style>

Leave a Reply

Your email address will not be published. Required fields are marked *