Developer Documentation

The Listonic Add-to-List button allows users to add ingredients or shopping items directly to their Listonic shopping list. It works on any website or web application and requires only a few lines of JavaScript.

2-Minute Setup

Get your shopping list button running in three simple steps.

1 Define your items using the data-items attribute
2 Add the button container and include the Listonic script
3 Test your button and customize as needed
Quick Start Example
<!-- Listonic Add-to-List Button -->
<div class="listonic-button"
     data-items="Milk, Eggs, Bread"
     data-name="My Shopping List">
</div>
<script src="widget/listonic-button.js" defer></script>

Overview & Benefits#

The Add-to-List integration is designed to be lightweight and easy to embed. You can use it in two main ways, depending on your use case:

  • Custom Button – Ideal for predefined item lists. You have full control over which items are added.
  • Automatic Button – Automatically extracts items from your HTML structure. Perfect for recipe blogs and structured content.

Both methods use a simple JavaScript snippet and hosted scripts provided by Listonic. You can start with the Custom Button for maximum control, or the Automatic Button to automatically convert existing ingredient lists into Add-to-List buttons.

Why use Listonic?

Listonic is used by over 20 million users worldwide and supports 40+ languages. Your visitors get a native shopping list experience automatically.

Custom Add-to-List Button#

The Custom Button gives you full control over which items are added to the user's shopping list. You define the items directly in JavaScript, and the button triggers adding them to Listonic.

When to Use

  • You have a predefined list of items (e.g., product bundles, meal kits)
  • You want complete control over the item list
  • Your items are generated dynamically via JavaScript
  • You're building an e-commerce integration

Script URL

listonic-button.js
widget/listonic-button.js

Basic Implementation

HTML
<!-- Items to be added – HTML links supported -->
<div class="listonic-button"
     data-items="item <a href='http://example.com'>one</a>, item two"
     data-name="My shopping list">
</div>
<script src="widget/listonic-button.js" defer></script>
Item Format

The data-items attribute uses comma-separated values. HTML <a> tags are supported within items to add links to products.

Automatic Button#

The Automatic Button is designed for structured content such as recipes and food blogs. It automatically reads ingredients from your HTML and exposes an Add-to-List experience without requiring you to manually define the items in JavaScript.

When to Use

  • You have recipe pages with ingredient lists in HTML
  • You want automatic extraction without manual configuration
  • Your content follows a consistent HTML structure
  • You're running a food blog or recipe website

Script URL

listonic-auto.js
widget/listonic-auto.js

Basic Implementation

HTML
<!-- Ingredient list on your page -->
<div class="recipe__wrapper__list">
  <ul>
    <li>1 onion</li>
    <li>2 tomatoes</li>
    <li>Olive oil</li>
  </ul>
</div>

<script>
  var listonic_auto = {
    entryClass: "recipe__wrapper__list",
    hideSideBar: true
  };
</script>
<script src="widget/listonic-auto.js" defer></script>

How Automatic Extraction Works

The widget scans the HTML element specified by the entryClass property and extracts text content from list items (<li>) or other text nodes. Each item becomes an entry in the shopping list.

Multiple Buttons on One Page#

If you need multiple Add-to-List buttons on the same page, simply use multiple <div class="listonic-button"> elements. The script only needs to be included once.

Multiple Buttons Example
<!-- First button -->
<div class="listonic-button"
     data-items="Milk, Eggs"
     data-name="Breakfast">
</div>

<!-- Second button -->
<div class="listonic-button"
     data-items="Chicken, Rice, Vegetables"
     data-name="Dinner">
</div>

<!-- Include the script once -->
<script src="widget/listonic-button.js" defer></script>
Important

Each button element must have the listonic-button class. The script only needs to be included once — it will automatically initialize all buttons on the page.

Custom Button Parameters#

data-items Required string

The items to be added to the shopping list. Separate items using commas. HTML links with <a> tags are supported within items.

data-name Optional string

The default name for the shopping list. If not provided, the user can choose or create a list in the Listonic interface.

data-style Optional JSON string

A JSON object with styling properties. Available properties: primaryColor, iconColor, textColor, borderRadius, border, padding, buttonText, fontFamily, fontSize, fontWeight, fontStyle, iconStyle, iconHidden, iconPosition, customCSS.

Automatic Button Parameters#

The Automatic Button is configured using the listonic_auto object. Set its properties before loading the script.

entryClass Required string

The CSS class name of the HTML element containing your ingredient list. The widget will scan this element for list items.

minCount Optional number

The minimum number of items required before the button is shown. Useful for filtering out containers with too few items.

hideSideBar Optional boolean

Set to true to hide the sidebar and use a more compact display mode. Defaults to false.

style Optional object

A style object applied to all auto-generated buttons. Supports the same properties as data-style (e.g. primaryColor, borderRadius, fontFamily).

