Performance: Nav tabs and pills
This affects page load speed and interaction responsiveness by how navigation elements are rendered and updated in the browser.
<ul class="nav nav-tabs" role="tablist"> <li class="nav-item"><button class="nav-link active" id="tab1-tab" data-bs-toggle="tab" data-bs-target="#tab1" type="button" role="tab" aria-controls="tab1" aria-selected="true">Tab 1</button></li> <li class="nav-item"><button class="nav-link" id="tab2-tab" data-bs-toggle="tab" data-bs-target="#tab2" type="button" role="tab" aria-controls="tab2" aria-selected="false">Tab 2</button></li> </ul> <div class="tab-content"> <div class="tab-pane fade show active" id="tab1" role="tabpanel" aria-labelledby="tab1-tab">Lightweight initial content or lazy loaded content</div> <div class="tab-pane fade" id="tab2" role="tabpanel" aria-labelledby="tab2-tab" hidden></div> </div>
<ul class="nav nav-tabs"> <li class="nav-item"><a class="nav-link active" href="#tab1" data-bs-toggle="tab">Tab 1</a></li> <li class="nav-item"><a class="nav-link" href="#tab2" data-bs-toggle="tab">Tab 2</a></li> <!-- many more tabs --> </ul> <div class="tab-content"> <div class="tab-pane fade show active" id="tab1">Heavy content with images and scripts</div> <div class="tab-pane fade" id="tab2">Heavy content with images and scripts</div> <!-- many more tab panes --> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| All tabs content rendered at once | High (many nodes) | Multiple on tab switch | High due to repaint | [X] Bad |
| Lazy load tab content on demand | Low (only active tab nodes) | Single on tab switch | Low repaint cost | [OK] Good |
nav-tabs and nav-pills in Bootstrap navigation?nav-tabs creates a tab-like navigation with rectangular borders around each item.nav-pillsnav-pills styles navigation links as rounded pills, giving a softer look.nav-tabs shows tabs with borders, nav-pills shows rounded pill-shaped links. -> Option Bnav-pills combined with nav.<ul class='nav nav-pills'> uses nav nav-pills, which is correct. Others have incorrect or non-existent classes.nav nav-pills for pills [OK]<ul class='nav nav-tabs' role='tablist'>
<li class='nav-item'>
<a class='nav-link active' href='#home' role='tab' aria-selected='true'>Home</a>
</li>
<li class='nav-item'>
<a class='nav-link' href='#profile' role='tab' aria-selected='false'>Profile</a>
</li>
</ul>nav-tabs class creates tab style navigation. The nav-link active class highlights the 'Home' tab as active.<ul class='nav nav-pills'>
<li class='nav-item'>
<a class='nav-link active' data-toggle='tab' href='#home'>Home</a>
</li>
<li class='nav-item'>
<a class='nav-link' data-toggle='tab' href='#profile'>Profile</a>
</li>
</ul>data-toggle with data-bs-toggle for JavaScript plugins.nav-pills is valid, href can use fragment IDs, and nav-item belongs on li.data-toggle should be data-bs-toggle in Bootstrap 5+. -> Option Anav nav-pills on ul with role='tablist' for accessibility.id, data-bs-toggle='pill', href to panel, role='tab', aria-controls, and aria-selected.nav-link active and aria-selected='true'.<ul class='nav nav-pills' role='tablist'> <li class='nav-item'> <a class='nav-link active' id='home-tab' data-bs-toggle='pill' href='#home' role='tab' aria-controls='home' aria-selected='true'>Home</a> </li> </ul> -> Option DPass the test and this pattern moves unknown