Creating tabs

Tabs group related content into panels that visitors can switch between without losing their place. Add them straight from the Zendesk article editor toolbar, and our themes style them to match the rest of your help center.

On this page

Tabs make it easier for visitors to find what they’re after by grouping related content, such as instructions for different operating systems, products or roles. The Zendesk article editor now includes native tabs that you can add and edit straight from the toolbar, and our themes style them to match the rest of your help center. We recommend using them for all new content.

The list-based tabs used in earlier versions of our themes are still supported, so existing articles don’t need to change. You’ll find their instructions in the Legacy elements tab.

Native article components are supported in version 4.0.0 or later of our themes. If you’re using an earlier version, use the legacy elements instead.

Adding tabs

  1. Create a new article or edit an existing one in your help center or Knowledge admin, and place your cursor where the tabs should appear.

  2. Click the Article components button in the editor toolbar and select Tabs.

  3. Enter a short title for the first tab, followed by its content. You can format the content using the editor toolbar as usual.

  4. Click the Add tab icon (+) in the tabs toolbar to add another tab. Use the Move up and Move down icons to reorder tabs, and the Remove icon to delete one.

  5. Expand the tab that should be selected when the page loads. Visitors will see this tab first.

  6. Click Save.

To move a tab group, hover over it and drag the handle. To remove it, click the handle to select the group and press Delete. You can add as many tab groups to an article as you need.

Native tabs

The editor creates this markup for you. Each tab is a <details> element with a <summary> for its title, which Zendesk turns into a tab bar when the page loads. If scripts are unavailable, visitors still see every tab’s content in order.

Linking to a tab

A link to the id of any element inside a tab, such as a heading, selects that tab and scrolls to the element. This makes it possible to link visitors straight to the instructions that apply to them.

Styling tabs

The tab color, border color, border width, corner radius and margin can be changed in the Tabs section of the visual builder’s Formatting elements panel.

You can also write your own custom CSS, for example:

/* Change the color of the selected tab to red */
.content .wysiwyg-tabs-active {
  --zd-wysiwyg-tabs-color: red;
}

/* Change the color of text in a tab to blue */
.content .wysiwyg-tabs .wysiwyg-disclosure-content {
  color: blue;
}

Adding legacy tabs to article content

Because the tabs script is built into all of our themes, there are no additional scripts to include or code to write.

The first step is to create a numbered or bulleted list in your article where each list item contains the content that will be contained within its own tab. If you have a lot of content to display in each tab, or content that contains headings and other custom elements, we recommend using the HTML (source code) view within the article editor.

The list itself will be a <ol> or <ul> element, with child list items represented as <li> elements.

Once you’ve added all of your content to the list add a class name of .js-tabs to the list and a title attribute to each list item. For example:

<ul class="js-tabs">
  <li title="The first tab title">...</li>
  <li title="The second tab title">...</li>
  <li title="The third tab title">...</li>
</ul>

Where:

  • The .js-tabs class name specifies that we’d like to convert this list into dynamic tabs.
  • The title attribute specifies the title for each tab.
  • The content of each list item is converted into its own tab.

This approach ensures a separation between your content and how it’s displayed to visitors. If you ever decide to disable tabs for a given list, change themes or export your content you’ll see a simple, uncontaminated list.

In version 4.0.0 of our themes you can also use data-element="tabs" in place of the class name, and give a tab its title with a data-title attribute or a heading with the .tab-heading class instead of the title attribute. Legacy tabs are rendered using the same markup as native tabs, so both look identical in your help center.

Styling legacy tabs

Because legacy tabs are rendered using the same markup as native tabs, they pick up the same styles, including those set in the visual builder. The custom CSS examples in the Article components tab apply to both.

Using a custom micro-template

For the more adventurous among you, you can create your own custom micro-template. A custom template replaces the default rendering for both native and legacy tabs.

A custom template allows you to change not just the appearance of the tabs, but their underlying HTML structure and behavior. Below is an example of a custom tabs template that you could use that not only changes the size and appearance of the tabs, but introduces custom icons:

Large, justified tabs with icons

An optional fade effect can be added by using .fade on each tab. If the fade effect is applied the active tab must also have .is-shown in order to be visible.

Version 4.0.0 of our themes includes a ready-made tabs template, commented out, in the Document head template (document_head.hbs). Remove the comment tags around the tmpl-tabs template to use it as a starting point. The tabs script looks for a micro-template with an id of tabs by default, so adding one to the Document head, Article page (article_page.hbs) or Footer (footer.hbs) template will ensure that it’s used for all tabs within your article content.

<script type="text/template" id="tmpl-tabs">
  ...
</script>

The template receives the tab group’s id, the index of the initial tab, the activeClass and a list of children. Each child has an id, a title and the tab’s content as innerHTML, whether the tab group was created with the article editor or as a legacy list.

Questions or feedback about this article? Let us know