---
id: css-image-modal
title: "CSS Image Modal"
category: "Frontend"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["modal image", "image lightbox", "popup image", "responsive modal", "image gallery modal"]
duplicate_of: ""
source_trust_level: "B"
confidence_score: 0.9
created_at: 2026-06-23
updated_at: 2026-06-23
review_reason: ""
merge_history: []
tags: ["css", "web", "frontend", "w3schools", "images", "modal"]
raw_sources: ["https://www.w3schools.com/css/css3_images_modal.asp"]
applied_in: []
github_commit: ""
---
# [[CSS Image Modal]]
## π― ν μ€ ν΅μ°° (One-line insight)
A modal image (lightbox) lets users click a gallery thumbnail to open a larger version in a full-screen overlay, built from a hidden fixed-position modal that JavaScript shows and hides. [S1]
## π§ ν΅μ¬ κ°λ
(Core concepts)
- **Modal overlay** β the modal is a full-viewport layer (`position: fixed`, `width: 100%`, `height: 100%`) hidden by default with `display: none` and shown via JavaScript. [S1]
- **Dim backdrop** β a semi-transparent background `rgba(0, 0, 0, 0.8)` and high `z-index: 1000` darken the page behind the enlarged image. [S1]
- **Zoom-in animation** β a `@keyframes zoomIn` animation scales the modal content from `0.6` to `1` when it opens. [S1]
- **Close control** β a `.close` "Γ" (`×`) element in the top-right corner closes the modal. [S1]
- **Caption** β a `.caption` element shows the image's label, populated from the trigger's `onclick` argument. [S1]
- **JavaScript control** β `openModal()` sets `display: "flex"` and adds a `show` class; `closeModal()` removes the class and hides the modal after a 300ms delay. [S1]
## π§© μΆμΆλ ν¨ν΄ (Extracted patterns)
- **Hidden fixed layer toggled by JS** β keep the modal `display: none`, then switch to a flex layout on demand to center the enlarged content. [S1]
- **Class-driven transition + timed teardown** β add a `show` class to animate in, and on close remove it and use `setTimeout` so the exit transition finishes before `display: none`. [S1]
- **Data passed via onclick args** β the gallery image's `onclick` passes the modal id and caption text directly into the handler. [S1]
## π μΈλΆ λ΄μ© (Details)
The W3Schools example builds a responsive modal image gallery in a single HTML document combining CSS and JavaScript. [S1]
```html
Responsive Modal Images
×
×
×
×
```
**Key components**
- **Modal container** β `display: none` initially, `position: fixed`, `z-index: 1000`, dark semi-transparent background `rgba(0, 0, 0, 0.8)`. [S1]
- **Animation** β zoom effect defined with `@keyframes zoomIn` scaling from `0.6` to `1`. [S1]
- **JavaScript** β `openModal()` retrieves the element by id, sets display to `flex`, adds the `show` class, and populates the caption; `closeModal()` removes the `show` class and hides the modal after a 300ms delay. [S1]
- **Responsive design** β media queries adjust gallery items from `25%` width (desktop) to `50%` (tablets, β€768px) to `100%` (mobile, β€480px). [S1]
## π οΈ μ μ© μ¬λ‘ (Applied in summary)
The full responsive modal-image gallery above is the source's applied case, integrating a flex gallery, a fixed overlay modal, a zoom animation, a close button, captions, and the open/close JavaScript. No external project/commit applications found in the source.
## π» μ½λ ν¨ν΄ (Code patterns)
Toggle-by-class modal control (language: JavaScript):
```javascript
function openModal(modalId, caption) {
let modal = document.getElementById(modalId);
modal.style.display = "flex";
modal.classList.add("show");
modal.querySelector(".caption").innerText = caption;
}
function closeModal(modalId) {
let modal = document.getElementById(modalId);
modal.classList.remove("show");
setTimeout(function () {
modal.style.display = "none";
modal.querySelector(".caption").innerText = "";
}, 300);
}
```
## βοΈ λͺ¨μ λ° μ
λ°μ΄νΈ (Contradictions & updates)
No contradictions found in the source.
## β
κ²μ¦ μν λ° μ λ’°λ
- **μν:** draft
- **κ²μ¦ λ¨κ³:** conceptual (μ€μ μ μ© μ¬λ‘ λ°κ²¬ μ applied/validatedλ‘ μΉκ²© κ°λ₯)
- **μΆμ² μ λ’°λ:** B (W3Schools β widely used educational reference, not a primary standards body)
- **μ λ’° μ μ:** 0.90
- **μ€λ³΅ κ²μ¬ κ²°κ³Ό:** μ κ· μμ± (New discovery)
## π μ§μ κ·Έλν (Knowledge Graph)
- **μμ/루νΈ:** [[CSS Tutorial]]
- **κ΄λ ¨ κ°λ
:** [[CSS Image Hover]], [[CSS Image Styling]], [[CSS Animations]], [[CSS Position]]
- **μ°Έμ‘° λ§₯λ½:** Referenced when building an image lightbox or click-to-enlarge gallery.
## π μΆμ² (Sources)
- [S1] W3Schools β CSS Image Modal β https://www.w3schools.com/css/css3_images_modal.asp
## π λ³κ²½ μ΄λ ₯ (Change history)
- 2026-06-23: Initial draft synthesized from the W3Schools "CSS Image Modal" page (Astra wiki-curation, P-Reinforce v3.1 format).