Skip to content
Learn Netverks

Lesson

Step 24/36 67% through track

modals-dialog

Modals with dialog

Last reviewed May 28, 2026 Content v20260528
Track mode
iframe_html
Means
HTML preview sandbox
Reading
~2 min
Level
intermediate

This lesson

This lesson teaches Modals with dialog—the ideas, syntax, and habits you need before moving on in Pico CSS.

Class-light frameworks teach when semantic HTML alone should carry the design.

You will apply Modals with dialog in contexts like: Documentation sites, blogs, internal tools, and side projects where you want polish without a large class vocabulary.

Read the lesson, edit HTML/CSS in the playground, press Run to preview, then answer the lesson MCQs.

Toward the end of the track—use it to consolidate patterns before the capstone or summary lessons.

Pico’s modal pattern is the native <dialog> wrapping an article. Headers can include a close button with rel="prev" (Pico floats it top-right); footers align action buttons to the end.

Opening and closing

Add the open attribute for static previews in the playground. In apps, call showModal() and close() on the element. Optional utility classes on htmlmodal-is-open, modal-is-opening, modal-is-closing—control scroll lock and animations (not available in classless CSS).

Compared to Bootstrap modals

Bootstrap needs data-bs-toggle and a large markup tree. Pico styles semantic dialog markup; you own the small script layer—same trade-off as other CSS-only frameworks.

Important interview questions and answers

  1. Q: Why prefer dialog over a styled div overlay?
    A: Built-in top layer, focus management hooks, and standardized close behavior with showModal() / close().
  2. Q: Does Pico provide modal JavaScript?
    A: No—only CSS; you wire HTMLDialogElement or a framework equivalent.

Self-check

  1. Which child element carries the modal title and close control?
  2. What method opens a modal in the top layer?

Challenge

Native dialog

  1. Use <dialog> with a trigger button.
  2. Open with showModal() in a tiny inline script if needed.

Done when: dialog opens with Pico styling and closes via the native close control.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • dialog vs div modal?
  • Close mechanism?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump