Skip to content
Tayyab RehmanDev

ACF Tab Fields vs Frontend Tabs: Build the Right Interface

Learn what the ACF Tab field does, model frontend tab content with a Repeater, and implement keyboard-accessible tabs.

ACF editor tabs organize fields while frontend tabs are separate accessible buttons and panels

ACF's Tab field organizes fields in the WordPress editing screen; it does not create a tab interface on the public website. To show frontend tabs, store the tab labels and panel content in a Repeater or another suitable field, render real buttons and panels, and add the expected keyboard behavior. Confusing the editor-only field with visitor-facing UI is a common reason a developer sees a field group in wp-admin but no tabs on the page.

Use a frontend tab interface only when people need to switch between related panels in the same context. If visitors need to compare all information at once, normal headings or an accordion can be easier to scan, especially on small screens or for assistive technology.

What does the ACF Tab field do?

The ACF Tab field separates a large field group into visual sections inside the post editor. It can make a content form easier for editors to navigate, but it is a layout aid for the admin form, not a value that contains frontend content. Adding a Tab field alone does not output a navigation bar or hide and reveal page content.

To organize the editor and create actual page tabs, use separate fields for separate purposes. For example, add an editor tab called “Project details” before project metadata, then add a Repeater called content_tabs with subfields label and content. This gives editors clear sections while supplying structured content to the theme.

How should tab content be modeled in ACF?

For a fixed set of panels that always exists, separate fields such as overview, specifications, and delivery can be more predictable. For an editor-managed variable number of panels, a Repeater makes sense:

FieldACF typeExample
content_tabsRepeaterOne row per panel
labelText“Overview”
contentWYSIWYG or textareaThe panel's content

Set sensible minimum and maximum rows and explain that labels should be short. If the content needs different structures in different rows, consider Flexible Content instead. The guide to ACF Flexible Content template parts explains when to use layouts rather than repeated identical rows.

How do you output accessible tab markup?

The WAI-ARIA tabs pattern uses a container with role="tablist", buttons with role="tab", and panels with role="tabpanel". Each tab references its panel with aria-controls, and each panel points back using aria-labelledby. A tab set also needs an active state, a focus-management model, and keyboard support; adding roles without behavior is not a complete implementation.

The following PHP example assumes the Repeater returns rows with text label and formatted HTML content. Place it in the relevant template and adjust the field names to match your ACF configuration:

php
<?php
$tabs = get_field( 'content_tabs', get_the_ID() );
$tabs = is_array( $tabs )
    ? array_values(
        array_filter(
            $tabs,
            function ( $tab ) {
                return is_array( $tab )
                    && isset( $tab['label'] )
                    && is_string( $tab['label'] )
                    && '' !== trim( $tab['label'] );
            }
        )
    )
    : array();
$tabs_id = wp_unique_id( 'content-tabs-' );

if ( $tabs ) :
    ?>
    <div class="content-tabs" data-tabs>
        <div role="tablist" aria-label="Project information" hidden>
            <?php foreach ( $tabs as $index => $tab ) : ?>
                <?php
                $label = isset( $tab['label'] ) && is_string( $tab['label'] )
                    ? trim( $tab['label'] )
                    : '';
                $tab_id = $tabs_id . '-tab-' . $index;
                $panel_id = $tabs_id . '-panel-' . $index;
                ?>
                <button
                    id="<?php echo esc_attr( $tab_id ); ?>"
                    type="button"
                    role="tab"
                    aria-selected="<?php echo 0 === $index ? 'true' : 'false'; ?>"
                    aria-controls="<?php echo esc_attr( $panel_id ); ?>"
                    tabindex="<?php echo 0 === $index ? '0' : '-1'; ?>"
                >
                    <?php echo esc_html( $label ); ?>
                </button>
            <?php endforeach; ?>
        </div>
        <?php foreach ( $tabs as $index => $tab ) : ?>
            <?php
            $label = isset( $tab['label'] ) && is_string( $tab['label'] )
                ? trim( $tab['label'] )
                : '';
            $tab_id = $tabs_id . '-tab-' . $index;
            $panel_id = $tabs_id . '-panel-' . $index;
            $content = isset( $tab['content'] ) && is_string( $tab['content'] )
                ? $tab['content']
                : '';
            ?>
            <section id="<?php echo esc_attr( $panel_id ); ?>">
                <h3 class="content-tabs__fallback-title"><?php echo esc_html( $label ); ?></h3>
                <?php echo wp_kses_post( $content ); ?>
            </section>
        <?php endforeach; ?>
    </div>
<?php endif; ?>

The example escapes labels and IDs, and filters rich text through wp_kses_post(). If the Repeater can contain rows with empty labels, ensure the active state is based on the first valid row rather than blindly using index zero; alternatively make labels required and validate that existing content complies. A production component should also avoid duplicate IDs if multiple tab sets can render for the same post. Give each set a unique template instance identifier.

How do you add keyboard interaction?

