Modal

DaisyUI

Modal is used to show a dialog or a box when you click a button.

There are 3 methods: HTML dialog (recommended), checkbox (legacy), and anchor links (legacy).

Method 1: HTML dialog element (recommended)

Open with JS document.getElementById('ID').showModal(). Close with ESC key or dialog button.

Dialog Modal

Basic modal opened with showModal().

Close on Backdrop Click

Add a second form with modal-backdrop class.

Close Button at Corner

Place a form with btn-circle button inside modal-box.

Custom Width

Use any w-* and max-w-* utility class on modal-box.

Responsive

Bottom on SM, middle on MD using responsive prefixes.

Placements

Top, bottom, start, end positions.

Method 2: Checkbox (legacy)

A hidden checkbox controls the state. Labels toggle the checkbox to open/close.

Checkbox Modal

Toggle using a hidden checkbox and label.

Checkbox + Backdrop Close

Use modal-backdrop label to close when clicked outside.

Method 3: Anchor links (legacy)

A link adds a URL hash. The modal is visible only when the URL contains that hash.

Anchor Modal

Open/close using anchor links.

open modal
Code Example
use rsxui::components::{Modal, ModalBox, ModalAction, ModalPlacement};
use rsx_macros::rsx;
// Trigger button + dialog modal
let html = rsx! {
    <button onclick="document.getElementById('my_modal').showModal()">
        "open modal"
    </button>
    <Modal id="my_modal" placement=ModalPlacement::Middle>
        <ModalBox>
            <h3>"Hello!"</h3>
            <ModalAction>
                <form method="dialog">
                    <button class="btn">"Close"</button>
                </form>
            </ModalAction>
        </ModalBox>
    </Modal>
};