Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
---
2
layout: docs
3
title: Navs
4
description: Documentation and examples for how to use Bootstrap's included navigation components.
5
group: components
6
toc: true
7
---
8
 
9
## Base nav
10
 
11
Navigation available in Bootstrap share general markup and styles, from the base `.nav` class to the active and disabled states. Swap modifier classes to switch between each style.
12
 
13
The base `.nav` component is built with flexbox and provide a strong foundation for building all types of navigation components. It includes some style overrides (for working with lists), some link padding for larger hit areas, and basic disabled styling.
14
 
15
{{< callout info >}}
16
The base `.nav` component does not include any `.active` state. The following examples include the class, mainly to demonstrate that this particular class does not trigger any special styling.
17
{{< /callout >}}
18
 
19
{{< example >}}
20
<ul class="nav">
21
  <li class="nav-item">
22
    <a class="nav-link active" href="#">Active</a>
23
  </li>
24
  <li class="nav-item">
25
    <a class="nav-link" href="#">Link</a>
26
  </li>
27
  <li class="nav-item">
28
    <a class="nav-link" href="#">Link</a>
29
  </li>
30
  <li class="nav-item">
31
    <a class="nav-link disabled">Disabled</a>
32
  </li>
33
</ul>
34
{{< /example >}}
35
 
36
Classes are used throughout, so your markup can be super flexible. Use `<ul>`s like above, `<ol>` if the order of your items is important, or roll your own with a `<nav>` element. Because the `.nav` uses `display: flex`, the nav links behave the same as nav items would, but without the extra markup.
37
 
38
{{< example >}}
39
<nav class="nav">
40
  <a class="nav-link active" href="#">Active</a>
41
  <a class="nav-link" href="#">Link</a>
42
  <a class="nav-link" href="#">Link</a>
43
  <a class="nav-link disabled">Disabled</a>
44
</nav>
45
{{< /example >}}
46
 
47
## Available styles
48
 
49
Change the style of `.nav`s component with modifiers and utilities. Mix and match as needed, or build your own.
50
 
51
### Horizontal alignment
52
 
53
Change the horizontal alignment of your nav with [flexbox utilities]({{< docsref "/layout/grid#horizontal-alignment" >}}). By default, navs are left-aligned, but you can easily change them to center or right aligned.
54
 
55
Centered with `.justify-content-center`:
56
 
57
{{< example >}}
58
<ul class="nav justify-content-center">
59
  <li class="nav-item">
60
    <a class="nav-link active" href="#">Active</a>
61
  </li>
62
  <li class="nav-item">
63
    <a class="nav-link" href="#">Link</a>
64
  </li>
65
  <li class="nav-item">
66
    <a class="nav-link" href="#">Link</a>
67
  </li>
68
  <li class="nav-item">
69
    <a class="nav-link disabled">Disabled</a>
70
  </li>
71
</ul>
72
{{< /example >}}
73
 
74
Right-aligned with `.justify-content-end`:
75
 
76
{{< example >}}
77
<ul class="nav justify-content-end">
78
  <li class="nav-item">
79
    <a class="nav-link active" href="#">Active</a>
80
  </li>
81
  <li class="nav-item">
82
    <a class="nav-link" href="#">Link</a>
83
  </li>
84
  <li class="nav-item">
85
    <a class="nav-link" href="#">Link</a>
86
  </li>
87
  <li class="nav-item">
88
    <a class="nav-link disabled">Disabled</a>
89
  </li>
90
</ul>
91
{{< /example >}}
92
 
93
### Vertical
94
 
95
Stack your navigation by changing the flex item direction with the `.flex-column` utility. Need to stack them on some viewports but not others? Use the responsive versions (e.g., `.flex-sm-column`).
96
 
97
{{< example >}}
98
<ul class="nav flex-column">
99
  <li class="nav-item">
100
    <a class="nav-link active" href="#">Active</a>
101
  </li>
102
  <li class="nav-item">
103
    <a class="nav-link" href="#">Link</a>
104
  </li>
105
  <li class="nav-item">
106
    <a class="nav-link" href="#">Link</a>
107
  </li>
108
  <li class="nav-item">
109
    <a class="nav-link disabled">Disabled</a>
110
  </li>
111
</ul>
112
{{< /example >}}
113
 
114
As always, vertical navigation is possible without `<ul>`s, too.
115
 
116
{{< example >}}
117
<nav class="nav flex-column">
118
  <a class="nav-link active" href="#">Active</a>
119
  <a class="nav-link" href="#">Link</a>
120
  <a class="nav-link" href="#">Link</a>
