CSS Modal Generator

Results

A modal dialog is a full-screen overlay with a panel on top: the backdrop dims the page and blocks interaction, the panel holds the title, content and action buttons. This generator writes the CSS for that structure with five classes: .modal-backdrop, .modal-panel, .modal-header, .modal-body and .modal-actions. You set the panel width, corner radius and accent color, then copy the snippet into your project.

How to generate a modal style

  1. 1

    Set the panel width

    Enter the target width in pixels. The panel uses `min(100%, Npx)`, so it shrinks to fit small screens.

  2. 2

    Choose the corner radius

    Pick the rounding of the panel corners, from a sharp square to a fully rounded card.

  3. 3

    Pick the accent color

    Select the color of the 4 px accent bar on top of the header.

  4. 4

    Copy the CSS

    Copy the snippet and match the class names in your markup: backdrop, panel, header, body and actions.

What the generated CSS covers

The snippet styles five classes:

  • .modal-backdrop: fixed full-screen layer, dark translucent background (rgba(17, 24, 39, .62)), centered grid, 24 px padding around the panel.
  • .modal-panel: white card, width min(100%, Npx), your corner radius, soft shadow, clipped corners.
  • .modal-header: 4 px accent bar in your color, then the heading area with 20 px 24 px padding.
  • .modal-body: the content area, 18 px 24 px padding.
  • .modal-actions: a right-aligned row of buttons with a 10 px gap.

Matching HTML structure

The CSS expects this markup:

<div class="modal-backdrop">
  <div class="modal-panel">
    <div class="modal-header">
      <h2>Confirm</h2>
    </div>
    <div class="modal-body">
      <p>Are you sure you want to continue?</p>
    </div>
    <div class="modal-actions">
      <button>Cancel</button>
      <button>Continue</button>
    </div>
  </div>
</div>

Keep the panel inside the backdrop: the backdrop is the fixed layer and the panel is centered inside it. To open and close the modal, mount and unmount the backdrop from your application code, or toggle its display.

Fitting small screens

The panel width is capped with min(100%, Npx), so a 520 px setting becomes the full viewport width on a narrow phone, minus the 24 px backdrop padding. The actions row keeps its right alignment, and long content scrolls with the page. No media queries are needed for the common cases.

Notes and limits

The generator produces CSS only. It does not include JavaScript to open or close the modal, trap keyboard focus, or handle the ESC key. Add that logic in your application.

The header keeps its 4 px accent bar at all times; if you do not need it, remove or recolor the rule in the copied code.

Frequently Asked Questions

A fixed dark backdrop, a centered white panel with your width and corner radius, a header with an accent bar, a content area and a right-aligned action row. Five classes ready to paste into your stylesheet.

CSS only. The snippet defines five classes; you match them in your own markup and handle open and close with your own script.

The panel width is capped with min(100%, Npx), so on a narrow phone the panel fills the available width minus 24 px of backdrop padding. The actions row stays right-aligned.

The generator does not ship JavaScript. Toggle the backdrop element from your application, for example with a small script that shows it on a button click and hides it again afterwards.

Related Tools

Tool available in other languages