# Product tabs: free Shopify section

> Up to 6 product info tabs from your own text, the product description, a page or a metafield. Tabs on desktop, accordion on mobile.

Product tabs is a free Shopify section that groups product information such as description, care, shipping and dimensions into up to six tabs, each filled from text you write, the product description, a page or a product metafield. It shows accessible tabs on desktop and an accordion on mobile, keeps every tab's content in the HTML, and works in Online Store 2.0 themes without an app.

- **Category:** Product page
- **Use on:** Product, Landing pages, Any page
- **Reads:** Products
- **Size:** 28 KB in 1 file, with a small script
- **License:** MIT, © 2026 Lintel
- **Page:** https://lintelagency.com/resources/shopify-sections/product-tabs
- **Live demo:** https://lintelagency.com/resources/shopify-sections/demo/lib-product-tabs.html
- **Added:** 2026-10-02

## What it’s for

- Under the buy box on a product page: description, materials and care, shipping and returns, dimensions
- A shared size guide or shipping policy page shown in a tab on every product page
- Per-product care or ingredient details stored in a metafield, without editing each product page

## Editor settings

In the theme editor the section is called “Lib · Product tabs”. IDs, types, labels and defaults come from the section’s schema; the labels are what the theme editor shows.

### Content

| ID | Type | Label | Default | Options or range |
| --- | --- | --- | --- | --- |
| `heading` | `inline_richtext` | Heading | The details |  |
| `heading_tag` | `select` | Heading tag | h2 | `h1`, `h2`, `h3`, `p` |
| `heading_size` | `select` | Heading size | medium | `small`, `medium`, `large`, `xlarge` |
| `text` | `richtext` | Intro text | – |  |
| `product` | `product` | Product | – |  |

### Layout

| ID | Type | Label | Default | Options or range |
| --- | --- | --- | --- | --- |
| `layout` | `select` | Layout | tabs | `tabs`, `accordion` |
| `tab_style` | `select` | Tab style | underline | `underline`, `pills`, `boxed` |
| `tab_alignment` | `select` | Tab alignment | left | `left`, `center` |
| `open_first` | `checkbox` | Open the first item | `true` |  |
| `section_width` | `select` | Width | page | `page`, `full` |
| `max_width` | `range` | Content max width | `960` | 600–1400 px, step 20 |
| `text_alignment` | `text_alignment` | Heading alignment on desktop | left |  |
| `text_alignment_mobile` | `select` | Heading alignment on mobile | left | `left`, `center`, `right` |

### Colors

| ID | Type | Label | Default | Options or range |
| --- | --- | --- | --- | --- |
| `color_bg` | `color` | Background | #FFFFFF |  |
| `color_bg_gradient` | `color_background` | Background gradient | – |  |
| `color_text` | `color` | Text | #1C1917 |  |
| `color_accent` | `color` | Accent (active tab, focus ring) | #1C1917 |  |
| `color_accent_text` | `color` | Text on accent (pill tabs) | #FFFFFF |  |
| `color_border` | `color` | Lines and borders | #E7E5E4 |  |

### Spacing and visibility

| ID | Type | Label | Default | Options or range |
| --- | --- | --- | --- | --- |
| `padding_top` | `range` | Top padding on desktop | `64` | 0–200 px, step 4 |
| `padding_bottom` | `range` | Bottom padding on desktop | `64` | 0–200 px, step 4 |
| `padding_top_mobile` | `range` | Top padding on mobile | `40` | 0–160 px, step 4 |
| `padding_bottom_mobile` | `range` | Bottom padding on mobile | `40` | 0–160 px, step 4 |
| `show_on` | `select` | Show on | all | `all`, `desktop`, `mobile` |
| `anchor_id` | `text` | Anchor ID | – |  |

### Motion

| ID | Type | Label | Default | Options or range |
| --- | --- | --- | --- | --- |
| `animate` | `checkbox` | Fade in the opened tab | `true` |  |

## Blocks

Up to 6 blocks in total.

### Tab (`tab`, up to 6)

| ID | Type | Label | Default | Options or range |
| --- | --- | --- | --- | --- |
| `title` | `text` | Title | Details |  |
| `icon` | `select` | Icon | none | `none`, `info`, `leaf`, `droplet`, `ruler`, `truck`, `return`, `star` |
| `source` | `select` | Content | text | `text`, `description`, `page`, `metafield` |
| `content` | `richtext` | Text | `<p>Add details about the product, care or delivery here.</p>` |  |
| `page` | `page` | Page | – |  |
| `metafield` | `text` | Metafield | custom.care |  |

## Install

### In Shopify admin

