Toggles

Use toggles to organize your article content in a way that makes it easy for your visitors to find what they're looking for.

Standard toggles

Creating toggles within your article content doesn’t involve copying and pasting any HTML as the Tabs extension lets you transform standard ordered (<ol>) and unordered (<ul>) lists created in the article editor into interactive collapsible and expandable sections. This makes it easy for visitors to find what they’re looking and allows content creators to focus on producing helpful content.

If you do ever need to migrate your content you can do so without having to worry about unnecessary markup or inline styles.

The default toggles template
View code
<ul class="js-toggles">
  <li data-title="Android">
    <p>Android is a mobile operating system based on a modified version of the Linux kernel and other open source software, designed primarily for touchscreen mobile devices such as smartphones and tablets. Android is developed by a consortium of developers known as the Open Handset Alliance and commercially sponsored by Google. It was unveiled in 2007, with the first commercial Android device launched in September 2008.</p>
  </li>
  <li data-title="iOS">
    <p>iOS is a mobile operating system created and developed by Apple Inc. exclusively for its hardware. It is the operating system that presently powers many of the company's mobile devices, including the iPhone, and iPod Touch; it also powered the iPad prior to the introduction of iPadOS in 2019. It is the second most popular mobile operating system globally after Android. It is the basis for other operating systems made by Apple Inc, like iPadOS, tvOS, and watchOS.</p>
  </li>
  <li data-title="Windows">
    <p>Windows 10 Mobile is a discontinued mobile operating system developed by Microsoft. First released in 2015, it is a successor to Windows Phone 8.1, but was marketed by Microsoft as being an edition of its PC operating system Windows 10. Windows 10 Mobile aimed to provide greater consistency with its counterpart for PCs, including more extensive synchronization of content, the ability to to connect devices to an external display and use a desktop interface with mouse and keyboard input support.</p>
  </li>
</ul>

The default template is simple, elegant and responsive and will automatically inherit the overall style of your theme. You can add any type of content you like to each collapsible section, including HTML, images, videos and other article formatting styles.

Customized toggles

Using the options described on the Usage tab you can have the toggles behave an an accordion, where only one toggle can be expanded at a time, and create custom templates. Custom templates can be used to change completely change the look-and-feel of the toggles, add new elements like icons and even modify the behavior of the toggles themselves.

Large, custom toggles with icons

Creating toggles

Toggles can be used anywhere in the help center, but often they are used within article content. Our extension allows you to create toggles in several different ways, none of which require you to copy-and-paste any HTML.

The Toggles extension is bundled into all of our themes by default, so you can start using it straight away. The source code can be found within the extensions.(min.)js file in the theme’s Assets folder.

When creating or updating an article using the Zendesk article editor:

  1. Create a numbered (Add numbered list button) or bulleted list (Add bulleted list button) using the editor toolbar and add the content that you’d like to see in each tab within the list items.

  2. Click the Source Code (Source code icon) button in the editor toolbar to view the source code of the page.

  3. Add a class name of .js-toggles to the list element to convert it into a set of interactive tabs.

  4. Add a data-title attribute to each list item containing the title you’d like to use for the tab. Alternatively, you can apply a class name of .toggle-heading to an element within the list item and that element’s text content will be used as the tab title.

     <ul class="js-tog">
       <li data-title="The first toggle title">...</li>
       <li data-title="The second toggle title">...</li>
       <li>
         <h3 class="toggle-heading">The third toggle title</h3>
         ...
       </li>
     </ul>
    

    If data attributes are used you will need to ensure that the allow unsafe HTML setting is enabled within Zendesk Guide.

The Toggles extension allows you to convert a standard ordered (<ol>) or unordered (<ul>) list into an interactive set of tabs using JavaScript:

<ul class="js-toggles">
  <li data-title="The first toggle">...</li>
  <li data-title="The second toggle">...</li>
  <li data-title="The third toggle">...</li>
</ul>

<script type="text/javascript">
  ready(function() {
    each('.js-toggles', function(el) {
      new Toggles(el, {
        // Options go here
      });
    });
  });
</script>

Options

Options can be passed via data attributes or JavaScript.

Name Type Default Description
initial number -1 The index of the toggle to open on initialization.
accordion boolean false True if the toggle group should behave as an accordion.
activeClass string 'text-primary' The class name(s) to apply to an active toggle heading.
template string
null
null The name of the template to use.
templateData object {} Additional data to provide to the template rendering function.

For data attributes, append the option name to data- and use kebab case instead of camel case.

Events

Class Properties
toggles:render Fires when the toggles markup has been rendered and inserted into the DOM.

Related extensions

Animations and transitions Free

Animations and transitions

Add engaging animation and transition effects to elements.

Carousels Free

Carousels

Present content in well defined and easy to follow steps.

Content blocks and icons Free

Content blocks and icons

Display icons against categories, sections and articles.