Modal

A modal displays content that temporarily blocks interactions with the main view of a site.
Example
Theme
Auto
Auto
Light
Dark
Scale
Medium
Large
Medium
Small
Modal Title
On the construction site, crackling sounds like a symphony of building.
<dialog class="ts-modal" open>
    <div class="content">
        <div class="ts-content">
            <div class="ts-header">Modal Title</div>
        </div>
        <div class="ts-divider"></div>
        <div class="ts-content">
            On the construction site,
            crackling sounds like a symphony of building.
        </div>
    </div>
</dialog>
Structure

Main content is placed inside the content block. For a title and action bar, see the Compositions section below.

<dialog class="ts-modal" open>
    <div class="content">
        <!-- ... -->
    </div>
</dialog>
States
Open

A modal with the [open] attribute will appear on the screen.

You are banned from the fishing competition for being "too pro at baiting on the internet."
<dialog class="ts-modal" open>
    <div class="content">
        <div class="ts-content">
            You are banned from the fishing competition
            for being "too pro at baiting on the internet."
        </div>
    </div>
</dialog>
Variations
Sizes

A modal can vary in size.

Small Modal
Default Modal
Large Modal
<dialog class="ts-modal is-small" open>
    <div class="content">
        <div class="ts-content is-center-aligned">
            Small Modal
        </div>
    </div>
</dialog>
<dialog class="ts-modal" open>
    <div class="content">
        <div class="ts-content is-center-aligned">
            Default Modal
        </div>
    </div>
</dialog>
<dialog class="ts-modal is-large" open>
    <div class="content">
        <div class="ts-content is-center-aligned">
            Large Modal
        </div>
    </div>
</dialog>
Fullscreen

A modal can fill the entire screen; this is useful for mobile device with Responsive.

Build connections for community.
Our primary goal is to build connections between people and provide a supportive environment for content creation. Everyone should have the freedom to create without restrictions.
<dialog class="ts-modal is-fullscreen" open>
    <div class="content">
        <div class="ts-content">
            <div class="ts-header">Build connections for community.</div>
        </div>
        <div class="ts-divider"></div>
        <div class="ts-content">
            Our primary goal is to build connections between people and provide a supportive environment for content creation. Everyone should have the freedom to create without restrictions.
        </div>
        <div class="ts-divider"></div>
        <div class="ts-content is-tertiary">
            <button class="ts-button">Close</button>
        </div>
    </div>
</dialog>
Compositions

Use Grid to add a Header and Close to the modal.

Supreme Agreement
We hope this agreement will prevent future deviations from our original ideals. As the name suggests, all definitions in the supreme agreement are core conditions that our services must follow.
<dialog class="ts-modal" open>
    <div class="content">
        <div class="ts-content">
            <div class="ts-grid">
                <div class="column is-fluid">
                    <div class="ts-header">Supreme Agreement</div>
                </div>
                <div class="column">
                    <button class="ts-close is-large is-secondary"></button>
                </div>
            </div>
        </div>
        <div class="ts-divider"></div>
        <div class="ts-content">
            We hope this agreement will prevent future deviations from our original ideals. As the name suggests, all definitions in the supreme agreement are core conditions that our services must follow.
        </div>
    </div>
</dialog>
Actions

Create an action bar with secondary Content, Buttons, and an end-aligned Wrap.

Enter the Username
<dialog class="ts-modal" open>
    <div class="content">
        <div class="ts-content">
            <div class="ts-header">Enter the Username</div>
        </div>
        <div class="ts-divider"></div>
        <div class="ts-content">
            <div class="ts-input">
                <input type="text" value="Yami Odymel" />
            </div>
        </div>
        <div class="ts-divider"></div>
        <div class="ts-content is-tertiary">
            <div class="ts-wrap is-end-aligned">
                <button class="ts-button">Confirm</button>
                <button class="ts-button is-outlined">Cancel</button>
            </div>
        </div>
    </div>
</dialog>
Warning

Create a warning modal with an icon Header.

Rebooting System

This procedure will take at least half an hour.

<dialog class="ts-modal" open>
    <div class="content">
        <div class="ts-content is-center-aligned is-padded">
            <div class="ts-header is-icon">
                <span class="ts-icon is-bomb-icon"></span>
                Rebooting System
            </div>
            <p>This procedure will take at least half an hour.</p>
        </div>
        <div class="ts-divider"></div>
        <div class="ts-content is-tertiary">
            <button class="ts-button is-fluid">OK</button>
        </div>
    </div>
</dialog>

A Content block with overflow-y: auto allows the text to scroll when it exceeds the height of the block.

Terms of Use

The comprehensive planning to consider during the "design" phase, the self-expectations and "attitude" towards things, and the crucial "execution" methods. Regardless, the design should be aimed at the public and operated with their input; the attitude towards dreams should never waver; and while executing, one should not forget the original intention.

<dialog class="ts-modal" open>
    <div class="content">
        <div class="ts-content">
            <div class="ts-header">Terms of Use</div>
        </div>
        <div class="ts-divider"></div>
        <div class="ts-content" style="max-height: 170px; overflow-y: auto">
            <p>The comprehensive planning to consider during the "design" phase, the self-expectations and "attitude" towards things, and the crucial "execution" methods. Regardless, the design should be aimed at the public and operated with their input; the attitude towards dreams should never waver; and while executing, one should not forget the original intention.</p>
        </div>
        <div class="ts-divider"></div>
        <div class="ts-content">
            <label class="ts-checkbox">
                <input type="checkbox" checked />
                I have read and agree to all of the above.
            </label>
        </div>
        <div class="ts-divider"></div>
        <div class="ts-content is-tertiary">
            <button class="ts-button is-fluid">OK</button>
        </div>
    </div>
</dialog>
JavaScript Features

Clicking a button with the [data-dialog] attribute opens or closes the modal with the corresponding [id].

Modal Title

Click the close button or the gray area to close the modal.

<button class="ts-button" data-dialog="modal">
    Open Modal ✨
</button>
<dialog class="ts-modal" id="modal">
    <div class="content">
        <div class="ts-content">
            <div class="ts-header">Modal Title</div>
        </div>
        <div class="ts-divider"></div>
        <div class="ts-content">
            <p>Click the close button or the gray area to close the modal.</p>
        </div>
        <div class="ts-divider"></div>
        <div class="ts-content is-tertiary is-end-aligned">
            <button class="ts-button" data-dialog="modal">Close</button>
        </div>
    </div>
</dialog>

Open the modal with the native .showModal() function. It has no effect if the modal already has the [open] attribute. When closed, it triggers the close or cancel event.

// Open the `#modal` modal.
document.querySelector("#modal").showModal();

// Close the `#modal` modal.
document.querySelector("#modal").close();
Properties
Description

If the modal can be closed by pressing the Esc key or clicking the gray area.

CSS Variables
Description

The width of the modal.

Designed by Yami Odymel from Taiwan, along with the ❤️ from contributors. The source code is licensed under MIT, and the documentation is under CC 0 public domain. Feel free to use, share, or contribute. Tocas UI is a design system for Caris Events, part of Sorae & Co., Ltd.
Translators: Yami Odymel
Trademark of the owner of Tocas UI