Documentation
Modal
Use Bootstrap’s JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
Modal components
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.
<Modal.Dialog>
<Modal.Header closeButton>
<Modal.Title>Modal title</Modal.Title>
</Modal.Header>
<Modal.Body>
<p>Modal body text goes here.</p>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary">Close</Button>
<Button variant="primary">Save changes</Button>
</Modal.Footer>
</Modal.Dialog>
Live demo
A modal with header, body, and set of actions in the footer. Use <Modal/>
in combination with other components to show or hide your Modal. The <Modal/>
Component comes with a few convenient "sub components": <Modal.Header/>
, <Modal.Title/>
, <Modal.Body/>
, and <Modal.Footer/>
, which you can use to build the Modal content.
<Button variant="primary" onClick={handleShow1}>
Launch demo modal
</Button>
<Modal show={show1} onHide={handleClose1}>
<Modal.Header closeButton>
<Modal.Title>Modal heading</Modal.Title>
</Modal.Header>
<Modal.Body>Woohoo, you're reading this text in a modal!</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose1}>
Close
</Button>
<Button variant="primary" onClick={handleClose1}>
Save Changes
</Button>
</Modal.Footer>
</Modal>
Static backdrop
When backdrop is set to static, the modal will not close when clicking outside it. Click the button below to try it.
<Button variant="primary" onClick={handleShow2}>
Launch static backdrop modal
</Button>
<Modal
show={show2}
onHide={handleClose}
backdrop="static"
keyboard={false}
>
<Modal.Header closeButton>
<Modal.Title>Modal title</Modal.Title>
</Modal.Header>
<Modal.Body>
I will not close if you click outside me. Don't even try to press
escape key.
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose2}>
Close
</Button>
<Button variant="primary">Understood</Button>
</Modal.Footer>
</Modal>
Scrolling long content
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.
You can also create a scrollable modal that allows scroll the modal body by adding .modal-dialog-scrollable
to .modal-dialog
.
<Button variant="primary" onClick={handleShow4}>
Launch demo modal
</Button>
<Modal scrollable={true} show={show4} onHide={handleClose4}>
<Modal.Header closeButton>
<Modal.Title>Modal title</Modal.Title>
</Modal.Header>
<Modal.Body>
<p>This is some placeholder content to show the scrolling behavior for modals. Instead of repeating the text the modal, we use an inline style set a minimum height, thereby extending the length of the overall modal and demonstrating the overflow scrolling. When content becomes longer than the height of the viewport, scrolling will move the modal as needed.</p>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<p>This content should appear at the bottom after you scroll.</p>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose4}>
Close
</Button>
<Button variant="primary" onClick={handleClose4}>
Save Changes
</Button>
</Modal.Footer>
</Modal>
Vertically centered
Add .modal-dialog-centered
to .modal-dialog
to vertically center the modal.
<Modal show={show5} onHide={handleClose5} centered={true}>
<Modal.Header closeButton>
<Modal.Title as="h5">Modal title</Modal.Title>
</Modal.Header>
<Modal.Body>
This is a vertically centered modal.
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose5}>Close</Button>
<Button variant="primary" onClick={handleClose5}>Save changes</Button>
</Modal.Footer>
</Modal>
Tooltips and popovers
Tooltips and popovers can be placed within modals as needed. When modals are closed, any tooltips and popovers within are also automatically dismissed.
<Modal show={show7} onHide={handleClose7}>
<Modal.Header closeButton>
<Modal.Title>Modal title</Modal.Title>
</Modal.Header>
<Modal.Body>
<h5>Popover in a modal</h5>
<p>This <Button href="#" variant="secondary">button</Button> triggers a popover on click.</p>
<hr/>
<h5>Tooltips in a modal</h5>
<p><Link to="#">This link</Link> and <Link to="#">that link</Link> have tooltips on hover.</p>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose7}>
Close
</Button>
<Button variant="primary" onClick={handleClose7}>
Save Changes
</Button>
</Modal.Footer>
</Modal>
Using the grid
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.
<Modal show={show8} onHide={handleClose8}>
<Modal.Header closeButton>
<Modal.Title>Grids in modals</Modal.Title>
</Modal.Header>
<Modal.Body>
<div className="mm-example-row">
<Container fluid>
<Row className="mb-3">
<Col md="4">.col-md-4</Col>
<Col md="4" className="ml-auto">.col-md-4 .ml-auto</Col>
</Row>
<Row className="mb-3">
<Col md="3" className="ml-auto">.col-md-3 .ml-auto</Col>
<Col md="2" className="ml-auto">.col-md-2 .ml-auto</Col>
</Row>
<Row className="mb-3">
<Col md="6" className="ml-auto">.col-md-6 .ml-auto</Col>
</Row>
<Row>
<Col sm="9">
Level 1: .col-sm-9
<Row>
<Col sm="6" className="col-8">
Level 2: .col-8 .col-sm-6
</Col>
<Col sm="6" className="col-4">
Level 2: .col-4 .col-sm-6
</Col>
</Row>
</Col>
</Row>
</Container>
</div>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose8}>Close</Button>
<Button variant="primary" onClick={handleClose8}>Save changes</Button>
</Modal.Footer>
</Modal>
Varying modal content
Have a bunch of buttons that all trigger the same modal with slightly different contents? Use event.relatedTarget
and HTML data-bs-*
attributes to vary the contents of the modal depending on which button was clicked.
<Modal show={show9} onHide={handleClose9}>
<Modal.Header closeButton>
<Modal.Title>New message to @mdo</Modal.Title>
</Modal.Header>
<Modal.Body>
<Form>
<Form.Group>
<Form.Label>Recipient:</Form.Label>
<Form.Control type="text"/><br/>
<Form.Label>Message:</Form.Label>
<Form.Control as="textarea" rows={3} />
</Form.Group>
</Form>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose9}>
Close
</Button>
<Button variant="primary" onClick={handleClose9}>
Save Changes
</Button>
</Modal.Footer>
</Modal>
Toggle between modals
Toggle between multiple modals with some clever placement of the data-bs-target
and data-bs-toggle
attributes. For example, you could toggle a password reset modal from within an already open sign in modal. Please note multiple modals cannot be open at the same time—this method simply toggles between two separate modals.
<Button variant="primary" className="mx-1" onClick={handleShow10}>
Open First Modal
</Button>
<Modal show={show10} onHide={handleClose10} centered={true}>
<Modal.Header closeButton>
<Modal.Title>Modal 1</Modal.Title>
</Modal.Header>
<Modal.Body>
Show a second modal and hide this one with the button below.
</Modal.Body>
<Modal.Footer>
<Button variant="primary" onClick={() => {
handleClose10();
handleShow11();
}}>
Open Second Modal
</Button>
</Modal.Footer>
</Modal>
<Modal show={show11} onHide={handleClose11} centered={true}>
<Modal.Header closeButton>
<Modal.Title>Modal 2</Modal.Title>
</Modal.Header>
<Modal.Body>
Hide this modal and show the first with the button below.
</Modal.Body>
<Modal.Footer>
<Button variant="primary" onClick={() => {
handleClose11();
handleShow10();
}}>
Back to first
</Button>
</Modal.Footer>
</Modal>
Without Animation
A Modal can also be without an animation. For that set the "animation" prop to false
.
<Modal show={show} onHide={handleClose} animation={false}>
<Modal.Header closeButton>
<Modal.Title>Modal heading</Modal.Title>
</Modal.Header>
<Modal.Body>Woohoo, you're reading this text in a modal!</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose}>
Close
</Button>
<Button variant="primary" onClick={handleClose}>
Save Changes
</Button>
</Modal.Footer>
</Modal>