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: Modal
4
description: Use Bootstrap's JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
5
group: components
6
toc: true
7
---
8
 
9
## How it works
10
 
11
Before getting started with Bootstrap's modal component, be sure to read the following as our menu options have recently changed.
12
 
13
- Modals are built with HTML, CSS, and JavaScript. They're positioned over everything else in the document and remove scroll from the `<body>` so that modal content scrolls instead.
14
- Clicking on the modal "backdrop" will automatically close the modal.
15
- Bootstrap only supports one modal window at a time. Nested modals aren't supported as we believe them to be poor user experiences.
16
- Modals use `position: fixed`, which can sometimes be a bit particular about its rendering. Whenever possible, place your modal HTML in a top-level position to avoid potential interference from other elements. You'll likely run into issues when nesting a `.modal` within another fixed element.
17
- Once again, due to `position: fixed`, there are some caveats with using modals on mobile devices. [See our browser support docs]({{< docsref "/getting-started/browsers-devices#modals-and-dropdowns-on-mobile" >}}) for details.
18
- Due to how HTML5 defines its semantics, [the `autofocus` HTML attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-autofocus) has no effect in Bootstrap modals. To achieve the same effect, use some custom JavaScript:
19
 
20
```js
21
$('#myModal').on('shown.bs.modal', function () {
22
  $('#myInput').trigger('focus')
23
})
24
```
25
 
26
{{< callout info >}}
27
{{< partial "callout-info-prefersreducedmotion.md" >}}
28
{{< /callout >}}
29
 
30
Keep reading for demos and usage guidelines.
31
 
32
## Examples
33
 
34
### Modal components
35
 
36
Below is a _static_ modal example (meaning its `position` and `display` have been overridden). Included are the modal header, modal body (required for `padding`), and modal footer (optional). We ask that you include modal headers with dismiss actions whenever possible, or provide another explicit dismiss action.
37
 
38
<div class="bd-example bd-example-modal">
39
  <div class="modal" tabindex="-1">
40
    <div class="modal-dialog">
41
      <div class="modal-content">
42
        <div class="modal-header">
43
          <h5 class="modal-title">Modal title</h5>
44
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
45
            <span aria-hidden="true">&times;</span>
46
          </button>
47
        </div>
48
        <div class="modal-body">
49
          <p>Modal body text goes here.</p>
50
        </div>
51
        <div class="modal-footer">
52
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
53
          <button type="button" class="btn btn-primary">Save changes</button>
54
        </div>
55
      </div>
56
    </div>
57
  </div>
58
</div>
59
 
60
```html
61
<div class="modal" tabindex="-1">
62
  <div class="modal-dialog">
63
    <div class="modal-content">
64
      <div class="modal-header">
65
        <h5 class="modal-title">Modal title</h5>
66
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
67
          <span aria-hidden="true">&times;</span>
68
        </button>
69
      </div>
70
      <div class="modal-body">
71
        <p>Modal body text goes here.</p>
72
      </div>
73
      <div class="modal-footer">
74
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
75
        <button type="button" class="btn btn-primary">Save changes</button>
76
      </div>
77
    </div>
78
  </div>
79
</div>
80
```
81
 
82
### Live demo
83
 
84
Toggle a working modal demo by clicking the button below. It will slide down and fade in from the top of the page.
85
 
86
<div class="modal fade" id="exampleModalLive" tabindex="-1" aria-labelledby="exampleModalLiveLabel" aria-hidden="true">
87
  <div class="modal-dialog">
88
    <div class="modal-content">
89
      <div class="modal-header">
90
        <h5 class="modal-title" id="exampleModalLiveLabel">Modal title</h5>
91
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
92
          <span aria-hidden="true">&times;</span>
93
        </button>
94
      </div>
95
      <div class="modal-body">
96
        <p>Woohoo, you're reading this text in a modal!</p>
97
      </div>
98
      <div class="modal-footer">
99
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
100
        <button type="button" class="btn btn-primary">Save changes</button>
101
      </div>
102
    </div>
103
  </div>
104
</div>
105
 
106
<div class="bd-example">
107
  <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalLive">
108
    Launch demo modal
109
  </button>
110
</div>
111
 
