How to structure a Custom Code section with styles, markup, and script
Every Custom Code section consists of three parts: styles, markup, and script. Together, these give you full control over appearance, content, and behavior.
Place your CSS inside a <style> tag at the top of the section. Always scope styles to section.id to prevent conflicts when multiple instances of the same section exist on a page.
The markup section contains HTML mixed with Liquid tags and objects. This is where you define the visual structure and dynamic content of your section.
Place your JavaScript inside a <script> tag. Scope DOM queries to the section root so multiple instances of the same section don’t interfere with each other, and wrap your code in an IIFE to avoid leaking variables into the global scope.
Always scope DOM queries to the section instance. Using document.querySelector('.toggle') without a section root will match elements across every instance of the section on the page.