Button Styling#

Customize the look and feel of your Listonic button using the data-style attribute. Pass a JSON object with the styling properties you want to override.

Custom Styling#

Use the data-style attribute on any button element to apply custom styles:

Custom Styling
<div class="listonic-button"
     data-items="Milk, Eggs, Bread"
     data-name="My List"
     data-style='{
       "primaryColor": "#FF6B35",
       "iconColor": "#ffffff",
       "textColor": "#ffffff",
       "borderRadius": "50px",
       "fontFamily": "Roboto, sans-serif",
       "fontSize": "16px",
       "fontWeight": "600",
       "buttonText": "Add to shopping list",
       "iconStyle": "shopping-cart"
     }'>
</div>
<script src="widget/listonic-button.js" defer></script>

Available Style Properties

Property Description
primaryColor Main button background color
iconColor Icon fill color
textColor Button text color
borderRadius Button border radius (e.g. "50px", "8px")
border CSS border value (e.g. "2px solid #ccc")
padding Button padding
buttonText Custom button label text
fontFamily Font family for button text
fontSize Font size for button text
fontWeight Font weight for button text
fontStyle Font style (e.g. "italic")
iconStyle Icon type: "clipboard-check", "shopping-cart", "list", "plus", or "check"
iconHidden Set to true to hide the icon
iconPosition Set to "right" to move icon after text
customCSS Raw CSS string for advanced customization

Dynamic Content (AJAX/SPAs)#

If you inject content dynamically (for example, via AJAX or a frontend framework), you can create and initialize Listonic buttons programmatically using the ListonicButton.initButton API.

Dynamic Loading Example
// After your content is loaded via AJAX
function addListonicButton(items, listName, containerId, style) {
  const container = document.getElementById(containerId);

  // Create button element with data attributes
  const el = document.createElement('div');
  el.className = 'listonic-button';
  el.dataset.items = items.join(', ');
  el.dataset.name = listName;
  if (style) {
    el.dataset.style = JSON.stringify(style);
  }
  container.appendChild(el);

  // Initialize the button via the public API
  if (window.ListonicButton) {
    window.ListonicButton.initButton(el);
  }
}
Important for Dynamic Loading

Make sure the widget/listonic-button.js script is already loaded before calling ListonicButton.initButton(). The script must be included once on the page.

Framework Integration#

The following examples show how to integrate Listonic buttons with popular JavaScript frameworks. These components use the v2 data-* attributes and ListonicButton.initButton API.

Key Implementation Notes

When using frameworks: (1) Load widget/listonic-button.js once (e.g. in your HTML or via a script loader), (2) Use data-* attributes on div elements, (3) Call ListonicButton.initButton(el) after the element is in the DOM.

React

ListonicButton.jsx
import React, { useEffect, useRef } from 'react';

const ListonicButton = ({ items, name, style }) => {
  const ref = useRef(null);

  useEffect(() => {
    if (ref.current && window.ListonicButton) {
      window.ListonicButton.initButton(ref.current);
    }
  }, [items, name]);

  return (
    <div
      ref={ref}
      className="listonic-button"
      data-items={items}
      data-name={name}
      data-style={style ? JSON.stringify(style) : undefined}
    />
  );
};

export default ListonicButton;

Vue.js

ListonicButton.vue
<template>
  <div ref="buttonEl"
       class="listonic-button"
       :data-items="items"
       :data-name="name"
       :data-style="styleJson"></div>
</template>

<script>
export default {
  props: {
    items: { type: String, required: true },
    name: { type: String, default: 'Shopping List' },
    style: { type: Object, default: null }
  },
  computed: {
    styleJson() {
      return this.style ? JSON.stringify(this.style) : undefined;
    }
  },
  mounted() {
    if (window.ListonicButton) {
      window.ListonicButton.initButton(this.$refs.buttonEl);
    }
  }
}
</script>

Platform Guides#

WordPress

  1. In the Gutenberg editor, add a "Custom HTML" block where you want the button
  2. Paste the complete Listonic button code into the block
  3. For the script, use a plugin like "Insert Headers and Footers" to add it site-wide, or include it in the Custom HTML block

Shopify

  1. Go to Online Store → Themes → Edit code
  2. Add the button HTML to your product template (product-template.liquid)
  3. Add the Listonic script to theme.liquid before </body>

Wix

  1. Add an "Embed" or "HTML iframe" element to your page
  2. Paste the complete button code including the script
  3. Adjust the element size to fit the button

Squarespace

  1. Add a "Code" block to your page
  2. Paste the complete Listonic button code
  3. Save and preview the page

Troubleshooting#

Common Issues

Button doesn't appear

  • Ensure the script URL is correct and accessible
  • Check that the container element has the class listonic-button
  • Verify there are no JavaScript errors in the console
  • Make sure data-items is set on the element before the script loads