112
```html
113
<!-- Button trigger modal -->
114
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
115
  Launch demo modal
116
</button>
117
 
118
<!-- Modal -->
119
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
120
  <div class="modal-dialog">
121
    <div class="modal-content">
122
      <div class="modal-header">
123
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
124
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
125
          <span aria-hidden="true">&times;</span>
126
        </button>
127
      </div>
128
      <div class="modal-body">
129
        ...
130
      </div>
131
      <div class="modal-footer">
132
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
133
        <button type="button" class="btn btn-primary">Save changes</button>
134
      </div>
135
    </div>
136
  </div>
137
</div>
138
```
139
 
140
### Static backdrop
141
 
142
When backdrop is set to static, the modal will not close when clicking outside it. Click the button below to try it.
143
 
144
<div class="modal fade" id="staticBackdropLive" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLiveLabel" aria-hidden="true">
145
  <div class="modal-dialog">
146
    <div class="modal-content">
147
      <div class="modal-header">
148
        <h5 class="modal-title" id="staticBackdropLiveLabel">Modal title</h5>
149
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
150
          <span aria-hidden="true">&times;</span>
151
        </button>
152
      </div>
153
      <div class="modal-body">
154
        <p>I will not close if you click outside me. Don't even try to press escape key.</p>
155
      </div>
156
      <div class="modal-footer">
157
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
158
        <button type="button" class="btn btn-primary">Understood</button>
159
      </div>
160
    </div>
161
  </div>
162
</div>
163
 
164
<div class="bd-example">
165
  <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#staticBackdropLive">
166
    Launch static backdrop modal
167
  </button>
168
</div>
169
 
170
```html
171
<!-- Button trigger modal -->
172
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#staticBackdrop">
173
  Launch static backdrop modal
174
</button>
175
 
176
<!-- Modal -->
177
<div class="modal fade" id="staticBackdrop" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
178
  <div class="modal-dialog">
179
    <div class="modal-content">
180
      <div class="modal-header">
181
        <h5 class="modal-title" id="staticBackdropLabel">Modal title</h5>
182
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
183
          <span aria-hidden="true">&times;</span>
184
        </button>
185
      </div>
186
      <div class="modal-body">
187
        ...
188
      </div>
189
      <div class="modal-footer">
190
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
191
        <button type="button" class="btn btn-primary">Understood</button>
192
      </div>
193
    </div>
194
  </div>
195
</div>
196
```
197
 
198
### Scrolling long content
199
 
200
When modals become too long for the user's viewport or device, they scroll independent of the page itself. Try the demo below to see what we mean.
201
 
202
<div class="modal fade" id="exampleModalLong" tabindex="-1" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
203
  <div class="modal-dialog">
204
    <div class="modal-content">
205
      <div class="modal-header">
206
        <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
207
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
208
          <span aria-hidden="true">&times;</span>
209
        </button>
210
      </div>
211
      <div class="modal-body">
212
        <p>What follows is just some placeholder text for this modal dialog. Sipping on Rosé, Silver Lake sun, coming up all lazy. It’s in the palm of your hand now baby. So we hit the boulevard. So make a wish, I'll make it like your birthday everyday. Do you ever feel already buried deep six feet under? It's time to bring out the big balloons. You could've been the greatest. Passport stamps, she's cosmopolitan. Your kiss is cosmic, every move is magic.</p>
213
        <p>We're living the life. We're doing it right. Open up your heart. I was tryna hit it and quit it. Her love is like a drug. Always leaves a trail of stardust. The girl's a freak, she drive a jeep in Laguna Beach. Fine, fresh, fierce, we got it on lock. All my girls vintage Chanel baby.</p>
214
        <p>Before you met me I was alright but things were kinda heavy. Peach-pink lips, yeah, everybody stares. This is no big deal. Calling out my name. I could have rewrite your addiction. She's got that, je ne sais quoi, you know it. Heavy is the head that wears the crown. 'Cause, baby, you're a firework. Like thunder gonna shake the ground.</p>
215
        <p>Just own the night like the 4th of July! I’m gon’ put her in a coma. What you're waiting for, it's time for you to show it off. Can't replace you with a million rings. You open my eyes and I'm ready to go, lead me into the light. And here you are. I’m gon’ put her in a coma. Come on, let your colours burst. So cover your eyes, I have a surprise. As I march alone to a different beat. Glitter all over the room pink flamingos in the pool.</p>
216
        <p>You just gotta ignite the light and let it shine! Come just as you are to me. Just own the night like the 4th of July. Infect me with your love and fill me with your poison. Come just as you are to me. End of the rainbow looking treasure.</p>
