React Modal Component

Modal

Rocket
New Year sale. Skyrocket your business in 2025!
Extra 25% off for all sale items + Free CoreUI Icons PRO with every order!
Limited-time offer for the first 100 customers in 2025. Use code 2025SKY25 at checkout.

React Modal component offers a lightweight, multi-purpose popup to add dialogs to yours. Learn how to customize CoreUI React modal components easily. Multiple examples and tutorial.

Other Frameworks

CoreUI components are available as native Angular, Bootstrap (Vanilla JS), and Vue components. To learn more please visit the following pages.

How to use React Modal Component?#

Static modal component example#

Below is a static react modal component 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 react modal headers with dismiss actions whenever possible, or provide another explicit dismiss action.

<CModal>
<CModalHeader>
<CModalTitle>React Modal title</CModalTitle>
</CModalHeader>
<CModalBody>
<p>React Modal body text goes here.</p>
</CModalBody>
<CModalFooter>
<CButton color="secondary">Close</CButton>
<CButton color="primary">Save changes</CButton>
</CModalFooter>
</CModal>

Live demo#

Toggle a working React modal component demo by clicking the button below. It will slide down and fade in from the top of the page.

Static backdrop#

If you set a backdrop to static, your React modal component will behave as though the backdrop is static, meaning it will not close when clicking outside it. Click the button below to try it.

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 react modal component that allows scroll the modal body by adding scrollable prop.

Vertically centered#

Add alignment="center to <CModal> to vertically center the React modal.

Tooltips and popovers#

<CTooltips> and <CPopovers> can be placed within react modals as needed. When modal components are closed, any tooltips and popovers within are also automatically dismissed.

Toggle between modals#

Toggle between multiple modals with some clever placement of the visible props. Please note multiple modals cannot be opened at the same time — this method simply toggles between two separate modals.

Change animation#

The variable $modal-fade-transform determines the transform state of React Modal component before the modal fade-in animation, whereas the variable $modal-show-transform determines the transform state of Modal component after the modal fade-in animation.

If you want a zoom-in animation, for example, set $modal-fade-transform: scale(.8).

Remove animation#

For modals that simply appear rather than fade into view, set transition to false.

<CModal transition={false}>...</CModal>

Accessibility#

Be sure to add aria-labelledby="...", referencing the modal title, to <CModal /> Additionally, you may give a description of your modal dialog with aria-describedby on <CModal>. Note that you don’t need to add role="dialog, aria-hidden="true", and aria-modal="true" since we already add it.

Optional sizes#

Modals have three optional sizes, available via modifier classes to be placed on a <CModal>. These sizes kick in at certain breakpoints to avoid horizontal scrollbars on narrower viewports.

SizeProperty sizeModal max-width
Small'sm'300px
DefaultNone500px
Large'lg'800px
Extra large'xl'1140px

Fullscreen Modal#

Another override is the option to pop up a React modal component that covers the user viewport, available via property fullscrean.

FullscreanAvailability
trueAlways
'sm'Below 576px
'md'Below 768px
'lg'Below 992px
'xl'Below 1200px
'xxl'Below 1400px

API#

Check out the documentation below for a comprehensive guide to all the props you can use with the components mentioned here.