tabs.mdx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. ---
  2. title: Tabs
  3. summary: 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. description: Organize content with interactive tabs.
  6. ---
  7. ## Default markup
  8. 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.
  9. ```html example centered columns={1} height="20rem"
  10. <div class="card">
  11. <div class="card-header">
  12. <ul class="nav nav-tabs card-header-tabs" data-bs-toggle="tabs">
  13. <li class="nav-item">
  14. <a href="#tabs-home-ex1" class="nav-link active" data-bs-toggle="tab">Home</a>
  15. </li>
  16. <li class="nav-item">
  17. <a href="#tabs-profile-ex1" class="nav-link" data-bs-toggle="tab">Profile</a>
  18. </li>
  19. </ul>
  20. </div>
  21. <div class="card-body">
  22. <div class="tab-content">
  23. <div class="tab-pane active show" id="tabs-home-ex1">
  24. <h4>Home tab</h4>
  25. <div>
  26. Cursus turpis vestibulum, dui in pharetra vulputate id sed non turpis ultricies fringilla
  27. at sed facilisis lacus pellentesque purus nibh
  28. </div>
  29. </div>
  30. <div class="tab-pane" id="tabs-profile-ex1">
  31. <h4>Profile tab</h4>
  32. <div>
  33. Fringilla egestas nunc quis tellus diam rhoncus ultricies tristique enim at diam, sem nunc
  34. amet, pellentesque id egestas velit sed
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. ```
  41. ## Tabs with icons
  42. Add icons to your tab labels, if you want to use a visual element and make the tab content easier to identify.
  43. ```html example centered columns={1} height="20rem"
  44. <div class="card">
  45. <div class="card-header">
  46. <ul class="nav nav-tabs card-header-tabs" data-bs-toggle="tabs">
  47. <li class="nav-item">
  48. <a href="#tabs-home-ex2" class="nav-link active" data-bs-toggle="tab">
  49. <svg
  50. xmlns="http://www.w3.org/2000/svg"
  51. class="icon me-2"
  52. width="24"
  53. height="24"
  54. viewBox="0 0 24 24"
  55. stroke-width="2"
  56. stroke="currentColor"
  57. fill="none"
  58. stroke-linecap="round"
  59. stroke-linejoin="round"
  60. >
  61. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  62. <polyline points="5 12 3 12 12 3 21 12 19 12" />
  63. <path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7" />
  64. <path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v6" />
  65. </svg>
  66. Home
  67. </a>
  68. </li>
  69. <li class="nav-item">
  70. <a href="#tabs-profile-ex2" class="nav-link" data-bs-toggle="tab">
  71. <svg
  72. xmlns="http://www.w3.org/2000/svg"
  73. class="icon me-2"
  74. width="24"
  75. height="24"
  76. viewBox="0 0 24 24"
  77. stroke-width="2"
  78. stroke="currentColor"
  79. fill="none"
  80. stroke-linecap="round"
  81. stroke-linejoin="round"
  82. >
  83. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  84. <circle cx="12" cy="7" r="4" />
  85. <path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2" />
  86. </svg>
  87. Profile
  88. </a>
  89. </li>
  90. <li class="nav-item ms-auto">
  91. <a href="#tabs-settings-ex2" class="nav-link" title="Settings" data-bs-toggle="tab">
  92. <svg
  93. xmlns="http://www.w3.org/2000/svg"
  94. class="icon"
  95. width="24"
  96. height="24"
  97. viewBox="0 0 24 24"
  98. stroke-width="2"
  99. stroke="currentColor"
  100. fill="none"
  101. stroke-linecap="round"
  102. stroke-linejoin="round"
  103. >
  104. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  105. <path
  106. 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"
  107. />
  108. <circle cx="12" cy="12" r="3" />
  109. </svg>
  110. </a>
  111. </li>
  112. </ul>
  113. </div>
  114. <div class="card-body">
  115. <div class="tab-content">
  116. <div class="tab-pane active show" id="tabs-home-ex2">
  117. <h4>Home tab</h4>
  118. <div>
  119. Cursus turpis vestibulum, dui in pharetra vulputate id sed non turpis ultricies fringilla
  120. at sed facilisis lacus pellentesque purus nibh
  121. </div>
  122. </div>
  123. <div class="tab-pane" id="tabs-profile-ex2">
  124. <h4>Profile tab</h4>
  125. <div>
  126. Fringilla egestas nunc quis tellus diam rhoncus ultricies tristique enim at diam, sem nunc
  127. amet, pellentesque id egestas velit sed
  128. </div>
  129. </div>
  130. <div class="tab-pane" id="tabs-settings-ex2">
  131. <h4>Settings tab</h4>
  132. <div>
  133. Donec ac vitae diam amet vel leo egestas consequat rhoncus in luctus amet, facilisi sit
  134. mauris accumsan nibh habitant senectus
  135. </div>
  136. </div>
  137. </div>
  138. </div>
  139. </div>
  140. ```
  141. ## Tabs only with icons
  142. Use tabs without label names to save space and make the tab content easy to recognize for international users.
  143. ```html example centered columns={1} height="20rem"
  144. <div class="card">
  145. <div class="card-header">
  146. <ul class="nav nav-tabs card-header-tabs" data-bs-toggle="tabs">
  147. <li class="nav-item">
  148. <a href="#tabs-home-ex3" class="nav-link active" data-bs-toggle="tab">
  149. <svg
  150. xmlns="http://www.w3.org/2000/svg"
  151. class="icon"
  152. width="24"
  153. height="24"
  154. viewBox="0 0 24 24"
  155. stroke-width="2"
  156. stroke="currentColor"
  157. fill="none"
  158. stroke-linecap="round"
  159. stroke-linejoin="round"
  160. >
  161. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  162. <polyline points="5 12 3 12 12 3 21 12 19 12" />
  163. <path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7" />
  164. <path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v6" />
  165. </svg>
  166. </a>
  167. </li>
  168. <li class="nav-item">
  169. <a href="#tabs-profile-ex3" class="nav-link" data-bs-toggle="tab">
  170. <svg
  171. xmlns="http://www.w3.org/2000/svg"
  172. class="icon"
  173. width="24"
  174. height="24"
  175. viewBox="0 0 24 24"
  176. stroke-width="2"
  177. stroke="currentColor"
  178. fill="none"
  179. stroke-linecap="round"
  180. stroke-linejoin="round"
  181. >
  182. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  183. <circle cx="12" cy="7" r="4" />
  184. <path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2" />
  185. </svg>
  186. </a>
  187. </li>
  188. <li class="nav-item ms-auto">
  189. <a href="#tabs-settings-ex3" class="nav-link" title="Settings" data-bs-toggle="tab">
  190. <svg
  191. xmlns="http://www.w3.org/2000/svg"
  192. class="icon"
  193. width="24"
  194. height="24"
  195. viewBox="0 0 24 24"
  196. stroke-width="2"
  197. stroke="currentColor"
  198. fill="none"
  199. stroke-linecap="round"
  200. stroke-linejoin="round"
  201. >
  202. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  203. <path
  204. 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"
  205. />
  206. <circle cx="12" cy="12" r="3" />
  207. </svg>
  208. </a>
  209. </li>
  210. </ul>
  211. </div>
  212. <div class="card-body">
  213. <div class="tab-content">
  214. <div class="tab-pane active show" id="tabs-home-ex3">
  215. <h4>Home tab</h4>
  216. <div>
  217. Cursus turpis vestibulum, dui in pharetra vulputate id sed non turpis ultricies fringilla
  218. at sed facilisis lacus pellentesque purus nibh
  219. </div>
  220. </div>
  221. <div class="tab-pane" id="tabs-profile-ex3">
  222. <h4>Profile tab</h4>
  223. <div>
  224. Fringilla egestas nunc quis tellus diam rhoncus ultricies tristique enim at diam, sem nunc
  225. amet, pellentesque id egestas velit sed
  226. </div>
  227. </div>
  228. <div class="tab-pane" id="tabs-settings-ex3">
  229. <h4>Settings tab</h4>
  230. <div>
  231. Donec ac vitae diam amet vel leo egestas consequat rhoncus in luctus amet, facilisi sit
  232. mauris accumsan nibh habitant senectus
  233. </div>
  234. </div>
  235. </div>
  236. </div>
  237. </div>
  238. ```
  239. ## Tabs with dropdown
  240. Make one or more of your tabs into a dropdown to add more options within one element.
  241. ```html example centered columns={1} height="20rem"
  242. <div class="card">
  243. <div class="card-header">
  244. <ul class="nav nav-tabs card-header-tabs" data-bs-toggle="tabs">
  245. <li class="nav-item">
  246. <a href="#tabs-home-ex4" class="nav-link active" data-bs-toggle="tab">Home</a>
  247. </li>
  248. <li class="nav-item">
  249. <a href="#tabs-profile-ex4" class="nav-link" data-bs-toggle="tab">Profile</a>
  250. </li>
  251. <li class="nav-item dropdown">
  252. <a
  253. class="nav-link dropdown-toggle"
  254. data-bs-toggle="dropdown"
  255. role="button"
  256. aria-haspopup="true"
  257. aria-expanded="false"
  258. >Dropdown</a
  259. >
  260. <div class="dropdown-menu">
  261. <a class="dropdown-item" href="#"> Action </a>
  262. <a class="dropdown-item" href="#"> Another action </a>
  263. </div>
  264. </li>
  265. </ul>
  266. </div>
  267. <div class="card-body">
  268. <div class="tab-content">
  269. <div class="tab-pane active show" id="tabs-home-ex4">
  270. <h4>Home tab</h4>
  271. <div>
  272. Cursus turpis vestibulum, dui in pharetra vulputate id sed non turpis ultricies fringilla
  273. at sed facilisis lacus pellentesque purus nibh
  274. </div>
  275. </div>
  276. <div class="tab-pane" id="tabs-profile-ex4">
  277. <h4>Profile tab</h4>
  278. <div>
  279. Fringilla egestas nunc quis tellus diam rhoncus ultricies tristique enim at diam, sem nunc
  280. amet, pellentesque id egestas velit sed
  281. </div>
  282. </div>
  283. </div>
  284. </div>
  285. </div>
  286. ```
  287. ## Full-width tabs
  288. Add the `.nav-fill` class to make the tabs take up the full space of the parent element.
  289. ```html example centered columns={1} height="20rem"
  290. <div class="card">
  291. <div class="card-header">
  292. <ul class="nav nav-tabs card-header-tabs nav-fill" data-bs-toggle="tabs">
  293. <li class="nav-item">
  294. <a href="#tabs-home-ex5" class="nav-link active" data-bs-toggle="tab">
  295. <svg
  296. xmlns="http://www.w3.org/2000/svg"
  297. class="icon"
  298. width="24"
  299. height="24"
  300. viewBox="0 0 24 24"
  301. stroke-width="2"
  302. stroke="currentColor"
  303. fill="none"
  304. stroke-linecap="round"
  305. stroke-linejoin="round"
  306. >
  307. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  308. <polyline points="5 12 3 12 12 3 21 12 19 12" />
  309. <path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7" />
  310. <path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v6" />
  311. </svg>
  312. </a>
  313. </li>
  314. <li class="nav-item">
  315. <a href="#tabs-profile-ex5" class="nav-link" data-bs-toggle="tab">
  316. <svg
  317. xmlns="http://www.w3.org/2000/svg"
  318. class="icon"
  319. width="24"
  320. height="24"
  321. viewBox="0 0 24 24"
  322. stroke-width="2"
  323. stroke="currentColor"
  324. fill="none"
  325. stroke-linecap="round"
  326. stroke-linejoin="round"
  327. >
  328. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  329. <circle cx="12" cy="7" r="4" />
  330. <path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2" />
  331. </svg>
  332. </a>
  333. </li>
  334. <li class="nav-item">
  335. <a href="#tabs-activity-ex5" class="nav-link" data-bs-toggle="tab">
  336. <svg
  337. xmlns="http://www.w3.org/2000/svg"
  338. class="icon"
  339. width="24"
  340. height="24"
  341. viewBox="0 0 24 24"
  342. stroke-width="2"
  343. stroke="currentColor"
  344. fill="none"
  345. stroke-linecap="round"
  346. stroke-linejoin="round"
  347. >
  348. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  349. <path d="M3 12h4l3 8l4 -16l3 8h4" />
  350. </svg>
  351. </a>
  352. </li>
  353. </ul>
  354. </div>
  355. <div class="card-body">
  356. <div class="tab-content">
  357. <div class="tab-pane active show" id="tabs-home-ex5">
  358. <h4>Home tab</h4>
  359. <div>
  360. Cursus turpis vestibulum, dui in pharetra vulputate id sed non turpis ultricies fringilla
  361. at sed facilisis lacus pellentesque purus nibh
  362. </div>
  363. </div>
  364. <div class="tab-pane" id="tabs-profile-ex5">
  365. <h4>Profile tab</h4>
  366. <div>
  367. Fringilla egestas nunc quis tellus diam rhoncus ultricies tristique enim at diam, sem nunc
  368. amet, pellentesque id egestas velit sed
  369. </div>
  370. </div>
  371. <div class="tab-pane" id="tabs-activity-ex5">
  372. <h4>Activity tab</h4>
  373. <div>
  374. Donec ac vitae diam amet vel leo egestas consequat rhoncus in luctus amet, facilisi sit
  375. mauris accumsan nibh habitant senectus
  376. </div>
  377. </div>
  378. </div>
  379. </div>
  380. </div>
  381. ```