For a standard horizontal tab set, Left and Right Arrow move focus between tabs; Home and End can move to the first and last tab. Activating a tab updates aria-selected, tabindex, and the visible panel. This code uses manual activation: arrow keys move focus, while Enter or Space activates the focused tab. That can be appropriate if changing panels triggers expensive content or network work.

js
document.querySelectorAll("[data-tabs]").forEach((group) => {
  const tabs = Array.from(group.querySelectorAll('[role="tab"]'));
  const tablist = group.querySelector('[role="tablist"]');
  const entries = tabs.map((tab) => {
    const panel = document.getElementById(tab.getAttribute("aria-controls"));
    return { tab, panel };
  }).filter(({ panel }) => panel && group.contains(panel));

  if (!tablist || entries.length === 0) return;

  const activate = (activeTab, moveFocus = false) => {
    entries.forEach(({ tab, panel }) => {
      const selected = tab === activeTab;
      tab.setAttribute("aria-selected", String(selected));
      tab.tabIndex = selected ? 0 : -1;
      panel.hidden = !selected;
    });
    if (moveFocus) activeTab.focus();
  };

  entries.forEach(({ tab }, index) => {
    tab.addEventListener("click", () => activate(tab));
    tab.addEventListener("keydown", (event) => {
      let nextIndex;
      if (event.key === "ArrowRight") nextIndex = (index + 1) % tabs.length;
      if (event.key === "ArrowLeft") nextIndex = (index - 1 + tabs.length) % tabs.length;
      if (event.key === "Home") nextIndex = 0;
      if (event.key === "End") nextIndex = tabs.length - 1;
      if (nextIndex !== undefined) {
        event.preventDefault();
        tabs[nextIndex].focus();
      }
      if (event.key === "Enter" || event.key === " ") {
        event.preventDefault();
        activate(tab);
      }
    });
  });

  entries.forEach(({ panel, tab }) => {
    panel.setAttribute("role", "tabpanel");
    panel.setAttribute("aria-labelledby", tab.id);
    panel.tabIndex = 0;
    panel.querySelector(".content-tabs__fallback-title")?.remove();
  });
  activate(entries[0].tab);
  tablist.hidden = false;
});

The tablist starts hidden and each panel begins visible with a heading. JavaScript reveals the controls and hides inactive panels only after the relationships are initialized, so content remains available if the script fails. The example filters out rows without a label and creates a unique ID prefix. Use a type="button" control so a tab inside a form does not submit it accidentally.

Accessible tab buttons link to labeled content panels and keyboard controls manage focus and selection

If panels load immediately and are inexpensive, automatic activation on arrow-key focus may be a better user experience; implement that deliberately and test it. If panel content is not present until a request completes, manual activation avoids firing a request for every arrow key.

How can you make tabs usable on mobile and without JavaScript?

Without JavaScript, a tab interface that hides all but one panel can make content inaccessible. This example renders all panel content with headings and hides the button strip until JavaScript establishes the tab-panel relationships. If initialization fails, all the content remains readable as sections. Once initialized, the script removes the fallback headings and reveals the working controls.

On narrow screens, let the tab strip scroll horizontally or wrap in a way that preserves visible focus. Do not shrink labels until they are unreadable. Ensure keyboard focus is visible, text contrast is sufficient, and panels have a useful heading or relationship to the tab. Test screen-reader announcements, keyboard navigation, zoom, and touch targets. If users benefit from seeing all sections in a single scroll, use normal headings or <details> instead of tabs.

Should tabs activate on focus or on click?

The ARIA pattern supports automatic or manual activation. With automatic activation, moving focus with arrow keys also switches the panel. This feels responsive when panel content is already in the page and changes instantly. With manual activation, arrow keys move focus and Enter or Space changes the panel. That avoids loading content or running expensive work just because a visitor explored the tab labels.

Choose one model and make the implementation match it. For automatic activation, call the same panel-selection function from the arrow-key handler after focusing the next button. For manual activation, keep the focused button distinct from the selected one and ensure the user can activate it with Enter or Space. A mixed model where focus moves but the panel silently changes can disorient users.

Use a normal button for each tab and do not add role="button" to a non-interactive element. Avoid putting links or other interactive controls inside the tab label. If a tab panel contains a form, its controls should remain in the expected focus sequence. When the set is vertical, adjust the arrow keys to match the orientation and set aria-orientation="vertical" on the tablist.

Testing checklist

  1. Confirm the ACF Tab field is used only to organize the editing screen.
  2. Add multiple frontend tab rows and verify labels and content save.
  3. Test first, last, and empty rows; long labels; repeated components; and missing content.
  4. Navigate with arrow keys, Home, End, Enter, and Space.
  5. Test with JavaScript disabled, mobile viewport, browser zoom, and a screen reader.
  6. Confirm all rich text is filtered and all IDs are unique.

Read ACF's Tab field, Repeater field, and Flexible Content documentation. Follow the W3C's ARIA Authoring Practices tabs pattern for interaction expectations. For the larger PHP file that owns the page, choose the correct route with WordPress template hierarchy guidance.

Tell me about your project

Share what you’re building, what you need help with, and your timeline.