In this tutorial, we’ll go over how to create SEO-friendly tabs using flex and jQuery.
Our code will be divided into three parts.
HTML Code
First, the HTML code — the foundation we start with:
<div class="tabs" data-tabs="name"> <ul class="tab-items"> <li class="tab__item active" data-tab-item="tab-item-1"> Tab 1 </li> <li class="tab__item" data-tab-item="tab-item-2"> Tab 2 </li> <li class="tab__item" data-tab-item="tab-item-3"> Tab 3 </li> </ul> <div class="tab-contents"> <div class="tab__content active" data-tab-content="tab-item-1"> Contents of Tab 1 </div> <div class="tab__content" data-tab-content="tab-item-2"> Contents of Tab 2 </div> <div class="tab__content" data-tab-content="tab-item-3"> Tab content 3 </div> </div> </div>
Roughly speaking, our code consists of three sections:
- A wrapper for the tab group, defined by the data attribute
data-tabs. - The tabs themselves. Each tab has its own identifier defined by
data-tab-item. This value must match one of thedata-tab-contentattributes in the content blocks. - The tab content blocks, wrapped in a container with the class
tab-contents. Each content block has adata-tab-contentattribute, which must match one of the tab item values. These attributes are used to map which tab displays which content.




