tabs.mdx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. ---
  2. title: Tabs
  3. description: Tabs allow users to alternate between equally important views within the same context. By dividing content into meaningful sections, they improve its organization and make it easy for users to navigate.
  4. bootstrapLink: components/navs/
  5. ---
  6. ## Default markup
  7. Use tabs to let users access different sections within one context quickly and with ease. In the default design, the current tab is highlighted, which makes the interface clear and user-friendly.
  8. ```html code example centered columns={1} height="20rem"
  9. <div class="card">
  10. <div class="card-header">
  11. <ul class="nav nav-tabs card-header-tabs" data-bs-toggle="tabs">
  12. <li class="nav-item">
  13. <a href="#tabs-home-ex1" class="nav-link active" data-bs-toggle="tab">Home</a>
  14. </li>
  15. <li class="nav-item">
  16. <a href="#tabs-profile-ex1" class="nav-link" data-bs-toggle="tab">Profile</a>
  17. </li>
  18. </ul>
  19. </div>
  20. <div class="card-body">
  21. <div class="tab-content">
  22. <div class="tab-pane active show" id="tabs-home-ex1">
  23. <h4>Home tab</h4>
  24. <div>Cursus turpis vestibulum, dui in pharetra vulputate id sed non turpis ultricies fringilla at sed facilisis lacus pellentesque purus nibh</div>
  25. </div>
  26. <div class="tab-pane" id="tabs-profile-ex1">
  27. <h4>Profile tab</h4>
  28. <div>Fringilla egestas nunc quis tellus diam rhoncus ultricies tristique enim at diam, sem nunc amet, pellentesque id egestas velit sed</div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. ```
  34. ## Tabs with icons
  35. Add icons to your tab labels, if you want to use a visual element and make the tab content easier to identify.
  36. ```html example code centered columns={1} height="20rem"
  37. <div class="card">
  38. <div class="card-header">
  39. <ul class="nav nav-tabs card-header-tabs" data-bs-toggle="tabs">
  40. <li class="nav-item">
  41. <a href="#tabs-home-ex2" class="nav-link active" data-bs-toggle="tab"><svg xmlns="http://www.w3.org/2000/svg" class="icon me-2" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  42. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  43. <polyline points="5 12 3 12 12 3 21 12 19 12" />
  44. <path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7" />
  45. <path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v6" />
  46. </svg> Home</a>
  47. </li>
  48. <li class="nav-item">
  49. <a href="#tabs-profile-ex2" class="nav-link" data-bs-toggle="tab"><svg xmlns="http://www.w3.org/2000/svg" class="icon me-2" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  50. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  51. <circle cx="12" cy="7" r="4" />
  52. <path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2" />
  53. </svg> Profile</a>
  54. </li>
  55. <li class="nav-item ms-auto">
  56. <a href="#tabs-settings-ex2" class="nav-link" title="Settings" data-bs-toggle="tab"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  57. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  58. <path d="M10.325 4.317c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756 .426 1.756 2.924 0 3.35a1.724 1.724 0 0 0 -1.066 2.573c.94 1.543 -.826 3.31 -2.37 2.37a1.724 1.724 0 0 0 -2.572 1.065c-.426 1.756 -2.924 1.756 -3.35 0a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065z" />
  59. <circle cx="12" cy="12" r="3" />
  60. </svg>
  61. </a>
  62. </li>
  63. </ul>
  64. </div>
  65. <div class="card-body">
  66. <div class="tab-content">
  67. <div class="tab-pane active show" id="tabs-home-ex2">
  68. <h4>Home tab</h4>
  69. <div>Cursus turpis vestibulum, dui in pharetra vulputate id sed non turpis ultricies fringilla at sed facilisis lacus pellentesque purus nibh</div>
  70. </div>
  71. <div class="tab-pane" id="tabs-profile-ex2">
  72. <h4>Profile tab</h4>
  73. <div>Fringilla egestas nunc quis tellus diam rhoncus ultricies tristique enim at diam, sem nunc amet, pellentesque id egestas velit sed</div>
  74. </div>
  75. <div class="tab-pane" id="tabs-settings-ex2">
  76. <h4>Settings tab</h4>
  77. <div>Donec ac vitae diam amet vel leo egestas consequat rhoncus in luctus amet, facilisi sit mauris accumsan nibh habitant senectus</div>
  78. </div>
  79. </div>
  80. </div>
  81. </div>
  82. ```
  83. ## Tabs only with icons
  84. Use tabs without label names to save space and make the tab content easy to recognize for international users.
  85. ```html code example centered columns={1} height="20rem"
  86. <div class="card">
  87. <div class="card-header">
  88. <ul class="nav nav-tabs card-header-tabs" data-bs-toggle="tabs">
  89. <li class="nav-item">
  90. <a href="#tabs-home-ex3" class="nav-link active" data-bs-toggle="tab">
  91. <svg xmlns="http://www.w3.org/2000/svg" class="icon " width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  92. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  93. <polyline points="5 12 3 12 12 3 21 12 19 12" />
  94. <path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7" />
  95. <path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v6" />
  96. </svg>
  97. </a>
  98. </li>
  99. <li class="nav-item">
  100. <a href="#tabs-profile-ex3" class="nav-link" data-bs-toggle="tab">
  101. <svg xmlns="http://www.w3.org/2000/svg" class="icon " width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  102. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  103. <circle cx="12" cy="7" r="4" />
  104. <path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2" />
  105. </svg>
  106. </a>
  107. </li>
  108. <li class="nav-item ms-auto">
  109. <a href="#tabs-settings-ex3" class="nav-link" title="Settings" data-bs-toggle="tab">
  110. <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  111. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  112. <path d="M10.325 4.317c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756 .426 1.756 2.924 0 3.35a1.724 1.724 0 0 0 -1.066 2.573c.94 1.543 -.826 3.31 -2.37 2.37a1.724 1.724 0 0 0 -2.572 1.065c-.426 1.756 -2.924 1.756 -3.35 0a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065z" />
  113. <circle cx="12" cy="12" r="3" />
  114. </svg>
  115. </a>
  116. </li>
  117. </ul>
  118. </div>
  119. <div class="card-body">
  120. <div class="tab-content">
  121. <div class="tab-pane active show" id="tabs-home-ex3">
  122. <h4>Home tab</h4>
  123. <div>Cursus turpis vestibulum, dui in pharetra vulputate id sed non turpis ultricies fringilla at sed facilisis lacus pellentesque purus nibh</div>
  124. </div>
  125. <div class="tab-pane" id="tabs-profile-ex3">
  126. <h4>Profile tab</h4>
  127. <div>Fringilla egestas nunc quis tellus diam rhoncus ultricies tristique enim at diam, sem nunc amet, pellentesque id egestas velit sed</div>
  128. </div>
  129. <div class="tab-pane" id="tabs-settings-ex3">
  130. <h4>Settings tab</h4>
  131. <div>Donec ac vitae diam amet vel leo egestas consequat rhoncus in luctus amet, facilisi sit mauris accumsan nibh habitant senectus</div>
  132. </div>
  133. </div>
  134. </div>
  135. </div>
  136. ```
  137. ## Tabs with dropdown
  138. Make one or more of your tabs into a dropdown to add more options within one element.
  139. ```html code example centered columns={1} height="20rem"
  140. <div class="card">
  141. <div class="card-header">
  142. <ul class="nav nav-tabs card-header-tabs" data-bs-toggle="tabs">
  143. <li class="nav-item">
  144. <a href="#tabs-home-ex4" class="nav-link active" data-bs-toggle="tab">Home</a>
  145. </li>
  146. <li class="nav-item">
  147. <a href="#tabs-profile-ex4" class="nav-link" data-bs-toggle="tab">Profile</a>
  148. </li>
  149. <li class="nav-item dropdown">
  150. <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown</a>
  151. <div class="dropdown-menu">
  152. <a class="dropdown-item" href="#">
  153. Action
  154. </a>
  155. <a class="dropdown-item" href="#">
  156. Another action
  157. </a>
  158. </div>
  159. </li>
  160. </ul>
  161. </div>
  162. <div class="card-body">
  163. <div class="tab-content">
  164. <div class="tab-pane active show" id="tabs-home-ex4">
  165. <h4>Home tab</h4>
  166. <div>Cursus turpis vestibulum, dui in pharetra vulputate id sed non turpis ultricies fringilla at sed facilisis lacus pellentesque purus nibh</div>
  167. </div>
  168. <div class="tab-pane" id="tabs-profile-ex4">
  169. <h4>Profile tab</h4>
  170. <div>Fringilla egestas nunc quis tellus diam rhoncus ultricies tristique enim at diam, sem nunc amet, pellentesque id egestas velit sed</div>
  171. </div>
  172. </div>
  173. </div>
  174. </div>
  175. ```
  176. ## Full-width tabs
  177. Add the `nav-fill` class to make the tabs take up the full space of the parent element.
  178. ```html code example centered columns={1} height="20rem"
  179. <div class="card">
  180. <div class="card-header">
  181. <ul class="nav nav-tabs card-header-tabs nav-fill" data-bs-toggle="tabs">
  182. <li class="nav-item">
  183. <a href="#tabs-home-ex5" class="nav-link active" data-bs-toggle="tab">
  184. <svg xmlns="http://www.w3.org/2000/svg" class="icon " width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  185. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  186. <polyline points="5 12 3 12 12 3 21 12 19 12" />
  187. <path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7" />
  188. <path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v6" />
  189. </svg>
  190. </a>
  191. </li>
  192. <li class="nav-item">
  193. <a href="#tabs-profile-ex5" class="nav-link" data-bs-toggle="tab">
  194. <svg xmlns="http://www.w3.org/2000/svg" class="icon " width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  195. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  196. <circle cx="12" cy="7" r="4" />
  197. <path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2" />
  198. </svg>
  199. </a>
  200. </li>
  201. <li class="nav-item">
  202. <a href="#tabs-activity-ex5" class="nav-link" data-bs-toggle="tab">
  203. <svg xmlns="http://www.w3.org/2000/svg" class="icon " width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  204. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  205. <path d="M3 12h4l3 8l4 -16l3 8h4" />
  206. </svg>
  207. </a>
  208. </li>
  209. </ul>
  210. </div>
  211. <div class="card-body">
  212. <div class="tab-content">
  213. <div class="tab-pane active show" id="tabs-home-ex5">
  214. <h4>Home tab</h4>
  215. <div>Cursus turpis vestibulum, dui in pharetra vulputate id sed non turpis ultricies fringilla at sed facilisis lacus pellentesque purus nibh</div>
  216. </div>
  217. <div class="tab-pane" id="tabs-profile-ex5">
  218. <h4>Profile tab</h4>
  219. <div>Fringilla egestas nunc quis tellus diam rhoncus ultricies tristique enim at diam, sem nunc amet, pellentesque id egestas velit sed</div>
  220. </div>
  221. <div class="tab-pane" id="tabs-activity-ex5">
  222. <h4>Activity tab</h4>
  223. <div>Donec ac vitae diam amet vel leo egestas consequat rhoncus in luctus amet, facilisi sit mauris accumsan nibh habitant senectus</div>
  224. </div>
  225. </div>
  226. </div>
  227. </div>
  228. ```