217
        <p>I can't sleep let's run away and don't ever look back, don't ever look back. I can't sleep let's run away and don't ever look back, don't ever look back. Yes, we make angels cry, raining down on earth from up above. I'm walking on air (tonight). Let you put your hands on me in my skin-tight jeans. Stinging like a bee I earned my stripes. I went from zero, to my own hero. Even brighter than the moon, moon, moon. Make 'em go, 'Aah, aah, aah' as you shoot across the sky-y-y! Why don't you let me stop by?</p>
218
        <p>Boom, boom, boom. Never made me blink one time. Yeah, you're lucky if you're on her plane. Talk about our future like we had a clue. Oh my God no exaggeration. You're original, cannot be replaced. The girl's a freak, she drive a jeep in Laguna Beach. It's no big deal, it's no big deal, it's no big deal. In another life I would make you stay. I'm ma get your heart racing in my skin-tight jeans. I wanna walk on your wave length and be there when you vibrate Never made me blink one time.</p>
219
        <p>We'd keep all our promises be us against the world. If you get the chance you better keep her. It's time to bring out the big, big, big, big, big, big balloons. I hope you got a healthy appetite. Don't let the greatness get you down, oh, oh yeah. Yeah, she's footloose and so fancy free. I want the jaw droppin', eye poppin', head turnin', body shockin'. End of the rainbow looking treasure.</p>
220
      </div>
221
      <div class="modal-footer">
222
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
223
        <button type="button" class="btn btn-primary">Save changes</button>
224
      </div>
225
    </div>
226
  </div>
227
</div>
228
 
229
<div class="bd-example">
230
  <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalLong">
231
    Launch demo modal
232
  </button>
233
</div>
234
 
235
You can also create a scrollable modal that allows scroll the modal body by adding `.modal-dialog-scrollable` to `.modal-dialog`.
236
 
237
<div class="modal fade" id="exampleModalScrollable" tabindex="-1" aria-labelledby="exampleModalScrollableTitle" aria-hidden="true">
238
  <div class="modal-dialog modal-dialog-scrollable">
239
    <div class="modal-content">
240
      <div class="modal-header">
241
        <h5 class="modal-title" id="exampleModalScrollableTitle">Modal title</h5>
242
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
243
          <span aria-hidden="true">&times;</span>
244
        </button>
245
      </div>
246
      <div class="modal-body">
247
        <p>What follows is just some placeholder text for this modal dialog. You just gotta ignite the light and let it shine! Come just as you are to me. Just own the night like the 4th of July. Infect me with your love and fill me with your poison. Come just as you are to me. End of the rainbow looking treasure.</p>
248
        <p>I can't sleep let's run away and don't ever look back, don't ever look back. I can't sleep let's run away and don't ever look back, don't ever look back. Yes, we make angels cry, raining down on earth from up above. I'm walking on air (tonight). Let you put your hands on me in my skin-tight jeans. Stinging like a bee I earned my stripes. I went from zero, to my own hero. Even brighter than the moon, moon, moon. Make 'em go, 'Aah, aah, aah' as you shoot across the sky-y-y! Why don't you let me stop by?</p>
249
        <p>Boom, boom, boom. Never made me blink one time. Yeah, you're lucky if you're on her plane. Talk about our future like we had a clue. Oh my God no exaggeration. You're original, cannot be replaced. The girl's a freak, she drive a jeep in Laguna Beach. It's no big deal, it's no big deal, it's no big deal. In another life I would make you stay. I'm ma get your heart racing in my skin-tight jeans. I wanna walk on your wave length and be there when you vibrate Never made me blink one time.</p>
250
        <p>We'd keep all our promises be us against the world. In another life I would be your girl. We can dance, until we die, you and I, will be young forever. And on my 18th Birthday we got matching tattoos. So open up your heart and just let it begin. 'Cause she's the muse and the artist. She eats your heart out. Like Jeffrey Dahmer (woo). Pop your confetti. (This is how we do) I know one spark will shock the world, yeah yeah. If you only knew what the future holds.</p>
251
        <p>Sipping on Rosé, Silver Lake sun, coming up all lazy. It’s in the palm of your hand now baby. So we hit the boulevard. So make a wish, I'll make it like your birthday everyday. Do you ever feel already buried deep six feet under? It's time to bring out the big balloons. You could've been the greatest. Passport stamps, she's cosmopolitan. Your kiss is cosmic, every move is magic.</p>
