Modal

✅ To create a modal, we use the <dialog> element, which is natively supported in most modern browsers. For more information, visit MDN.

Dialog modal

Add a unique id to the <dialog id="myModal"> HTML element, then use that id in JavaScript to call `myModal.showModal()` to open the modal and `myModal.close()` to close the modal.

Close modal when click outside

The .modal-backdrop provides a clickable background that closes the modal when clicked outside the modal content.

Modal Slide Animations

Smoothly slide in and out from the top, bottom, start (left in LTR, right in RTL), or end (right in LTR, left in RTL) with the following directional utility classes: modal-slide-top, modal-slide-bottom, modal-slide-start, and modal-slide-end in the modal component. These animations improve the user experience through the use of dynamic transitions based on modal position.

Slide from Start (Horizontal): modal-slide-start

➡️ Direction: Slides in horizontally from the start side

  • LTR: from the left
  • RTL: from the right

Slide from End (Horizontal): modal-slide-end

➡️ Direction: Slides in horizontally from the end side

  • LTR: from the right
  • RTL: from the left

Slide from Bottom (Vertical): modal-slide-up

➡️ Direction: Slides in vertically from the bottom

Slide from Top (Vertical): modal-slide-down

➡️ Direction: Slides in vertically from the top

Example usage of sliding animation modal for notification

Modal placements

The modal component is by default positioned in the center of the screen, but it can be placed depending upon the use case using utility classes such as modal-x-{position} and modal-y-{position}, where {position} is start, center, or end. Placement is designed with RTL and LTR compatibility in mind, making the modal adaptable to different language directions and layouts.

Use `modal-x-{position}` for horizontal placement and `modal-y-{position}` for vertical placement, where `{position}` can be `start`, `center`, or `end`. These classes are applied to the modal component.

Top left modal placement

Top center modal placement

Top right modal placement

Center left modal placement

Center right modal placement

Bottom left modal placement

Bottom center modal placement

Bottom right modal placement

Responsive positioning of modal for desktop and mobile screens

Depending on your use case, you can position the modal anywhere on desktop or mobile—for example, desktop center and mobile top center.

Modal positioning based on language direction

Place the modal wherever on the screen depending on the language direction (LTR or RTL).

Right center on LTR and left center on RTL

Place the modal based on screen size and language direction.

Website built with Frutjam UI library