Items not being added

  • Check that items are separated by commas in the data-items attribute
  • Ensure the content doesn't contain invalid HTML
  • For the automatic button, verify the entryClass in listonic_auto matches your HTML

Multiple buttons conflict

  • Use separate <div class="listonic-button"> elements for each button
  • Include the script only once on the page

Browser Compatibility

The Listonic widget supports all modern browsers:

  • Chrome (desktop and mobile)
  • Firefox
  • Safari (desktop and iOS)
  • Edge

The widget uses standard JavaScript functionality supported by all modern browsers.

Debugging Tips

  1. Open browser DevTools (F12) and check the Console for errors
  2. Inspect the button element to ensure it has the correct data-* attributes
  3. Verify the public API is available: type window.ListonicButton in the console
  4. Check Network tab to ensure the script loaded (200 status)

Best Practices#

Performance & Script Placement

  • Place the script tag with defer attribute so it does not block initial page rendering
  • For pages with many buttons, use separate <div class="listonic-button"> elements — the script handles them all
  • Load the Listonic script only once per page, even when using multiple buttons

HTML Structure Guidelines

  • Keep ingredient lists in clean, semantic HTML structures (for example, unordered lists with list items) so the widget can parse them reliably
  • Use consistent class names across your recipe pages
  • Avoid nesting interactive elements inside list items

Accessibility

  • The button is rendered as a native HTML element, accessible to screen readers
  • Ensure sufficient color contrast if customizing colors
  • The button is keyboard-navigable by default

Dynamic Content

  • If you inject content dynamically (via AJAX or a frontend framework), use ListonicButton.initButton(el) to initialize new button elements after they are added to the DOM
  • When using multiple buttons, each <div class="listonic-button"> element is independent — no special configuration needed
  • Test your integration on both desktop and mobile devices to ensure a smooth user experience

API Reference#

Custom Button API

Attribute / API Type Required Description
data-items string Yes Comma-separated list of items
data-name string No Default list name
data-style JSON string No JSON object with styling properties
ListonicButton.init() function No Re-initialize all buttons on the page
ListonicButton.initButton(el) function No Initialize a single button element

Automatic Button API

Property Type Required Description
listonic_auto.entryClass string Yes CSS class of ingredient container
listonic_auto.minCount number No Minimum items to show button
listonic_auto.hideSideBar boolean No Hide sidebar for compact mode
listonic_auto.style object No Style object applied to auto-generated buttons

Script URLs

Widget Type URL
Custom Button widget/listonic-button.js
Automatic Button widget/listonic-auto.js

Frequently Asked Questions#

Installation Questions

Can I use the widget on any website?

Yes! The widget works on virtually any website or web application, including WordPress, Shopify, custom HTML sites, and modern JavaScript frameworks. As long as you can insert JavaScript into the page, you can use the Listonic Add-to-List button.

Do I need an API key?

No, the Listonic widget is free to use and doesn't require any API key or registration.

Is there a limit to how many buttons I can add?

No, you can add as many buttons as needed. Just use separate <div class="listonic-button"> elements — the script initializes them all automatically.

Customization Questions

Can I customize the button appearance?

Yes, you can customize colors and other styles using the data-style attribute. See the Styling section for all available properties. You can also use the Widget generator for a visual editor.

Can I change the button text?

Yes, use the buttonText property in the data-style attribute to set any custom label, for example: data-style='{"buttonText":"Add to shopping list"}'.

Technical Questions

Is the widget mobile-friendly?

Yes, the widget is fully responsive and works seamlessly on mobile devices. It connects directly with the Listonic app, which is used by over 20 million users worldwide.

Does the widget affect page load speed?

The widget is lightweight. The script uses the defer attribute, so it loads without blocking initial page rendering.

What happens when a user clicks the button?

The button opens the Listonic interface where users can add items to their shopping list. If they have the Listonic app, items sync automatically across their devices.

Live Examples#

Recipe Blogs & Websites

Recipe websites and food bloggers use our buttons to help readers instantly save ingredients to their shopping lists.

Automatic ingredient extraction, one-click recipe saving, and perfect for meal planning.

View demo →

Travel Guides & Blogs

Travel websites help readers prepare for trips by saving packing lists, local shopping items, and destination essentials.

Destination packing lists, local market shopping guides, and travel essentials reminders.

View demo →

Fitness Blogs & Wellness Sites

Fitness websites help readers save meal prep ingredients, supplement lists, and healthy eating shopping guides.

Meal prep shopping lists, nutrition plan ingredients, and supplement recommendations.

View demo →

Teacher Resources & Educational Sites

Educational platforms help teachers share classroom supply lists, project materials, and student resources with parents.

Classroom supply lists, project material lists, and parent-teacher sharing.

View demo →
Try the Widget generator

Use our interactive Widget generator to create custom-styled buttons with live preview and copy-ready code.