252
        <p>We're living the life. We're doing it right. Open up your heart. I was tryna hit it and quit it. Her love is like a drug. Always leaves a trail of stardust. The girl's a freak, she drive a jeep in Laguna Beach. Fine, fresh, fierce, we got it on lock. All my girls vintage Chanel baby.</p>
253
        <p>Before you met me I was alright but things were kinda heavy. Peach-pink lips, yeah, everybody stares. This is no big deal. Calling out my name. I could have rewrite your addiction. She's got that, je ne sais quoi, you know it. Heavy is the head that wears the crown. 'Cause, baby, you're a firework. Like thunder gonna shake the ground.</p>
254
        <p>Just own the night like the 4th of July! I’m gon’ put her in a coma. What you're waiting for, it's time for you to show it off. Can't replace you with a million rings. You open my eyes and I'm ready to go, lead me into the light. And here you are. I’m gon’ put her in a coma. Come on, let your colours burst. So cover your eyes, I have a surprise. As I march alone to a different beat. Glitter all over the room pink flamingos in the pool.</p>
255
      </div>
256
      <div class="modal-footer">
257
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
258
        <button type="button" class="btn btn-primary">Save changes</button>
259
      </div>
260
    </div>
261
  </div>
262
</div>
263
 
264
<div class="bd-example">
265
  <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalScrollable">
266
    Launch demo modal
267
  </button>
268
</div>
269
 
270
```html
271
<!-- Scrollable modal -->
272
<div class="modal-dialog modal-dialog-scrollable">
273
  ...
274
</div>
275
```
276
 
277
### Vertically centered
278
 
279
Add `.modal-dialog-centered` to `.modal-dialog` to vertically center the modal.
280
 
281
<div class="modal fade" id="exampleModalCenter" tabindex="-1" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
282
  <div class="modal-dialog modal-dialog-centered">
283
    <div class="modal-content">
284
      <div class="modal-header">
285
        <h5 class="modal-title" id="exampleModalCenterTitle">Modal title</h5>
286
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
287
          <span aria-hidden="true">&times;</span>
288
        </button>
289
      </div>
290
      <div class="modal-body">
291
        <p>Placeholder text for this demonstration of a vertically centered modal dialog.</p>
292
      </div>
293
      <div class="modal-footer">
294
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
295
        <button type="button" class="btn btn-primary">Save changes</button>
296
      </div>
297
    </div>
298
  </div>
299
</div>
300
 
301
<div class="modal fade" id="exampleModalCenteredScrollable" tabindex="-1" aria-labelledby="exampleModalCenteredScrollableTitle" aria-hidden="true">
302
  <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
303
    <div class="modal-content">
304
      <div class="modal-header">
305
        <h5 class="modal-title" id="exampleModalCenteredScrollableTitle">Modal title</h5>
306
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
307
          <span aria-hidden="true">&times;</span>
308
        </button>
309
      </div>
310
      <div class="modal-body">
311
        <p>Placeholder text for this demonstration of a vertically centered modal dialog.</p>
312
        <p>In this case, the dialog has a bit more content, just to show how vertical centering can be added to a scrollable modal.</p>
313
        <p>What follows is just some placeholder text for this modal dialog. Sipping on Rosé, Silver Lake sun, coming up all lazy. It’s in the palm of your hand now baby. So we hit the boulevard. So make a wish, I'll make it like your birthday everyday. Do you ever feel already buried deep six feet under? It's time to bring out the big balloons. You could've been the greatest. Passport stamps, she's cosmopolitan. Your kiss is cosmic, every move is magic.</p>
314
        <p>We're living the life. We're doing it right. Open up your heart. I was tryna hit it and quit it. Her love is like a drug. Always leaves a trail of stardust. The girl's a freak, she drive a jeep in Laguna Beach. Fine, fresh, fierce, we got it on lock. All my girls vintage Chanel baby.</p>
315
      </div>
316
      <div class="modal-footer">
317
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
318
        <button type="button" class="btn btn-primary">Save changes</button>
319
      </div>
320
    </div>
321
  </div>
322
</div>
323
 
324
<div class="bd-example">
325
  <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
326
    Vertically centered modal
327
  </button>
328
  <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenteredScrollable">
329
    Vertically centered scrollable modal
330
  </button>
331
</div>
332
 
333
```html
334
<!-- Vertically centered modal -->
335
<div class="modal-dialog modal-dialog-centered">
336
  ...
337
</div>
338
 
339
<!-- Vertically centered scrollable modal -->
340
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
341
  ...
342
</div>
343
```
344
 
