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>

One Comment

  1. I have watched your video multiple times but failed to achieve the result. May be because of UI chane from 2023 to 2025. Can you help where to add the custom code. Also you were showing what already been set. Best way would be to show and do it in the latest version

Leave a Reply

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