Table of Contents

Creates a list of links to all the h2 and h3 headings of your content

Demo


This page is the example.

The Page Contents list is generated by Socks UI based on this content

Scripts

Add these before the </body> tag in your site/page settings

GSAP
 <script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/gsap.min.js"></script>
ScrollTrigger
 <script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/ScrollTrigger.min.js"></script>
Table of Contents component
<script src="https://cdn.jsdelivr.net/npm/socks-ui@{v}/dist/toc.js"></script>

Features

  • Support for 2 levels of links
  • Customizable selectors (up to 2)
  • Customizable active class
  • Custom offset so that your navbar doesn't cover the clicked heading

Anatomy

  • Content [s-toc="content"]
  • List [s-toc="list"]
    • List item
      • Link
        • Text [s-toc="text"]
      • List (optional)
        • List item (optional)
          • Link
            • Text [s-toc="text"]

Usage

Main Attributes:

s-toc = content - The content wrapper that you want the links to be generated from.

s-toc = list - The list element that will include the main links.

s-toc = text - The text element inside the list item that will get replaced with the heading text.

Options (add to the list element):

s-toc-offset - The distance between heading and top of your screen when you click one of the links. Can be any CSS unit. Default: 80px.

s-toc-active - The class that will be added to active links. Default: s-active

s-custom-selector - Which heading tags to look for (max. 2). Default: h2,h3

Setup:

  1. Add the s-toc="content" attribute to the div or rich text element that contains your content
  1. Add the s-toc="list" attribute to the list element that will have all the links. This is also where you can add the options attributes. Inside the list element, add one list item.
  2. Inside the list item, add a link block, and inside the link block, add a text block. Add the s-toc-"text" attribute to the text block
  3. (Optional) If you want 2 levels of links, add another list element inside the first list item, and add one list item in it, with the same setup as the first list.


You can also add your active classes on the items and Socks UI will remove them for you if needed.

It should look like this:

The structure of your list

Advanced

Events

No custom events are exported for this component.

Methods

No custom methods are exported for this component.

Use Cases