345
### Tooltips and popovers
346
 
347
[Tooltips]({{< docsref "/components/tooltips" >}}) and [popovers]({{< docsref "/components/popovers" >}}) can be placed within modals as needed. When modals are closed, any tooltips and popovers within are also automatically dismissed.
348
 
349
<div class="modal fade" id="exampleModalPopovers" tabindex="-1" aria-labelledby="exampleModalPopoversLabel" aria-hidden="true">
350
  <div class="modal-dialog">
351
    <div class="modal-content">
352
      <div class="modal-header">
353
        <h5 class="modal-title" id="exampleModalPopoversLabel">Modal title</h5>
354
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
355
          <span aria-hidden="true">&times;</span>
356
        </button>
357
      </div>
358
      <div class="modal-body">
359
        <h5>Popover in a modal</h5>
360
        <p>This <a href="#" role="button" class="btn btn-secondary popover-test" title="Popover title" data-content="Popover body content is set in this attribute." data-container="#exampleModalPopovers">button</a> triggers a popover on click.</p>
361
        <hr>
362
        <h5>Tooltips in a modal</h5>
363
        <p><a href="#" class="tooltip-test" title="Tooltip" data-container="#exampleModalPopovers">This link</a> and <a href="#" class="tooltip-test" title="Tooltip" data-container="#exampleModalPopovers">that link</a> have tooltips on hover.</p>
364
      </div>
365
      <div class="modal-footer">
366
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
367
        <button type="button" class="btn btn-primary">Save changes</button>
368
      </div>
369
    </div>
370
  </div>
371
</div>
372
 
373
<div class="bd-example">
374
  <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalPopovers">
375
    Launch demo modal
376
  </button>
377
</div>
378
 
379
```html
380
<div class="modal-body">
381
  <h5>Popover in a modal</h5>
382
  <p>This <a href="#" role="button" class="btn btn-secondary popover-test" title="Popover title" data-content="Popover body content is set in this attribute.">button</a> triggers a popover on click.</p>
383
  <hr>
384
  <h5>Tooltips in a modal</h5>
385
  <p><a href="#" class="tooltip-test" title="Tooltip">This link</a> and <a href="#" class="tooltip-test" title="Tooltip">that link</a> have tooltips on hover.</p>
386
</div>
387
```
388
 
389
### Using the grid
390
 
391
Utilize the Bootstrap grid system within a modal by nesting `.container-fluid` within the `.modal-body`. Then, use the normal grid system classes as you would anywhere else.
392
 
393
<div class="modal fade" id="gridSystemModal" tabindex="-1" aria-labelledby="gridModalLabel" aria-hidden="true">
394
  <div class="modal-dialog">
395
    <div class="modal-content">
396
      <div class="modal-header">
397
        <h5 class="modal-title" id="gridModalLabel">Grids in modals</h5>
398
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
399
      </div>
400
      <div class="modal-body">
401
        <div class="container-fluid bd-example-row">
402
          <div class="row">
403
            <div class="col-md-4">.col-md-4</div>
404
            <div class="col-md-4 ml-auto">.col-md-4 .ml-auto</div>
405
          </div>
406
          <div class="row">
407
            <div class="col-md-3 ml-auto">.col-md-3 .ml-auto</div>
408
            <div class="col-md-2 ml-auto">.col-md-2 .ml-auto</div>
409
          </div>
410
          <div class="row">
411
            <div class="col-md-6 ml-auto">.col-md-6 .ml-auto</div>
412
          </div>
413
          <div class="row">
414
            <div class="col-sm-9">
415
              Level 1: .col-sm-9
416
              <div class="row">
417
                <div class="col-8 col-sm-6">
418
                  Level 2: .col-8 .col-sm-6
419
                </div>
420
                <div class="col-4 col-sm-6">
421
                  Level 2: .col-4 .col-sm-6
422
                </div>
423
              </div>
424
            </div>
425
          </div>
426
        </div>
427
      </div>
428
      <div class="modal-footer">
429
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
430
        <button type="button" class="btn btn-primary">Save changes</button>
431
      </div>
432
    </div>
433
  </div>
434
</div>
435
 
436
<div class="bd-example">
437
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#gridSystemModal">
438
  Launch demo modal
439
</button>
440
</div>
441
 