121
  <a class="nav-link disabled">Disabled</a>
122
</nav>
123
{{< /example >}}
124
 
125
### Tabs
126
 
127
Takes the basic nav from above and adds the `.nav-tabs` class to generate a tabbed interface. Use them to create tabbable regions with our [tab JavaScript plugin](#javascript-behavior).
128
 
129
{{< example >}}
130
<ul class="nav nav-tabs">
131
  <li class="nav-item">
132
    <a class="nav-link active" href="#">Active</a>
133
  </li>
134
  <li class="nav-item">
135
    <a class="nav-link" href="#">Link</a>
136
  </li>
137
  <li class="nav-item">
138
    <a class="nav-link" href="#">Link</a>
139
  </li>
140
  <li class="nav-item">
141
    <a class="nav-link disabled">Disabled</a>
142
  </li>
143
</ul>
144
{{< /example >}}
145
 
146
### Pills
147
 
148
Take that same HTML, but use `.nav-pills` instead:
149
 
150
{{< example >}}
151
<ul class="nav nav-pills">
152
  <li class="nav-item">
153
    <a class="nav-link active" href="#">Active</a>
154
  </li>
155
  <li class="nav-item">
156
    <a class="nav-link" href="#">Link</a>
157
  </li>
158
  <li class="nav-item">
159
    <a class="nav-link" href="#">Link</a>
160
  </li>
161
  <li class="nav-item">
162
    <a class="nav-link disabled">Disabled</a>
163
  </li>
164
</ul>
165
{{< /example >}}
166
 
167
### Fill and justify
168
 
169
Force your `.nav`'s contents to extend the full available width one of two modifier classes. To proportionately fill all available space with your `.nav-item`s, use `.nav-fill`. Notice that all horizontal space is occupied, but not every nav item has the same width.
170
 
171
{{< example >}}
172
<ul class="nav nav-pills nav-fill">
173
  <li class="nav-item">
174
    <a class="nav-link active" href="#">Active</a>
175
  </li>
176
  <li class="nav-item">
177
    <a class="nav-link" href="#">Much longer nav link</a>
178
  </li>
179
  <li class="nav-item">
180
    <a class="nav-link" href="#">Link</a>
181
  </li>
182
  <li class="nav-item">
183
    <a class="nav-link disabled">Disabled</a>
184
  </li>
185
</ul>
186
{{< /example >}}
187
 
188
When using a `<nav>`-based navigation, you can safely omit `.nav-item` as only `.nav-link` is required for styling `<a>` elements.
189
 
190
{{< example >}}
191
<nav class="nav nav-pills nav-fill">
192
  <a class="nav-link active" href="#">Active</a>
193
  <a class="nav-link" href="#">Much longer nav link</a>
194
  <a class="nav-link" href="#">Link</a>
195
  <a class="nav-link disabled">Disabled</a>
196
</nav>
197
{{< /example >}}
198
 
199
For equal-width elements, use `.nav-justified`. All horizontal space will be occupied by nav links, but unlike the `.nav-fill` above, every nav item will be the same width.
200
 
201
{{< example >}}
202
<ul class="nav nav-pills nav-justified">
203
  <li class="nav-item">
204
    <a class="nav-link active" href="#">Active</a>
205
  </li>
206
  <li class="nav-item">
207
    <a class="nav-link" href="#">Much longer nav link</a>
208
  </li>
209
  <li class="nav-item">
210
    <a class="nav-link" href="#">Link</a>
211
  </li>
212
  <li class="nav-item">
213
    <a class="nav-link disabled">Disabled</a>
214
  </li>
215
</ul>
216
{{< /example >}}
217
 
218
Similar to the `.nav-fill` example using a `<nav>`-based navigation.
219
 
220
{{< example >}}
221
<nav class="nav nav-pills nav-justified">
222
  <a class="nav-link active" href="#">Active</a>
223
  <a class="nav-link" href="#">Much longer nav link</a>
224
  <a class="nav-link" href="#">Link</a>
225
  <a class="nav-link disabled">Disabled</a>
226
</nav>
227
 
228
{{< /example >}}
229
## Working with flex utilities
230
 
231
If you need responsive nav variations, consider using a series of [flexbox utilities]({{< docsref "/utilities/flex" >}}). While more verbose, these utilities offer greater customization across responsive breakpoints. In the example below, our nav will be stacked on the lowest breakpoint, then adapt to a horizontal layout that fills the available width starting from the small breakpoint.
232
 
233
{{< example >}}
234
<nav class="nav nav-pills flex-column flex-sm-row">
235
  <a class="flex-sm-fill text-sm-center nav-link active" href="#">Active</a>
236
  <a class="flex-sm-fill text-sm-center nav-link" href="#">Longer nav link</a>
237
  <a class="flex-sm-fill text-sm-center nav-link" href="#">Link</a>
238
  <a class="flex-sm-fill text-sm-center nav-link disabled">Disabled</a>
239
</nav>
240
{{< /example >}}
241
 
242
## Regarding accessibility
243
 
244
If you're using navs to provide a navigation bar, be sure to add a `role="navigation"` to the most logical parent container of the `<ul>`, or wrap a `<nav>` element around the whole navigation. Do not add the role to the `<ul>` itself, as this would prevent it from being announced as an actual list by assistive technologies.
245
 
246
Note that navigation bars, even if visually styled as tabs with the `.nav-tabs` class, should **not** be given `role="tablist"`, `role="tab"` or `role="tabpanel"` attributes. These are only appropriate for dynamic tabbed interfaces, as described in the [ARIA Authoring Practices Guide tabs pattern](https://www.w3.org/WAI/ARIA/apg/patterns/tabpanel/). See [JavaScript behavior](#javascript-behavior) for dynamic tabbed interfaces in this section for an example.
247
 
248
## Using dropdowns
249
 
250
Add dropdown menus with a little extra HTML and the [dropdowns JavaScript plugin]({{< docsref "/components/dropdowns#usage" >}}).
251
 
252
### Tabs with dropdowns
253
 
254
{{< example >}}
255
<ul class="nav nav-tabs">
256
  <li class="nav-item">
257
    <a class="nav-link active" href="#">Active</a>
258
  </li>
259
  <li class="nav-item dropdown">
260
    <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
261
    <div class="dropdown-menu">
262
      <a class="dropdown-item" href="#">Action</a>
263
      <a class="dropdown-item" href="#">Another action</a>
264
      <a class="dropdown-item" href="#">Something else here</a>
265
      <div class="dropdown-divider"></div>
266
      <a class="dropdown-item" href="#">Separated link</a>
267
    </div>
268
  </li>
269
  <li class="nav-item">
270
    <a class="nav-link" href="#">Link</a>
271
  </li>
272
  <li class="nav-item">
273
    <a class="nav-link disabled">Disabled</a>
274
  </li>
275
</ul>
276
{{< /example >}}
277
 
278
### Pills with dropdowns
279
 
280
{{< example >}}
281
<ul class="nav nav-pills">
282
  <li class="nav-item">
283
    <a class="nav-link active" href="#">Active</a>
284
  </li>
285
  <li class="nav-item dropdown">
286
    <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
287
    <div class="dropdown-menu">
288
      <a class="dropdown-item" href="#">Action</a>
289
      <a class="dropdown-item" href="#">Another action</a>
290
      <a class="dropdown-item" href="#">Something else here</a>
291
      <div class="dropdown-divider"></div>
292
      <a class="dropdown-item" href="#">Separated link</a>
293
    </div>
294
  </li>
295
  <li class="nav-item">
296
    <a class="nav-link" href="#">Link</a>
297
  </li>
298
  <li class="nav-item">
299
    <a class="nav-link disabled">Disabled</a>
300
  </li>
301
</ul>
302
{{< /example >}}
303
 
304
## JavaScript behavior
305
 
306
Use the tab JavaScript plugin—include it individually or through the compiled `bootstrap.js` file—to extend our navigational tabs and pills to create tabbable panes of local content.
307
 
308
If you're building our JavaScript from source, it [requires `util.js`]({{< docsref "/getting-started/javascript#util" >}}).
309
 
310
Dynamic tabbed interfaces, as described in the [ARIA Authoring Practices Guide tabs pattern](https://www.w3.org/WAI/ARIA/apg/patterns/tabpanel/), require `role="tablist"`, `role="tab"`, `role="tabpanel"`, and additional `aria-` attributes in order to convey their structure, functionality and current state to users of assistive technologies (such as screen readers). As a best practice, we recommend using `<button>` elements for the tabs, as these are controls that trigger a dynamic change, rather than links that navigate to a new page or location.
311
 
312
{{< callout danger >}}
313
Note that the tab JavaScript plugin **does not** support tabbed interfaces that contain dropdown menus, as these cause both usability and accessibility issues. From a usability perspective, the fact that the currently displayed tab's trigger element is not immediately visible (as it's inside the closed dropdown menu) can cause confusion. From an accessibility point of view, there is currently no sensible way to map this sort of construct to a standard WAI ARIA pattern, meaning that it cannot be easily made understandable to users of assistive technologies.
314
{{< /callout >}}
315
 
316
<div class="bd-example bd-example-tabs">
317
  <ul class="nav nav-tabs" id="myTab" role="tablist">
318
    <li class="nav-item" role="presentation">
319
      <button class="nav-link active" id="home-tab" data-toggle="tab" data-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">Home</button>
320
    </li>
321
    <li class="nav-item" role="presentation">
322
      <button class="nav-link" id="profile-tab" data-toggle="tab" data-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">Profile</button>
323
    </li>
324
    <li class="nav-item" role="presentation">
325
      <button class="nav-link" id="contact-tab" data-toggle="tab" data-target="#contact" type="button" role="tab" aria-controls="contact" aria-selected="false">Contact</button>
326
    </li>
327
  </ul>
328
  <div class="tab-content" id="myTabContent">
329
    <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
330
      <p>Placeholder content for the tab panel. This one relates to the home tab. Takes you miles high, so high, 'cause she’s got that one international smile. There's a stranger in my bed, there's a pounding in my head. Oh, no. In another life I would make you stay. ‘Cause I, I’m capable of anything. Suiting up for my crowning battle. Used to steal your parents' liquor and climb to the roof. Tone, tan fit and ready, turn it up cause its gettin' heavy. Her love is like a drug. I guess that I forgot I had a choice.</p>
331
    </div>
332
    <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
333
      <p>Placeholder content for the tab panel. This one relates to the profile tab. You got the finest architecture. Passport stamps, she's cosmopolitan. Fine, fresh, fierce, we got it on lock. Never planned that one day I'd be losing you. She eats your heart out. Your kiss is cosmic, every move is magic. I mean the ones, I mean like she's the one. Greetings loved ones let's take a journey. Just own the night like the 4th of July! But you'd rather get wasted.</p>
334
    </div>
335
    <div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">
336
      <p>Placeholder content for the tab panel. This one relates to the contact tab. Her love is like a drug. All my girls vintage Chanel baby. Got a motel and built a fort out of sheets. 'Cause she's the muse and the artist. (This is how we do) So you wanna play with magic. So just be sure before you give it all to me. I'm walking, I'm walking on air (tonight). Skip the talk, heard it all, time to walk the walk. Catch her if you can. Stinging like a bee I earned my stripes.</p>
337
    </div>
338
  </div>
339
</div>
340
 
341
```html
342
<ul class="nav nav-tabs" id="myTab" role="tablist">
343
  <li class="nav-item" role="presentation">
344
    <button class="nav-link active" id="home-tab" data-toggle="tab" data-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">Home</button>
345
  </li>
346
  <li class="nav-item" role="presentation">
347
    <button class="nav-link" id="profile-tab" data-toggle="tab" data-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">Profile</button>
348
  </li>
349
  <li class="nav-item" role="presentation">
350
    <button class="nav-link" id="contact-tab" data-toggle="tab" data-target="#contact" type="button" role="tab" aria-controls="contact" aria-selected="false">Contact</button>
351
  </li>
352
</ul>
353
<div class="tab-content" id="myTabContent">
354
  <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
355
  <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
356
  <div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">...</div>
357
</div>
358
```
359
 
360
To help fit your needs, this works with `<ul>`-based markup, as shown above, or with any arbitrary "roll your own" markup. Note that if you're using `<nav>`, you shouldn't add `role="tablist"` directly to it, as this would override the element's native role as a navigation landmark. Instead, switch to an alternative element (in the example below, a simple `<div>`) and wrap the `<nav>` around it.
361
 
362
<div class="bd-example bd-example-tabs">
363
  <nav>
364
    <div class="nav nav-tabs" id="nav-tab" role="tablist">
365
      <button class="nav-link active" id="nav-home-tab" data-toggle="tab" data-target="#nav-home" type="button" role="tab" aria-controls="nav-home" aria-selected="true">Home</button>
366
      <button class="nav-link" id="nav-profile-tab" data-toggle="tab" data-target="#nav-profile" type="button" role="tab" aria-controls="nav-profile" aria-selected="false">Profile</button>
367
      <button class="nav-link" id="nav-contact-tab" data-toggle="tab" data-target="#nav-contact" type="button" role="tab" aria-controls="nav-contact" aria-selected="false">Contact</button>
368
    </div>
369
  </nav>
370
  <div class="tab-content" id="nav-tabContent">
371
    <div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
372
      <p>Placeholder content for the tab panel. This one relates to the home tab. Takes you miles high, so high, 'cause she’s got that one international smile. There's a stranger in my bed, there's a pounding in my head. Oh, no. In another life I would make you stay. ‘Cause I, I’m capable of anything. Suiting up for my crowning battle. Used to steal your parents' liquor and climb to the roof. Tone, tan fit and ready, turn it up cause its gettin' heavy. Her love is like a drug. I guess that I forgot I had a choice.</p>
373
    </div>
374
    <div class="tab-pane fade" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">
375
      <p>Placeholder content for the tab panel. This one relates to the profile tab. You got the finest architecture. Passport stamps, she's cosmopolitan. Fine, fresh, fierce, we got it on lock. Never planned that one day I'd be losing you. She eats your heart out. Your kiss is cosmic, every move is magic. I mean the ones, I mean like she's the one. Greetings loved ones let's take a journey. Just own the night like the 4th of July! But you'd rather get wasted.</p>
376
    </div>
377
    <div class="tab-pane fade" id="nav-contact" role="tabpanel" aria-labelledby="nav-contact-tab">
378
      <p>Placeholder content for the tab panel. This one relates to the contact tab. Her love is like a drug. All my girls vintage Chanel baby. Got a motel and built a fort out of sheets. 'Cause she's the muse and the artist. (This is how we do) So you wanna play with magic. So just be sure before you give it all to me. I'm walking, I'm walking on air (tonight). Skip the talk, heard it all, time to walk the walk. Catch her if you can. Stinging like a bee I earned my stripes.</p>
379
    </div>
380
  </div>
381
</div>
382
 
383
```html
384
<nav>
385
  <div class="nav nav-tabs" id="nav-tab" role="tablist">
386
    <button class="nav-link active" id="nav-home-tab" data-toggle="tab" data-target="#nav-home" type="button" role="tab" aria-controls="nav-home" aria-selected="true">Home</button>
387
    <button class="nav-link" id="nav-profile-tab" data-toggle="tab" data-target="#nav-profile" type="button" role="tab" aria-controls="nav-profile" aria-selected="false">Profile</button>
388
    <button class="nav-link" id="nav-contact-tab" data-toggle="tab" data-target="#nav-contact" type="button" role="tab" aria-controls="nav-contact" aria-selected="false">Contact</button>
389
  </div>
390
</nav>
391
<div class="tab-content" id="nav-tabContent">
392
  <div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">...</div>
393
  <div class="tab-pane fade" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">...</div>
394
  <div class="tab-pane fade" id="nav-contact" role="tabpanel" aria-labelledby="nav-contact-tab">...</div>
395
</div>
396
```
397
 
398
The tabs plugin also works with pills.
399
 
400
<div class="bd-example bd-example-tabs">
401
  <ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
402
    <li class="nav-item" role="presentation">
403
      <button class="nav-link active" id="pills-home-tab" data-toggle="pill" data-target="#pills-home" type="button" role="tab" aria-controls="pills-home" aria-selected="true">Home</button>
404
    </li>
405
    <li class="nav-item" role="presentation">
406
      <button class="nav-link" id="pills-profile-tab" data-toggle="pill" data-target="#pills-profile" type="button" role="tab" aria-controls="pills-profile" aria-selected="false">Profile</button>
407
    </li>
408
    <li class="nav-item" role="presentation">
409
      <button class="nav-link" id="pills-contact-tab" data-toggle="pill" data-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
410
    </li>
411
  </ul>
412
  <div class="tab-content" id="pills-tabContent">
413
    <div class="tab-pane fade show active" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab">
414
      <p>Placeholder content for the tab panel. This one relates to the home tab. Takes you miles high, so high, 'cause she’s got that one international smile. There's a stranger in my bed, there's a pounding in my head. Oh, no. In another life I would make you stay. ‘Cause I, I’m capable of anything. Suiting up for my crowning battle. Used to steal your parents' liquor and climb to the roof. Tone, tan fit and ready, turn it up cause its gettin' heavy. Her love is like a drug. I guess that I forgot I had a choice.</p>
415
    </div>
416
    <div class="tab-pane fade" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab">
417
      <p>Placeholder content for the tab panel. This one relates to the profile tab. You got the finest architecture. Passport stamps, she's cosmopolitan. Fine, fresh, fierce, we got it on lock. Never planned that one day I'd be losing you. She eats your heart out. Your kiss is cosmic, every move is magic. I mean the ones, I mean like she's the one. Greetings loved ones let's take a journey. Just own the night like the 4th of July! But you'd rather get wasted.</p>
418
    </div>
419
    <div class="tab-pane fade" id="pills-contact" role="tabpanel" aria-labelledby="pills-contact-tab">
420
      <p>Placeholder content for the tab panel. This one relates to the contact tab. Her love is like a drug. All my girls vintage Chanel baby. Got a motel and built a fort out of sheets. 'Cause she's the muse and the artist. (This is how we do) So you wanna play with magic. So just be sure before you give it all to me. I'm walking, I'm walking on air (tonight). Skip the talk, heard it all, time to walk the walk. Catch her if you can. Stinging like a bee I earned my stripes.</p>
421
    </div>
422
  </div>
423
</div>
424
 
425
```html
426
<ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
427
  <li class="nav-item" role="presentation">
428
    <button class="nav-link active" id="pills-home-tab" data-toggle="pill" data-target="#pills-home" type="button" role="tab" aria-controls="pills-home" aria-selected="true">Home</button>
429
  </li>
430
  <li class="nav-item" role="presentation">
431
    <button class="nav-link" id="pills-profile-tab" data-toggle="pill" data-target="#pills-profile" type="button" role="tab" aria-controls="pills-profile" aria-selected="false">Profile</button>
432
  </li>
433
  <li class="nav-item" role="presentation">
434
    <button class="nav-link" id="pills-contact-tab" data-toggle="pill" data-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
435
  </li>
436
</ul>
437
<div class="tab-content" id="pills-tabContent">
438
  <div class="tab-pane fade show active" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab">...</div>
439
  <div class="tab-pane fade" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab">...</div>
440
  <div class="tab-pane fade" id="pills-contact" role="tabpanel" aria-labelledby="pills-contact-tab">...</div>
441
</div>
442
```
443
 
444
And with vertical pills.
445
 
446
<div class="bd-example bd-example-tabs">
447
  <div class="row">
448
    <div class="col-3">
449
      <div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
450
        <button class="nav-link active" id="v-pills-home-tab" data-toggle="pill" data-target="#v-pills-home" type="button" role="tab" aria-controls="v-pills-home" aria-selected="true">Home</button>
451
        <button class="nav-link" id="v-pills-profile-tab" data-toggle="pill" data-target="#v-pills-profile" type="button" role="tab" aria-controls="v-pills-profile" aria-selected="false">Profile</button>
452
        <button class="nav-link" id="v-pills-messages-tab" data-toggle="pill" data-target="#v-pills-messages" type="button" role="tab" aria-controls="v-pills-messages" aria-selected="false">Messages</button>
453
        <button class="nav-link" id="v-pills-settings-tab" data-toggle="pill" data-target="#v-pills-settings" type="button" role="tab" aria-controls="v-pills-settings" aria-selected="false">Settings</button>
454
      </div>
455
    </div>
456
    <div class="col-9">
457
      <div class="tab-content" id="v-pills-tabContent">
458
        <div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">
459
          <p>Placeholder content for the tab panel. This one relates to the home tab. Saw you downtown singing the Blues. Watch you circle the drain. Why don't you let me stop by? Heavy is the head that wears the crown. Yes, we make angels cry, raining down on earth from up above. Wanna see the show in 3D, a movie. Do you ever feel, feel so paper thin. It’s a yes or no, no maybe.</p>
460
        </div>
461
        <div class="tab-pane fade" id="v-pills-profile" role="tabpanel" aria-labelledby="v-pills-profile-tab">
462
          <p>Placeholder content for the tab panel. This one relates to the profile tab. Takes you miles high, so high, 'cause she’s got that one international smile. There's a stranger in my bed, there's a pounding in my head. Oh, no. In another life I would make you stay. ‘Cause I, I’m capable of anything. Suiting up for my crowning battle. Used to steal your parents' liquor and climb to the roof. Tone, tan fit and ready, turn it up cause its gettin' heavy. Her love is like a drug. I guess that I forgot I had a choice.</p>
463
        </div>
464
        <div class="tab-pane fade" id="v-pills-messages" role="tabpanel" aria-labelledby="v-pills-messages-tab">
465
          <p>Placeholder content for the tab panel. This one relates to the messages tab. You got the finest architecture. Passport stamps, she's cosmopolitan. Fine, fresh, fierce, we got it on lock. Never planned that one day I'd be losing you. She eats your heart out. Your kiss is cosmic, every move is magic. I mean the ones, I mean like she's the one. Greetings loved ones let's take a journey. Just own the night like the 4th of July! But you'd rather get wasted.</p>
466
        </div>
467
        <div class="tab-pane fade" id="v-pills-settings" role="tabpanel" aria-labelledby="v-pills-settings-tab">
468
          <p>Placeholder content for the tab panel. This one relates to the settings tab. Her love is like a drug. All my girls vintage Chanel baby. Got a motel and built a fort out of sheets. 'Cause she's the muse and the artist. (This is how we do) So you wanna play with magic. So just be sure before you give it all to me. I'm walking, I'm walking on air (tonight). Skip the talk, heard it all, time to walk the walk. Catch her if you can. Stinging like a bee I earned my stripes.</p>
469
        </div>
470
      </div>
471
    </div>
472
  </div>
473
</div>
474
 
475
```html
476
<div class="row">
477
  <div class="col-3">
478
    <div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
479
      <button class="nav-link active" id="v-pills-home-tab" data-toggle="pill" data-target="#v-pills-home" type="button" role="tab" aria-controls="v-pills-home" aria-selected="true">Home</button>
480
      <button class="nav-link" id="v-pills-profile-tab" data-toggle="pill" data-target="#v-pills-profile" type="button" role="tab" aria-controls="v-pills-profile" aria-selected="false">Profile</button>
481
      <button class="nav-link" id="v-pills-messages-tab" data-toggle="pill" data-target="#v-pills-messages" type="button" role="tab" aria-controls="v-pills-messages" aria-selected="false">Messages</button>
482
      <button class="nav-link" id="v-pills-settings-tab" data-toggle="pill" data-target="#v-pills-settings" type="button" role="tab" aria-controls="v-pills-settings" aria-selected="false">Settings</button>
483
    </div>
484
  </div>
485
  <div class="col-9">
486
    <div class="tab-content" id="v-pills-tabContent">
487
      <div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">...</div>
488
      <div class="tab-pane fade" id="v-pills-profile" role="tabpanel" aria-labelledby="v-pills-profile-tab">...</div>
489
      <div class="tab-pane fade" id="v-pills-messages" role="tabpanel" aria-labelledby="v-pills-messages-tab">...</div>
490
      <div class="tab-pane fade" id="v-pills-settings" role="tabpanel" aria-labelledby="v-pills-settings-tab">...</div>
491
    </div>
492
  </div>
493
</div>
494
```
495
 
496
### Using data attributes
497
 
498
You can activate a tab or pill navigation without writing any JavaScript by simply specifying `data-toggle="tab"` or `data-toggle="pill"` on an element. Use these data attributes on `.nav-tabs` or `.nav-pills`.
499
 
500
```html
501
<!-- Nav tabs -->
502
<ul class="nav nav-tabs" id="myTab" role="tablist">
503
  <li class="nav-item" role="presentation">
504
    <button class="nav-link active" id="home-tab" data-toggle="tab" data-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">Home</button>
505
  </li>
506
  <li class="nav-item" role="presentation">
507
    <button class="nav-link" id="profile-tab" data-toggle="tab" data-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">Profile</button>
508
  </li>
509
  <li class="nav-item" role="presentation">
510
    <button class="nav-link" id="messages-tab" data-toggle="tab" data-target="#messages" type="button" role="tab" aria-controls="messages" aria-selected="false">Messages</button>
511
  </li>
512
  <li class="nav-item" role="presentation">
513
    <button class="nav-link" id="settings-tab" data-toggle="tab" data-target="#settings" type="button" role="tab" aria-controls="settings" aria-selected="false">Settings</button>
514
  </li>
515
</ul>
516
 
517
<!-- Tab panes -->
518
<div class="tab-content">
519
  <div class="tab-pane active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
520
  <div class="tab-pane" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
521
  <div class="tab-pane" id="messages" role="tabpanel" aria-labelledby="messages-tab">...</div>
522
  <div class="tab-pane" id="settings" role="tabpanel" aria-labelledby="settings-tab">...</div>
523
</div>
524
```
525
 
526
### Via JavaScript
527
 
528
Enable tabbable tabs via JavaScript (each tab needs to be activated individually):
529
 
530
```js
531
$('#myTab button').on('click', function (event) {
532
  event.preventDefault()
533
  $(this).tab('show')
534
})
535
```
536
 
537
You can activate individual tabs in several ways:
538
 
539
```js
540
$('#myTab button[data-target="#profile"]').tab('show') // Select tab by name
541
$('#myTab li:first-child button').tab('show') // Select first tab
542
$('#myTab li:last-child button').tab('show') // Select last tab
543
$('#myTab li:nth-child(3) button').tab('show') // Select third tab
544
```
545
 
546
### Fade effect
547
 
548
To make tabs fade in, add `.fade` to each `.tab-pane`. The first tab pane must also have `.show` to make the initial content visible.
549
 
550
```html
551
<div class="tab-content">
552
  <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
553
  <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
554
  <div class="tab-pane fade" id="messages" role="tabpanel" aria-labelledby="messages-tab">...</div>
555
  <div class="tab-pane fade" id="settings" role="tabpanel" aria-labelledby="settings-tab">...</div>
556
</div>
557
```
558
 
559
### Methods
560
 
561
{{< callout danger >}}
562
{{< partial "callout-danger-async-methods.md" >}}
563
{{< /callout >}}
564
 
565
#### $().tab
566
 
567
Activates a tab element and content container. Tab should have either a `data-target` or, if using a link, an `href` attribute targeting a container node in the DOM.
568
 
569
```html
570
<ul class="nav nav-tabs" id="myTab" role="tablist">
571
  <li class="nav-item" role="presentation">
572
    <button class="nav-link active" id="home-tab" data-toggle="tab" data-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">Home</button>
573
  </li>
574
  <li class="nav-item" role="presentation">
575
    <button class="nav-link" id="profile-tab" data-toggle="tab" data-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">Profile</button>
576
  </li>
577
  <li class="nav-item" role="presentation">
578
    <button class="nav-link" id="messages-tab" data-toggle="tab" data-target="#messages" type="button" role="tab" aria-controls="messages" aria-selected="false">Messages</button>
579
  </li>
580
  <li class="nav-item" role="presentation">
581
    <button class="nav-link" id="settings-tab" data-toggle="tab" data-target="#settings" type="button" role="tab" aria-controls="settings" aria-selected="false">Settings</button>
582
  </li>
583
</ul>
584
 
585
<div class="tab-content">
586
  <div class="tab-pane active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
587
  <div class="tab-pane" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
588
  <div class="tab-pane" id="messages" role="tabpanel" aria-labelledby="messages-tab">...</div>
589
  <div class="tab-pane" id="settings" role="tabpanel" aria-labelledby="settings-tab">...</div>
590
</div>
591
 
592
<script>
593
  $(function () {
594
    $('#myTab li:last-child button').tab('show')
595
  })
596
</script>
597
```
598
 
599
#### .tab('show')
600
 
601
Selects the given tab and shows its associated pane. Any other tab that was previously selected becomes unselected and its associated pane is hidden. **Returns to the caller before the tab pane has actually been shown** (i.e. before the `shown.bs.tab` event occurs).
602
 
603
```js
604
$('#someTab').tab('show')
605
```
606
 
607
#### .tab('dispose')
608
 
609
Destroys an element's tab.
610
 
611
### Events
612
 
613
When showing a new tab, the events fire in the following order:
614
 
615
1. `hide.bs.tab` (on the current active tab)
616
2. `show.bs.tab` (on the to-be-shown tab)
617
3. `hidden.bs.tab` (on the previous active tab, the same one as for the `hide.bs.tab` event)
618
4. `shown.bs.tab` (on the newly-active just-shown tab, the same one as for the `show.bs.tab` event)
619
 
620
If no tab was already active, then the `hide.bs.tab` and `hidden.bs.tab` events will not be fired.
621
 
622
<table class="table table-bordered table-striped">
623
  <thead>
624
    <tr>
625
      <th style="width: 150px;">Event Type</th>
626
      <th>Description</th>
627
    </tr>
628
  </thead>
629
  <tbody>
630
    <tr>
631
      <td>show.bs.tab</td>
632
      <td>This event fires on tab show, but before the new tab has been shown. Use <code>event.target</code> and <code>event.relatedTarget</code> to target the active tab and the previous active tab (if available) respectively.</td>
633
    </tr>
634
    <tr>
635
      <td>shown.bs.tab</td>
636
      <td>This event fires on tab show after a tab has been shown. Use <code>event.target</code> and <code>event.relatedTarget</code> to target the active tab and the previous active tab (if available) respectively.</td>
637
    </tr>
638
    <tr>
639
      <td>hide.bs.tab</td>
640
      <td>This event fires when a new tab is to be shown (and thus the previous active tab is to be hidden). Use <code>event.target</code> and <code>event.relatedTarget</code> to target the current active tab and the new soon-to-be-active tab, respectively.</td>
641
    </tr>
642
    <tr>
643
      <td>hidden.bs.tab</td>
644
      <td>This event fires after a new tab is shown (and thus the previous active tab is hidden). Use <code>event.target</code> and <code>event.relatedTarget</code> to target the previous active tab and the new active tab, respectively.</td>
645
    </tr>
646
  </tbody>
647
</table>
648
 
649
```js
650
$('button[data-toggle="tab"]').on('shown.bs.tab', function (event) {
651
  event.target // newly activated tab
652
  event.relatedTarget // previous active tab
653
})
654
```