No special use cases added yet
{"type":"@webflow/XscpData","payload":{"nodes":[{"_id":"a358dc12-5705-7c3b-41b9-4236eb6e2bde","type":"Block","tag":"nav","classes":[],"children":["9d746669-965f-7a8c-0190-76a48b4d8ad1","9ea1003f-6091-092d-cc51-50843f4ba329"],"data":{"text":false,"tag":"nav","xattr":[{"name":"aria-labelledby","value":"toc-title"}]}},{"_id":"9d746669-965f-7a8c-0190-76a48b4d8ad1","type":"Block","tag":"div","classes":[],"children":["a5d89c68-78a6-a641-3187-eba8552236de"],"data":{"text":true,"tag":"div","attr":{"id":"toc-title"}}},{"_id":"a5d89c68-78a6-a641-3187-eba8552236de","text":true,"v":"Page Contents"},{"_id":"9ea1003f-6091-092d-cc51-50843f4ba329","type":"List","tag":"ul","classes":["0ce16345-71dd-0719-2bbc-81fb046bde7f"],"children":["af2f604e-5c51-43b1-cc7e-045c4d2b7a3a"],"data":{"tag":"ul","list":{"type":"list","unstyled":true},"devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[{"name":"s-toc","value":"list"},{"name":"s-toc-active","value":"cc-active"}],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"af2f604e-5c51-43b1-cc7e-045c4d2b7a3a","type":"ListItem","tag":"li","classes":[],"children":["a4bb273b-28ac-de54-6bce-4f81df232aff","eb41df9f-2177-450b-8751-a7349ece2ab2"],"data":{"list":{"type":"item"},"text":false,"devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"a4bb273b-28ac-de54-6bce-4f81df232aff","type":"Link","tag":"a","classes":["e40db630-1402-e986-5b52-1556af6bbee7","8cbe82b5-81f2-729c-0d28-fbf7222e839b"],"children":["b8d39c79-06aa-66ee-dce8-8852405e1dfc"],"data":{"button":false,"block":"inline","link":{"mode":"external","url":"#"},"attr":{"id":""},"devlink":{"runtimeProps":{},"slot":""},"displayName":"","xattr":[],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"b8d39c79-06aa-66ee-dce8-8852405e1dfc","type":"Block","tag":"div","classes":["7ae31e58-dcfd-04a5-d469-fe86fef9c726"],"children":["25c96916-61c4-28d8-cc10-364ccc4f3481"],"data":{"text":true,"tag":"div","devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[{"name":"s-toc","value":"text"}],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"25c96916-61c4-28d8-cc10-364ccc4f3481","text":true,"v":"Example"},{"_id":"eb41df9f-2177-450b-8751-a7349ece2ab2","type":"List","tag":"ul","classes":["ec937d14-a51b-6895-9a5e-92f90c252e80"],"children":["42ff02e1-f6c1-6ba3-9f92-027f7d196979"],"data":{"tag":"ul","list":{"type":"list","unstyled":false},"devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"42ff02e1-f6c1-6ba3-9f92-027f7d196979","type":"ListItem","tag":"li","classes":[],"children":["dc03b156-4b94-fe07-baea-8126565b1cae"],"data":{"list":{"type":"item"},"text":false,"devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"dc03b156-4b94-fe07-baea-8126565b1cae","type":"Link","tag":"a","classes":["e40db630-1402-e986-5b52-1556af6bbee7","a35fe710-3930-1d7b-e8ad-fb78b4194a5b","551f8088-1329-736a-2888-9289714621e7"],"children":["d8c843c0-7543-2392-1de2-e7ce865f6f03"],"data":{"button":false,"block":"inline","link":{"mode":"external","url":"#"},"attr":{"id":""},"devlink":{"runtimeProps":{},"slot":""},"displayName":"","xattr":[],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"d8c843c0-7543-2392-1de2-e7ce865f6f03","type":"Block","tag":"div","classes":["32f4f133-852c-b71c-1f6d-47e4855a4fba"],"children":["545cf147-e4c3-bc28-0ee8-d5cc9a28e864"],"data":{"text":true,"tag":"div","devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[{"name":"s-toc","value":"text"}],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"545cf147-e4c3-bc28-0ee8-d5cc9a28e864","text":true,"v":"Example"}],"styles":[{"_id":"0ce16345-71dd-0719-2bbc-81fb046bde7f","fake":false,"type":"class","name":"toc","namespace":"","comb":"","styleLess":"padding-left: 0rem; list-style-type: none;","variants":{},"children":[],"createdBy":"5de3f22e747d41cf4377aef1","origin":null,"selector":null},{"_id":"e40db630-1402-e986-5b52-1556af6bbee7","fake":false,"type":"class","name":"sidebar_link","namespace":"","comb":"","styleLess":"position: relative; display: flex; padding-top: 0.5rem; padding-right: 1rem; padding-bottom: 0.4rem; padding-left: 1rem; justify-content: flex-start; align-items: center; border-top-left-radius: 0.625rem; border-top-right-radius: 0.625rem; border-bottom-left-radius: 0.625rem; border-bottom-right-radius: 0.625rem; transition-property: background-color, padding-left; transition-duration: 200ms, 200ms; transition-timing-function: ease, ease;","variants":{"main_current":{"styleLess":"background-color: hsla(157, 0.00%, 79.33%, 1.00);"},"main_hover":{"styleLess":"background-color: rgba(255, 255, 255, 0.1);"}},"children":["a35fe710-3930-1d7b-e8ad-fb78b4194a5b","8cbe82b5-81f2-729c-0d28-fbf7222e839b"],"createdBy":"5de3f22e747d41cf4377aef1","origin":null,"selector":null},{"_id":"8cbe82b5-81f2-729c-0d28-fbf7222e839b","fake":false,"type":"class","name":"cc-active","namespace":"","comb":"&","styleLess":"","variants":{},"children":[],"createdBy":"5de3f22e747d41cf4377aef1","origin":null,"selector":null},{"_id":"7ae31e58-dcfd-04a5-d469-fe86fef9c726","fake":false,"type":"class","name":"text-sm","namespace":"","comb":"","styleLess":"font-size: 1rem; line-height: 1.4;","variants":{},"children":["3fa5ec7c-3bf9-7778-9138-bd125510090b"],"createdBy":"64f4c4cdbe566b5a0114b6d3","origin":null,"selector":null},{"_id":"ec937d14-a51b-6895-9a5e-92f90c252e80","fake":false,"type":"class","name":"toc_sub","namespace":"","comb":"","styleLess":"margin-top: 4px; padding-left: 0rem; list-style-type: none;","variants":{},"children":[],"createdBy":"5de3f22e747d41cf4377aef1","origin":null,"selector":null},{"_id":"a35fe710-3930-1d7b-e8ad-fb78b4194a5b","fake":false,"type":"class","name":"cc-sub","namespace":"","comb":"&","styleLess":"margin-left: 1em;","variants":{},"children":["551f8088-1329-736a-2888-9289714621e7"],"createdBy":"5de3f22e747d41cf4377aef1","origin":null,"selector":null},{"_id":"551f8088-1329-736a-2888-9289714621e7","fake":false,"type":"class","name":"cc-active","namespace":"","comb":"&","styleLess":"","variants":{},"children":[],"createdBy":"5de3f22e747d41cf4377aef1","origin":null,"selector":null},{"_id":"32f4f133-852c-b71c-1f6d-47e4855a4fba","fake":false,"type":"class","name":"text-xs","namespace":"","comb":"","styleLess":"font-size: 0.875rem; line-height: 1.4;","variants":{},"children":["95b9e158-4247-6ed7-2acc-d2280c74d5f2"],"createdBy":"64f4c4cdbe566b5a0114b6d3","origin":null,"selector":null}],"assets":[],"ix1":[],"ix2":{"interactions":[],"events":[],"actionLists":[]}},"meta":{"droppedLinks":0,"dynBindRemovedCount":0,"dynListBindRemovedCount":0,"paginationRemovedCount":0,"universalBindingsRemovedCount":0,"unlinkedSymbolCount":0}}