442
```html
443
<div class="modal-body">
444
  <div class="container-fluid">
445
    <div class="row">
446
      <div class="col-md-4">.col-md-4</div>
447
      <div class="col-md-4 ml-auto">.col-md-4 .ml-auto</div>
448
    </div>
449
    <div class="row">
450
      <div class="col-md-3 ml-auto">.col-md-3 .ml-auto</div>
451
      <div class="col-md-2 ml-auto">.col-md-2 .ml-auto</div>
452
    </div>
453
    <div class="row">
454
      <div class="col-md-6 ml-auto">.col-md-6 .ml-auto</div>
455
    </div>
456
    <div class="row">
457
      <div class="col-sm-9">
458
        Level 1: .col-sm-9
459
        <div class="row">
460
          <div class="col-8 col-sm-6">
461
            Level 2: .col-8 .col-sm-6
462
          </div>
463
          <div class="col-4 col-sm-6">
464
            Level 2: .col-4 .col-sm-6
465
          </div>
466
        </div>
467
      </div>
468
    </div>
469
  </div>
470
</div>
471
```
472
 
473
### Varying modal content
474
 
475
Have a bunch of buttons that all trigger the same modal with slightly different contents? Use `event.relatedTarget` and [HTML `data-*` attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes) (possibly [via jQuery](https://api.jquery.com/data/)) to vary the contents of the modal depending on which button was clicked.
476
 
477
Below is a live demo followed by example HTML and JavaScript. For more information, [read the modal events docs](#events) for details on `relatedTarget`.
478
 
479
{{< example >}}
480
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Open modal for @mdo</button>
481
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@fat">Open modal for @fat</button>
482
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@getbootstrap">Open modal for @getbootstrap</button>
483
 
484
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
485
  <div class="modal-dialog">
486
    <div class="modal-content">
487
      <div class="modal-header">
488
        <h5 class="modal-title" id="exampleModalLabel">New message</h5>
489
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
490
          <span aria-hidden="true">&times;</span>
491
        </button>
492
      </div>
493
      <div class="modal-body">
494
        <form>
495
          <div class="form-group">
496
            <label for="recipient-name" class="col-form-label">Recipient:</label>
497
            <input type="text" class="form-control" id="recipient-name">
498
          </div>
499
          <div class="form-group">
500
            <label for="message-text" class="col-form-label">Message:</label>
501
            <textarea class="form-control" id="message-text"></textarea>
502
          </div>
503
        </form>
504
      </div>
505
      <div class="modal-footer">
506
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
507
        <button type="button" class="btn btn-primary">Send message</button>
508
      </div>
509
    </div>
510
  </div>
511
</div>
512
{{< /example >}}
513
 
514
```js
515
$('#exampleModal').on('show.bs.modal', function (event) {
516
  var button = $(event.relatedTarget) // Button that triggered the modal
517
  var recipient = button.data('whatever') // Extract info from data-* attributes
518
  // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
519
  // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
520
  var modal = $(this)
521
  modal.find('.modal-title').text('New message to ' + recipient)
522
  modal.find('.modal-body input').val(recipient)
523
})
524
```
525
 
526
### Change animation
527
 
528
The `$modal-fade-transform` variable determines the transform state of `.modal-dialog` before the modal fade-in animation, the `$modal-show-transform` variable determines the transform of `.modal-dialog` at the end of the modal fade-in animation.
529
 
530
If you want for example a zoom-in animation, you can set `$modal-fade-transform: scale(.8)`.
531
 
532
### Remove animation
533
 
534
For modals that simply appear rather than fade in to view, remove the `.fade` class from your modal markup.
535
 
536
```html
537
<div class="modal" tabindex="-1" aria-labelledby="..." aria-hidden="true">
538
  ...
539
</div>
540
```
541
 
542
### Dynamic heights
543
 
544
If the height of a modal changes while it is open, you should call `$('#myModal').modal('handleUpdate')` to readjust the modal's position in case a scrollbar appears.
545
 
546
### Accessibility
547
 
548
Be sure to add `aria-labelledby="..."`, referencing the modal title, to `.modal`. Additionally, you may give a description of your modal dialog with `aria-describedby` on `.modal`. Note that you don't need to add `role="dialog"` since we already add it via JavaScript.
549
 
550
### Embedding YouTube videos
551
 
552
Embedding YouTube videos in modals requires additional JavaScript not in Bootstrap to automatically stop playback and more. [See this helpful Stack Overflow post](https://stackoverflow.com/questions/18622508/bootstrap-3-and-youtube-in-modal) for more information.
553
 
554
## Optional sizes
555
 
556
Modals have three optional sizes, available via modifier classes to be placed on a `.modal-dialog`. These sizes kick in at certain breakpoints to avoid horizontal scrollbars on narrower viewports.
557
 
558
<table class="table table-bordered table-striped">
559
  <thead>
560
    <tr>
561
      <th>Size</th>
562
      <th>Class</th>
563
      <th>Modal max-width</th>
564
    </tr>
565
  </thead>
566
  <tbody>
567
    <tr>
568
      <td>Small</td>
569
      <td><code>.modal-sm</code></td>
570
      <td><code>300px</code></td>
571
    </tr>
572
    <tr>
573
      <td>Default</td>
574
      <td class="text-muted">None</td>
575
      <td><code>500px</code></td>
576
    </tr>
577
    <tr>
578
      <td>Large</td>
579
      <td><code>.modal-lg</code></td>
580
      <td><code>800px</code></td>
581
    </tr>
582
    <tr>
583
      <td>Extra large</td>
584
      <td><code>.modal-xl</code></td>
585
      <td><code>1140px</code></td>
586
    </tr>
587
  </tbody>
588
</table>
589
 
590
Our default modal without modifier class constitutes the "medium" size modal.
591
 
592
<div class="bd-example">
593
  <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalXl">Extra large modal</button>
594
  <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalLg">Large modal</button>
595
  <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalSm">Small modal</button>
596
</div>
597
 
598
```html
599
<div class="modal-dialog modal-xl">...</div>
600
<div class="modal-dialog modal-lg">...</div>
601
<div class="modal-dialog modal-sm">...</div>
602
```
603
 
604
<div class="modal fade" id="exampleModalXl" tabindex="-1" aria-labelledby="exampleModalXlLabel" aria-hidden="true">
605
  <div class="modal-dialog modal-xl">
606
    <div class="modal-content">
607
      <div class="modal-header">
608
        <h5 class="modal-title h4" id="exampleModalXlLabel">Extra large modal</h5>
609
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
610
          <span aria-hidden="true">&times;</span>
611
        </button>
612
      </div>
613
      <div class="modal-body">
614
        ...
615
      </div>
616
    </div>
617
  </div>
618
</div>
619
 
620
<div class="modal fade" id="exampleModalLg" tabindex="-1" aria-labelledby="exampleModalLgLabel" aria-hidden="true">
621
  <div class="modal-dialog modal-lg">
622
    <div class="modal-content">
623
      <div class="modal-header">
624
        <h5 class="modal-title h4" id="exampleModalLgLabel">Large modal</h5>
625
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
626
          <span aria-hidden="true">&times;</span>
627
        </button>
628
      </div>
629
      <div class="modal-body">
630
        ...
631
      </div>
632
    </div>
633
  </div>
634
</div>
635
 
636
<div class="modal fade" id="exampleModalSm" tabindex="-1" aria-labelledby="exampleModalSmLabel" aria-hidden="true">
637
  <div class="modal-dialog modal-sm">
638
    <div class="modal-content">
639
      <div class="modal-header">
640
        <h5 class="modal-title h4" id="exampleModalSmLabel">Small modal</h5>
641
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
642
          <span aria-hidden="true">&times;</span>
643
        </button>
644
      </div>
645
      <div class="modal-body">
646
        ...
647
      </div>
648
    </div>
649
  </div>
650
</div>
651
 
652
## Usage
653
 
654
The modal plugin toggles your hidden content on demand, via data attributes or JavaScript. It also adds `.modal-open` to the `<body>` to override default scrolling behavior and generates a `.modal-backdrop` to provide a click area for dismissing shown modals when clicking outside the modal.
655
 
656
### Via data attributes
657
 
658
Activate a modal without writing JavaScript. Set `data-toggle="modal"` on a controller element, like a button, along with a `data-target="#foo"` or `href="#foo"` to target a specific modal to toggle.
659
 
660
```html
661
<button type="button" data-toggle="modal" data-target="#myModal">Launch modal</button>
662
```
663
 
664
### Via JavaScript
665
 
666
Call a modal with id `myModal` with a single line of JavaScript:
667
 
668
```js
669
$('#myModal').modal(options)
670
```
671
 
672
### Options
673
 
674
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to `data-`, as in `data-backdrop=""`.
675
 
676
<table class="table table-bordered table-striped">
677
  <thead>
678
    <tr>
679
      <th style="width: 100px;">Name</th>
680
      <th style="width: 50px;">Type</th>
681
      <th style="width: 50px;">Default</th>
682
      <th>Description</th>
683
    </tr>
684
  </thead>
685
  <tbody>
686
    <tr>
687
      <td>backdrop</td>
688
      <td>boolean or the string <code>'static'</code></td>
689
      <td>true</td>
690
      <td>Includes a modal-backdrop element. Alternatively, specify <code>static</code> for a backdrop which doesn't close the modal on click.</td>
691
    </tr>
692
    <tr>
693
      <td>keyboard</td>
694
      <td>boolean</td>
695
      <td>true</td>
696
      <td>Closes the modal when escape key is pressed</td>
697
    </tr>
698
    <tr>
699
      <td>focus</td>
700
      <td>boolean</td>
701
      <td>true</td>
702
      <td>Puts the focus on the modal when initialized.</td>
703
    </tr>
704
    <tr>
705
      <td>show</td>
706
      <td>boolean</td>
707
      <td>true</td>
708
      <td>Shows the modal when initialized.</td>
709
    </tr>
710
  </tbody>
711
</table>
712
 
713
### Methods
714
 
715
{{< callout danger >}}
716
{{< partial "callout-danger-async-methods.md" >}}
717
{{< /callout >}}
718
 
719
#### `.modal(options)`
720
 
721
Activates your content as a modal. Accepts an optional options `object`.
722
 
723
```js
724
$('#myModal').modal({
725
  keyboard: false
726
})
727
```
728
 
729
#### `.modal('toggle')`
730
 
731
Manually toggles a modal. **Returns to the caller before the modal has actually been shown or hidden** (i.e. before the `shown.bs.modal` or `hidden.bs.modal` event occurs).
732
 
733
```js
734
$('#myModal').modal('toggle')
735
```
736
 
737
#### `.modal('show')`
738
 
739
Manually opens a modal. **Returns to the caller before the modal has actually been shown** (i.e. before the `shown.bs.modal` event occurs).
740
 
741
```js
742
$('#myModal').modal('show')
743
```
744
 
745
#### `.modal('hide')`
746
 
747
Manually hides a modal. **Returns to the caller before the modal has actually been hidden** (i.e. before the `hidden.bs.modal` event occurs).
748
 
749
```js
750
$('#myModal').modal('hide')
751
```
752
 
753
#### `.modal('handleUpdate')`
754
 
755
Manually readjust the modal's position if the height of a modal changes while it is open (i.e. in case a scrollbar appears).
756
 
757
```js
758
$('#myModal').modal('handleUpdate')
759
```
760
 
761
#### `.modal('dispose')`
762
 
763
Destroys an element's modal.
764
 
765
### Events
766
 
767
Bootstrap's modal class exposes a few events for hooking into modal functionality. All modal events are fired at the modal itself (i.e. at the `<div class="modal">`).
768
 
769
<table class="table table-bordered table-striped">
770
  <thead>
771
    <tr>
772
      <th style="width: 150px;">Event Type</th>
773
      <th>Description</th>
774
    </tr>
775
  </thead>
776
  <tbody>
777
    <tr>
778
      <td>show.bs.modal</td>
779
      <td>This event fires immediately when the <code>show</code> instance method is called. If caused by a click, the clicked element is available as the <code>relatedTarget</code> property of the event.</td>
780
    </tr>
781
    <tr>
782
      <td>shown.bs.modal</td>
783
      <td>This event is fired when the modal has been made visible to the user (will wait for CSS transitions to complete). If caused by a click, the clicked element is available as the <code>relatedTarget</code> property of the event.</td>
784
    </tr>
785
    <tr>
786
      <td>hide.bs.modal</td>
787
      <td>This event is fired immediately when the <code>hide</code> instance method has been called.</td>
788
    </tr>
789
    <tr>
790
      <td>hidden.bs.modal</td>
791
      <td>This event is fired when the modal has finished being hidden from the user (will wait for CSS transitions to complete).</td>
792
    </tr>
793
    <tr>
794
      <td>hidePrevented.bs.modal</td>
795
      <td>This event is fired when the modal is shown, its backdrop is <code>static</code> and a click outside the modal or an escape key press is performed with the keyboard option or <code>data-keyboard</code> set to <code>false</code>.</td>
796
    </tr>
797
  </tbody>
798
</table>
799
 
800
```js
801
$('#myModal').on('hidden.bs.modal', function (event) {
802
  // do something...
803
})
804
```