--- id: css-opacity title: "CSS Opacity" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["opacity", "transparency", "image transparency", "rgba opacity", "transparent box"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["css", "web", "frontend", "w3schools", "opacity", "transparency"] raw_sources: ["https://www.w3schools.com/css/css_image_transparency.asp"] applied_in: [] github_commit: "" --- # [[CSS Opacity]] ## π― ν μ€ ν΅μ°° (One-line insight) The `opacity` property sets how transparent an element is on a 0.0β1.0 scale, but because it affects the whole element (including children), `rgba()` is preferred when only the background should be see-through. [S1] ## π§ ν΅μ¬ κ°λ (Core concepts) - **`opacity` property** β specifies the opacity/transparency of an element. [S1] - **Value range** β 0.0 is completely transparent, 1.0 is fully opaque. [S1] - **Hover interaction** β opacity can change on `:hover` to fade images in or out. [S1] - **RGBA alternative** β `rgba()` adds a fourth alpha value (0.0β1.0) to a color, making only that color transparent. [S1] ## π§© μΆμΆλ ν¨ν΄ (Extracted patterns) - **Fade-on-hover** β pair a base `opacity` with an `:hover` opacity to brighten or dim images on pointer-over. [S1] - **Transparent background only** β use `rgba()` on `background-color` so the text/children stay fully opaque while the background is see-through. [S1] - **Text-in-transparent-box** β layer a `transbox` with an `rgba()` background over a patterned background `div`. [S1] ## π μΈλΆ λ΄μ© (Details) **Opacity property** [S1] The `opacity` property specifies the opacity/transparency of an element. It can take a value from 0.0 to 1.0, where 0.0 is completely transparent and 1.0 is fully opaque. Basic image opacity: ```css img { opacity: 0.5; } ``` Transparent image that becomes opaque on hover: ```css img { opacity: 0.5; } img:hover { opacity: 1.0; } ``` Reversed hover effect (opaque image fades on hover): ```css img:hover { opacity: 0.5; } ``` Transparent box: ```css div { opacity: 0.3; } ``` **Transparency using RGBA** [S1] RGBA color values add a fourth alpha channel that specifies the opacity of the color, so only the background becomes transparent: ```css div { background: rgba(4, 170, 109, 0.3) /* Green background with 30% opacity */ } ``` **Text in a transparent box** [S1] ```html
This is some text that is placed in the transparent box.