1. Work on a copy, not your live theme: in Shopify admin go to **Online Store > Themes**, open the **…** menu on your current theme and choose **Duplicate**.
2. On the copy, open the **…** menu and choose **Edit code**.
3. In the `sections` folder, add a new file named `lib-product-tabs.liquid` and paste the contents of `sections/lib-product-tabs.liquid` from the source below. Save.
4. Open **Customize** on the copy, choose **Add section** and pick **Lib · Product tabs**. Replace the sample content with your own and set the colors.
5. Preview the copy, then publish it when it looks right.

### With Shopify CLI

From your local theme folder, download the files and push only them to an unpublished theme (find its ID with `shopify theme list`):

```sh
curl -fsSL -o sections/lib-product-tabs.liquid https://lintelagency.com/resources/shopify-sections/files/lib-product-tabs.liquid
shopify theme push --theme <unpublished-theme-id> --only sections/lib-product-tabs.liquid
```

Never push to the live theme: always pass the ID of an unpublished theme and never use `--live` or `--allow-live`. Then add the section in the theme editor as above.

## Files

- [sections/lib-product-tabs.liquid](https://lintelagency.com/resources/shopify-sections/files/lib-product-tabs.liquid): goes in `sections/`

## Questions

### Where can a tab's content come from?

Each tab block picks one source: text entered in the block, the product description, a page's content, or a product metafield written as namespace.key, for example custom.care. Single-line and multi-line text metafields are output as text with line breaks kept; other types, such as rich text, are rendered with Shopify's metafield_tag filter.

### What happens when a product has no content for a tab?

The tab is left out for that product, for example when the metafield is not set or the description is empty, so shoppers never see an empty tab. In the theme editor, a metafield or page tab with nothing to show, or a description tab with no product, displays a short note instead so you can see why.

### Is hidden tab content still indexed by search engines?

All tab content is in the page's HTML. Tabs only change which panel is shown, so nothing is loaded later by JavaScript.

### How does it work on mobile and with the keyboard?

Below 750px every tab becomes an accordion item built on native details and summary elements. From 750px up, the default layout shows a tablist with the ARIA tab pattern: arrow keys move between tabs and wrap around, Home and End jump to the first and last tab. You can also choose an accordion on every screen size.

### Does it need JavaScript?

The accordion opens and closes with the browser alone. Switching tabs on desktop uses a small script; before it runs the first tab is shown, so the layout does not jump.

### Which product does it use?

The product picked in the section settings if there is one, otherwise the product of the product page it sits on. With neither, product-based tabs are left out and text and page tabs still show.

## Source

### sections/lib-product-tabs.liquid

```liquid
{%- comment -%}
  MIT License · (c) 2026 Lintel · https://lintelagency.com/resources/shopify-sections
{%- endcomment -%}
{%- comment -%}
  Product tabs: up to 6 tabs of product information. Each tab shows text entered in the block,
  the product description, a page, or a product metafield. Tabs on desktop (ARIA tablist with
  arrow keys, Home and End), an accordion on mobile, or an accordion everywhere.
  Every tab's content is in the HTML; tabs only change which one is shown.
  Uses the product picked in the settings, or the product of the product template.
  Tabs whose source is empty for a product (no description, metafield not set) are left out.
  No snippets needed.
{%- endcomment -%}

{%- liquid
  assign s = section.settings
  assign p = s.product
  if p == blank
    assign p = product
  endif
  assign heading_tag = s.heading_tag | default: 'h2'
  assign uid = 'lib-ptabs-' | append: section.id
  assign list_label = s.heading | strip_html | strip
  if list_label == blank
    assign list_label = p.title | default: 'Product details'
  endif

  assign tabs_html = ''
  assign items_html = ''
  assign n = 0
-%}

{%- for block in section.blocks -%}
  {%- liquid
    assign b = block.settings
    assign body = ''
  -%}
  {%- capture body -%}
    {%- case b.source -%}
      {%- when 'description' -%}
        {%- if p != blank -%}
          {{- p.description -}}
        {%- elsif request.design_mode -%}
          <p>The product description appears here. Pick a product in the section settings to preview it.</p>
        {%- endif -%}
      {%- when 'page' -%}
        {%- if b.page != blank -%}
          {{- b.page.content -}}
        {%- elsif request.design_mode -%}
          <p>Pick a page in this tab's settings to show its content here.</p>
        {%- endif -%}
      {%- when 'metafield' -%}
        {%- liquid
          assign mf = blank
          assign key_parts = b.metafield | strip | split: '.'
          if p != blank and key_parts.size == 2
            assign mf_namespace = key_parts.first
            assign mf_key = key_parts.last
            assign mf = p.metafields[mf_namespace][mf_key]
          endif
        -%}
        {%- if mf != blank -%}
          {%- case mf.type -%}
            {%- when 'multi_line_text_field' -%}
              <p>{{ mf.value | escape | newline_to_br }}</p>
            {%- when 'single_line_text_field' -%}
              <p>{{ mf.value | escape }}</p>
            {%- else -%}
              {{- mf | metafield_tag -}}
          {%- endcase -%}
        {%- elsif request.design_mode -%}
          <p>The metafield {{ b.metafield | escape }} is empty or not set for this product.</p>
        {%- endif -%}
      {%- else -%}
        {{- b.content -}}
    {%- endcase -%}
  {%- endcapture -%}

  {%- liquid
    assign body_check = body | strip_html | strip
    assign has_media = false
    if body contains '<img' or body contains '<iframe' or body contains '<video'
      assign has_media = true
    endif
    if body_check == blank and has_media == false
      continue
    endif
    assign n = n | plus: 1
    assign tab_id = uid | append: '-tab-' | append: block.id
    assign panel_id = uid | append: '-panel-' | append: block.id
  -%}

  {%- capture icon -%}
    {%- case b.icon -%}
      {%- when 'info' -%}
        <svg class="lib-product-tabs__icon" viewBox="0 0 24 24" width="20" height="20" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" stroke-width="1.5"/><path d="M12 11v5M12 7.5v.5" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>
      {%- when 'leaf' -%}
        <svg class="lib-product-tabs__icon" viewBox="0 0 24 24" width="20" height="20" aria-hidden="true" focusable="false"><path d="M5 19c0-8 5-13 14-14 0 9-5 14-13 14H5Zm0 0 7-7" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
      {%- when 'droplet' -%}
        <svg class="lib-product-tabs__icon" viewBox="0 0 24 24" width="20" height="20" aria-hidden="true" focusable="false"><path d="M12 3.5s6 6.5 6 11a6 6 0 0 1-12 0c0-4.5 6-11 6-11Z" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>
      {%- when 'ruler' -%}
        <svg class="lib-product-tabs__icon" viewBox="0 0 24 24" width="20" height="20" aria-hidden="true" focusable="false"><path d="m3.5 15.5 12-12 5 5-12 12-5-5Zm4-4 2 2m1-5 2 2m1-5 2 2" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
      {%- when 'truck' -%}
        <svg class="lib-product-tabs__icon" viewBox="0 0 24 24" width="20" height="20" aria-hidden="true" focusable="false"><path d="M2.5 6.5h11v9h-11zM13.5 9.5h4l3 3v3h-7" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/><circle cx="7" cy="17.5" r="1.75" fill="none" stroke="currentColor" stroke-width="1.5"/><circle cx="17" cy="17.5" r="1.75" fill="none" stroke="currentColor" stroke-width="1.5"/></svg>
      {%- when 'return' -%}
        <svg class="lib-product-tabs__icon" viewBox="0 0 24 24" width="20" height="20" aria-hidden="true" focusable="false"><path d="M9 6 5 10l4 4M5 10h9.5a4.5 4.5 0 0 1 0 9H11" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
      {%- when 'star' -%}
        <svg class="lib-product-tabs__icon" viewBox="0 0 24 24" width="20" height="20" aria-hidden="true" focusable="false"><path d="m12 3.5 2.6 5.3 5.9.9-4.3 4.1 1 5.8-5.2-2.7-5.2 2.7 1-5.8-4.3-4.1 5.9-.9L12 3.5Z" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>
    {%- endcase -%}
  {%- endcapture -%}

  {%- capture tab_html -%}
    <button
      type="button"
      class="lib-product-tabs__tab"
      role="tab"
      id="{{ tab_id }}"
      aria-controls="{{ panel_id }}"
      aria-selected="{% if n == 1 %}true{% else %}false{% endif %}"
      tabindex="{% if n == 1 %}0{% else %}-1{% endif %}"
    >
      {{- icon -}}
      <span>{{ b.title | escape }}</span>
    </button>
  {%- endcapture -%}

  {%- capture item_html -%}
    <details
      class="lib-product-tabs__item"
      {% if n == 1 and s.open_first %}
        open
      {% elsif n == 1 and s.layout == 'tabs' %}
        open
      {% endif %}
      {{ block.shopify_attributes }}
    >
      <summary class="lib-product-tabs__summary">
        {{- icon -}}
        <span class="lib-product-tabs__summary-title">{{ b.title | escape }}</span>
        <svg class="lib-product-tabs__chevron" viewBox="0 0 12 12" width="12" height="12" aria-hidden="true" focusable="false">
          <path d="m2.5 4.5 3.5 3.5 3.5-3.5" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
        </svg>
      </summary>
      <div class="lib-product-tabs__panel" id="{{ panel_id }}">
        <div class="lib-product-tabs__rte">{{ body }}</div>
      </div>
    </details>
  {%- endcapture -%}

  {%- liquid
    assign tabs_html = tabs_html | append: tab_html
    assign items_html = items_html | append: item_html
  -%}
{%- endfor -%}

<div
  class="lib-product-tabs lib-product-tabs--{{ s.section_width }}"
  {% if s.anchor_id != blank %}
    id="{{ s.anchor_id | handleize }}"
  {% endif %}
  data-show="{{ s.show_on }}"
  data-layout="{{ s.layout }}"
  data-tab-style="{{ s.tab_style }}"
  data-tab-align="{{ s.tab_alignment }}"
  {% if s.animate %}
    data-animate
  {% endif %}
  style="
    --lib-bg: {{ s.color_bg }};
    {% if s.color_bg_gradient != blank %}--lib-bg-image: {{ s.color_bg_gradient }};{% endif %}
    --lib-text: {{ s.color_text }};
    --lib-accent: {{ s.color_accent }};
    --lib-accent-text: {{ s.color_accent_text }};
    --lib-border: {{ s.color_border }};
    --lib-max: {{ s.max_width }}px;
    --lib-pt: {{ s.padding_top }}px;
    --lib-pb: {{ s.padding_bottom }}px;
    --lib-pt-m: {{ s.padding_top_mobile }}px;
    --lib-pb-m: {{ s.padding_bottom_mobile }}px;
  "
>
  <div class="lib-product-tabs__inner">
    {%- if s.heading != blank or s.text != blank -%}
      <div class="lib-product-tabs__head" data-align="{{ s.text_alignment }}" data-align-m="{{ s.text_alignment_mobile }}">
        {%- if s.heading != blank -%}
          <{{ heading_tag }} class="lib-product-tabs__heading lib-product-tabs__heading--{{ s.heading_size }}">
            {{- s.heading -}}
          </{{ heading_tag }}>
        {%- endif -%}
        {%- if s.text != blank -%}
          <div class="lib-product-tabs__text">{{ s.text }}</div>
        {%- endif -%}
      </div>
    {%- endif -%}

    {%- if n > 0 -%}
      <lib-product-tabs-panels class="lib-product-tabs__body">
        {%- if s.layout == 'tabs' -%}
          <div class="lib-product-tabs__tablist" role="tablist" aria-label="{{ list_label | escape }}">
            {{- tabs_html -}}
          </div>
        {%- endif -%}
        <div class="lib-product-tabs__items">
          {{- items_html -}}
        </div>
      </lib-product-tabs-panels>
    {%- elsif request.design_mode -%}
      <p class="lib-product-tabs__empty">Add a tab block, or pick a product, to show content here.</p>
    {%- endif -%}
  </div>
</div>

{% stylesheet %}
  .lib-product-tabs {
    background-color: var(--lib-bg);
    background-image: var(--lib-bg-image, none);
    color: var(--lib-text);
    padding: var(--lib-pt-m) 1rem var(--lib-pb-m);
  }
  .lib-product-tabs__inner { max-width: var(--lib-max); margin: 0 auto; }
  .lib-product-tabs--full .lib-product-tabs__inner { max-width: none; }
  @media (max-width: 749px) {
    .lib-product-tabs[data-show='desktop'] { display: none; }
  }
  @media (min-width: 750px) {
    .lib-product-tabs { padding: var(--lib-pt) 1.5rem var(--lib-pb); }
    .lib-product-tabs[data-show='mobile'] { display: none; }
  }

  /* Heading and intro, aligned per device. */
  .lib-product-tabs__head { margin-bottom: 1.75rem; text-align: left; }
  .lib-product-tabs__head[data-align='center'] { text-align: center; }
  .lib-product-tabs__head[data-align='right'] { text-align: right; }
  @media (max-width: 749px) {
    .lib-product-tabs__head[data-align-m='left'] { text-align: left; }
    .lib-product-tabs__head[data-align-m='center'] { text-align: center; }
    .lib-product-tabs__head[data-align-m='right'] { text-align: right; }
  }
  .lib-product-tabs__heading {
    margin: 0;
    font-size: clamp(1.75rem, 3.5vw, 2.5rem);
    line-height: 1.1;
    letter-spacing: -0.02em;
    text-wrap: balance;
  }
  .lib-product-tabs__heading--small { font-size: clamp(1.25rem, 2vw, 1.5rem); }
  .lib-product-tabs__heading--medium { font-size: clamp(1.5rem, 2.75vw, 2rem); }
  .lib-product-tabs__heading--xlarge { font-size: clamp(2.25rem, 5vw, 3.5rem); }
  .lib-product-tabs__text { margin-top: 0.75rem; line-height: 1.6; opacity: 0.75; }
  .lib-product-tabs__text > :first-child { margin-top: 0; }
  .lib-product-tabs__text > :last-child { margin-bottom: 0; }
  .lib-product-tabs__empty { margin: 0; opacity: 0.6; }

  .lib-product-tabs__body { display: block; }

  /* Accordion: every layout on mobile, and "accordion everywhere" on desktop. */
  .lib-product-tabs__items { border-top: 1px solid var(--lib-border); }
  .lib-product-tabs__item { border-bottom: 1px solid var(--lib-border); }
  .lib-product-tabs__summary {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.1rem 0;
    font-weight: 600;
    font-size: 1rem;
    line-height: 1.35;
    list-style: none;
    cursor: pointer;
  }
  .lib-product-tabs__summary::-webkit-details-marker { display: none; }
  .lib-product-tabs__summary::marker { content: ''; }
  .lib-product-tabs__summary-title { flex: 1; min-width: 0; }
  .lib-product-tabs__summary:focus-visible { outline: 2px solid var(--lib-accent); outline-offset: 2px; border-radius: 2px; }
  .lib-product-tabs__icon { flex: none; width: 1.25rem; height: 1.25rem; }
  .lib-product-tabs__chevron { flex: none; transition: transform 0.25s; }
  .lib-product-tabs__item[open] > .lib-product-tabs__summary .lib-product-tabs__chevron { transform: rotate(180deg); }
  .lib-product-tabs__panel { padding: 0 0 1.5rem; }
  .lib-product-tabs__panel:focus-visible { outline: 2px solid var(--lib-accent); outline-offset: 4px; border-radius: 2px; }

  /* Rich text inside a panel. */
  .lib-product-tabs__rte { line-height: 1.65; overflow-wrap: anywhere; }
  .lib-product-tabs__rte > :first-child { margin-top: 0; }
  .lib-product-tabs__rte > :last-child { margin-bottom: 0; }
  .lib-product-tabs__rte :is(p, ul, ol) { margin: 0 0 1em; }
  .lib-product-tabs__rte :is(ul, ol) { padding-inline-start: 1.25em; }
  .lib-product-tabs__rte li + li { margin-top: 0.35em; }
  .lib-product-tabs__rte :is(h2, h3, h4) { margin: 1.5em 0 0.5em; font-size: 1.05rem; }
  .lib-product-tabs__rte a { color: inherit; text-decoration-color: var(--lib-accent); text-underline-offset: 0.2em; }
  .lib-product-tabs__rte img { max-width: 100%; height: auto; }
  .lib-product-tabs__rte table { width: 100%; border-collapse: collapse; display: block; overflow-x: auto; }
  .lib-product-tabs__rte :is(th, td) { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--lib-border); text-align: left; }

  /* Tab bar: hidden on mobile, where the accordion is used. */
  .lib-product-tabs__tablist { display: none; }
  .lib-product-tabs__tab {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.85rem 0;
    color: inherit;
    background: none;
    border: 0;
    font: inherit;
    font-weight: 600;
    font-size: 0.975rem;
    line-height: 1.3;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s, color 0.2s, background-color 0.2s, border-color 0.2s;
  }
  .lib-product-tabs__tab:hover, .lib-product-tabs__tab[aria-selected='true'] { opacity: 1; }
  .lib-product-tabs__tab:focus-visible { outline: 2px solid var(--lib-accent); outline-offset: 2px; border-radius: 4px; }

  @media (min-width: 750px) {
    .lib-product-tabs[data-layout='tabs'] .lib-product-tabs__tablist {
      display: flex;
      flex-wrap: wrap;
      gap: 0.25rem 2rem;
      margin-bottom: 1.75rem;
      border-bottom: 1px solid var(--lib-border);
    }
    .lib-product-tabs[data-layout='tabs'][data-tab-align='center'] .lib-product-tabs__tablist { justify-content: center; }
    .lib-product-tabs[data-layout='tabs'] .lib-product-tabs__items { border-top: 0; }
    .lib-product-tabs[data-layout='tabs'] .lib-product-tabs__item { border-bottom: 0; }
    .lib-product-tabs[data-layout='tabs'] .lib-product-tabs__summary { display: none; }
    .lib-product-tabs[data-layout='tabs'] .lib-product-tabs__panel { padding: 0; }

    /* Underline */
    .lib-product-tabs[data-tab-style='underline'] .lib-product-tabs__tab {
      margin-bottom: -1px;
      border-bottom: 2px solid transparent;
    }
    .lib-product-tabs[data-tab-style='underline'] .lib-product-tabs__tab[aria-selected='true'] { border-bottom-color: var(--lib-accent); }

    /* Pills */
    .lib-product-tabs[data-layout='tabs'][data-tab-style='pills'] .lib-product-tabs__tablist { gap: 0.5rem; border-bottom: 0; }
    .lib-product-tabs[data-tab-style='pills'] .lib-product-tabs__tab {
      padding: 0.6rem 1.15rem;
      border-radius: 999px;
      background: color-mix(in srgb, var(--lib-text) 6%, transparent);
      opacity: 0.8;
    }
    .lib-product-tabs[data-tab-style='pills'] .lib-product-tabs__tab[aria-selected='true'] {
      color: var(--lib-accent-text);
      background: var(--lib-accent);
      opacity: 1;
    }

    /* Boxed: tabs sit on a panel with a border. */
    .lib-product-tabs[data-layout='tabs'][data-tab-style='boxed'] .lib-product-tabs__tablist { gap: 0.25rem; margin-bottom: 0; }
    .lib-product-tabs[data-tab-style='boxed'] .lib-product-tabs__tab {
      margin-bottom: -1px;
      padding: 0.8rem 1.25rem;
      border: 1px solid transparent;
      border-radius: 8px 8px 0 0;
    }
    .lib-product-tabs[data-tab-style='boxed'] .lib-product-tabs__tab[aria-selected='true'] {
      background-color: var(--lib-bg);
      border-color: var(--lib-border);
      border-bottom-color: var(--lib-bg);
    }
    .lib-product-tabs[data-layout='tabs'][data-tab-style='boxed'] .lib-product-tabs__items {
      padding: 2rem;
      border: 1px solid var(--lib-border);
      border-top: 0;
      border-radius: 0 0 8px 8px;
    }
  }

  /* Motion: the shown panel fades in. */
  .lib-product-tabs[data-animate] .lib-product-tabs__item[open] .lib-product-tabs__panel { animation: lib-product-tabs-in 0.35s ease both; }
  @keyframes lib-product-tabs-in {
    from { opacity: 0; transform: translateY(6px); }
  }
  @media (prefers-reduced-motion: reduce) {
    .lib-product-tabs[data-animate] .lib-product-tabs__item[open] .lib-product-tabs__panel { animation: none; }
    .lib-product-tabs__chevron, .lib-product-tabs__tab { transition: none; }
  }
{% endstylesheet %}

{% javascript %}
  if (!customElements.get('lib-product-tabs-panels')) {
    customElements.define(
      'lib-product-tabs-panels',
      class extends HTMLElement {
        connectedCallback() {
          const list = this.querySelector(':scope > [role="tablist"]');
          const items = this.querySelector(':scope > .lib-product-tabs__items');
          if (!list || !items) return;
          this.tabs = [...list.querySelectorAll(':scope > [role="tab"]')];
          this.items = [...items.querySelectorAll(':scope > details')];
          if (!this.tabs.length || this.tabs.length !== this.items.length) return;
          this.panels = this.items.map((item) => item.querySelector('.lib-product-tabs__panel'));
          this.mq = window.matchMedia('(min-width: 750px)');
          this.active = Math.max(0, this.items.findIndex((item) => item.open));

          this.onClick = (e) => {
            const tab = e.target.closest('[role="tab"]');
            const i = this.tabs.indexOf(tab);
            if (i > -1) this.select(i);
          };
          this.onKey = (e) => {
            const i = this.tabs.indexOf(document.activeElement);
            if (i < 0) return;
            const last = this.tabs.length - 1;
            const map = { ArrowRight: i === last ? 0 : i + 1, ArrowLeft: i === 0 ? last : i - 1, Home: 0, End: last };
            if (!(e.key in map)) return;
            e.preventDefault();
            this.select(map[e.key], true);
          };
          // A closed panel opened by the browser (find in page) becomes the selected tab.
          this.onToggle = (e) => {
            if (!this.isTabs || !e.target.open) return;
            const i = this.items.indexOf(e.target);
            if (i > -1 && i !== this.active) this.select(i);
          };
          this.onMode = () => this.applyMode();

          list.addEventListener('click', this.onClick);
          list.addEventListener('keydown', this.onKey);
          items.addEventListener('toggle', this.onToggle, true);
          this.mq.addEventListener('change', this.onMode);
          this.applyMode();
        }

        disconnectedCallback() {
          if (this.mq && this.onMode) this.mq.removeEventListener('change', this.onMode);
        }

        applyMode() {
          this.isTabs = this.mq.matches;
          this.panels.forEach((panel, i) => {
            if (!panel) return;
            if (this.isTabs) {
              panel.setAttribute('role', 'tabpanel');
              panel.setAttribute('aria-labelledby', this.tabs[i].id);
              panel.tabIndex = 0;
            } else {
              panel.removeAttribute('role');
              panel.removeAttribute('aria-labelledby');
              panel.removeAttribute('tabindex');
            }
          });
          if (this.isTabs) {
            const open = this.items.findIndex((item) => item.open);
            this.select(open > -1 ? open : this.active);
          }
        }

        select(index, focus) {
          this.active = index;
          this.tabs.forEach((tab, i) => {
            const on = i === index;
            tab.setAttribute('aria-selected', String(on));
            tab.tabIndex = on ? 0 : -1;
          });
          if (this.isTabs) this.items.forEach((item, i) => (item.open = i === index));
          if (focus) this.tabs[index].focus();
        }
      }
    );
  }
{% endjavascript %}

{% schema %}
{
  "name": "Lib · Product tabs",
  "tag": "section",
  "class": "lib-section",
  "max_blocks": 6,
  "settings": [
    { "type": "header", "content": "Content" },
    { "type": "inline_richtext", "id": "heading", "label": "Heading", "default": "The details" },
    {
      "type": "select",
      "id": "heading_tag",
      "label": "Heading tag",
      "info": "Use H1 only when this is the page's main heading.",
      "options": [
        { "value": "h1", "label": "H1" },
        { "value": "h2", "label": "H2" },
        { "value": "h3", "label": "H3" },
        { "value": "p", "label": "Paragraph" }
      ],
      "default": "h2"
    },
    {
      "type": "select",
      "id": "heading_size",
      "label": "Heading size",
      "options": [
        { "value": "small", "label": "Small" },
        { "value": "medium", "label": "Medium" },
        { "value": "large", "label": "Large" },
        { "value": "xlarge", "label": "Extra large" }
      ],
      "default": "medium"
    },
    { "type": "richtext", "id": "text", "label": "Intro text" },
    {
      "type": "product",
      "id": "product",
      "label": "Product",
      "info": "Optional on product pages, where the page's own product is used. Pick one to use the tabs on any other page."
    },

    { "type": "header", "content": "Layout" },
    {
      "type": "select",
      "id": "layout",
      "label": "Layout",
      "options": [
        { "value": "tabs", "label": "Tabs on desktop, accordion on mobile" },
        { "value": "accordion", "label": "Accordion everywhere" }
      ],
      "default": "tabs"
    },
    {
      "type": "select",
      "id": "tab_style",
      "label": "Tab style",
      "options": [
        { "value": "underline", "label": "Underline" },
        { "value": "pills", "label": "Pills" },
        { "value": "boxed", "label": "Boxed" }
      ],
      "default": "underline",
      "visible_if": "{{ section.settings.layout == 'tabs' }}"
    },
    {
      "type": "select",
      "id": "tab_alignment",
      "label": "Tab alignment",
      "options": [
        { "value": "left", "label": "Left" },
        { "value": "center", "label": "Center" }
      ],
      "default": "left",
      "visible_if": "{{ section.settings.layout == 'tabs' }}"
    },
    {
      "type": "checkbox",
      "id": "open_first",
      "label": "Open the first item",
      "info": "With tabs on desktop, the first item always starts open.",
      "default": true,
      "visible_if": "{{ section.settings.layout == 'accordion' }}"
    },
    {
      "type": "select",
      "id": "section_width",
      "label": "Width",
      "options": [
        { "value": "page", "label": "Page width" },
        { "value": "full", "label": "Full width" }
      ],
      "default": "page"
    },
    {
      "type": "range",
      "id": "max_width",
      "label": "Content max width",
      "min": 600,
      "max": 1400,
      "step": 20,
      "unit": "px",
      "default": 960,
      "visible_if": "{{ section.settings.section_width == 'page' }}"
    },
    { "type": "text_alignment", "id": "text_alignment", "label": "Heading alignment on desktop", "default": "left" },
    {
      "type": "select",
      "id": "text_alignment_mobile",
      "label": "Heading alignment on mobile",
      "options": [
        { "value": "left", "label": "Left" },
        { "value": "center", "label": "Center" },
        { "value": "right", "label": "Right" }
      ],
      "default": "left"
    },

    { "type": "header", "content": "Colors" },
    { "type": "color", "id": "color_bg", "label": "Background", "default": "#FFFFFF" },
    { "type": "color_background", "id": "color_bg_gradient", "label": "Background gradient", "info": "Optional. Covers the background color." },
    { "type": "color", "id": "color_text", "label": "Text", "default": "#1C1917" },
    { "type": "color", "id": "color_accent", "label": "Accent (active tab, focus ring)", "default": "#1C1917" },
    { "type": "color", "id": "color_accent_text", "label": "Text on accent (pill tabs)", "default": "#FFFFFF" },
    { "type": "color", "id": "color_border", "label": "Lines and borders", "default": "#E7E5E4" },

    { "type": "header", "content": "Spacing and visibility" },
    { "type": "range", "id": "padding_top", "label": "Top padding on desktop", "min": 0, "max": 200, "step": 4, "unit": "px", "default": 64 },
    { "type": "range", "id": "padding_bottom", "label": "Bottom padding on desktop", "min": 0, "max": 200, "step": 4, "unit": "px", "default": 64 },
    { "type": "range", "id": "padding_top_mobile", "label": "Top padding on mobile", "min": 0, "max": 160, "step": 4, "unit": "px", "default": 40 },
    { "type": "range", "id": "padding_bottom_mobile", "label": "Bottom padding on mobile", "min": 0, "max": 160, "step": 4, "unit": "px", "default": 40 },
    {
      "type": "select",
      "id": "show_on",
      "label": "Show on",
      "options": [
        { "value": "all", "label": "All devices" },
        { "value": "desktop", "label": "Desktop only" },
        { "value": "mobile", "label": "Mobile only" }
      ],
      "default": "all"
    },
    { "type": "text", "id": "anchor_id", "label": "Anchor ID", "info": "Optional. Link to this section with #your-id." },

    { "type": "header", "content": "Motion" },
    { "type": "checkbox", "id": "animate", "label": "Fade in the opened tab", "default": true }
  ],
  "blocks": [
    {
      "type": "tab",
      "name": "Tab",
      "limit": 6,
      "settings": [
        { "type": "text", "id": "title", "label": "Title", "default": "Details" },
        {
          "type": "select",
          "id": "icon",
          "label": "Icon",
          "options": [
            { "value": "none", "label": "None" },
            { "value": "info", "label": "Info" },
            { "value": "leaf", "label": "Leaf" },
            { "value": "droplet", "label": "Droplet" },
            { "value": "ruler", "label": "Ruler" },
            { "value": "truck", "label": "Truck" },
            { "value": "return", "label": "Return arrow" },
            { "value": "star", "label": "Star" }
          ],
          "default": "none"
        },
        {
          "type": "select",
          "id": "source",
          "label": "Content",
          "info": "A tab whose content is empty for a product is left out.",
          "options": [
            { "value": "text", "label": "Text entered below" },
            { "value": "description", "label": "Product description" },
            { "value": "page", "label": "A page" },
            { "value": "metafield", "label": "A product metafield" }
          ],
          "default": "text"
        },
        {
          "type": "richtext",
          "id": "content",
          "label": "Text",
          "default": "<p>Add details about the product, care or delivery here.</p>",
          "visible_if": "{{ block.settings.source == 'text' }}"
        },
        {
          "type": "page",
          "id": "page",
          "label": "Page",
          "info": "Used when Content is set to A page, for example a shared shipping or size guide page."
        },
        {
          "type": "text",
          "id": "metafield",
          "label": "Metafield",
          "info": "Namespace and key, for example custom.care. Text, multi-line text and rich text metafields are supported.",
          "default": "custom.care",
          "visible_if": "{{ block.settings.source == 'metafield' }}"
        }
      ]
    }
  ],
  "presets": [
    {
      "name": "Lib · Product tabs",
      "blocks": [
        { "type": "tab", "settings": { "title": "Description", "icon": "info", "source": "description" } },
        { "type": "tab", "settings": { "title": "Materials and care", "icon": "droplet", "source": "metafield", "metafield": "custom.care" } },
        {
          "type": "tab",
          "settings": {
            "title": "Shipping and returns",
            "icon": "truck",
            "source": "text",
            "content": "<p>Orders ship within 2 business days in recycled packaging. Delivery takes 3 to 5 business days.</p><p>Changed your mind? Return unused pieces within 30 days for a full refund.</p>"
          }
        },
        {
          "type": "tab",
          "settings": {
            "title": "Dimensions",
            "icon": "ruler",
            "source": "text",
            "content": "<ul><li>Height: 9.5 cm</li><li>Diameter: 8.5 cm</li><li>Capacity: 350 ml</li><li>Weight: 320 g</li></ul>"
          }
        }
      ]
    }
  ]
}
{% endschema %}
```

## License

MIT License, © 2026 Lintel. Free to use, change and ship in your own store or in client work; keep the license line at the top of each file.
