--- id: css-dropdowns title: "CSS Dropdowns" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["dropdown", "CSS dropdown menu", "hover dropdown", "dropdown box", "pure CSS dropdown"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.89 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["css", "web", "frontend", "w3schools", "dropdown", "hover", "menu"] raw_sources: ["https://www.w3schools.com/css/css_dropdowns.asp"] applied_in: [] github_commit: "" --- # [[CSS Dropdowns]] ## π― ν μ€ ν΅μ°° (One-line insight) A CSS dropdown reveals hidden content on hover by combining a `position: relative` wrapper, an absolutely positioned `display: none` content box, and a `:hover` rule that flips it to `display: block` β no JavaScript required. [S1] ## π§ ν΅μ¬ κ°λ (Core concepts) - **Dropdown** β a UI element that displays content (text, links, images) when the user moves over or interacts with a trigger element such as a `div`, `button`, `p`, or `a`. [S1] - **Wrapper positioning** β the outer `.dropdown` container is given `position: relative` so the dropdown content can be positioned relative to it. [S1] - **Hidden-by-default content** β `.dropdown-content` starts at `display: none` and `position: absolute`, so it does not occupy space until shown. [S1] - **Hover reveal** β the `.dropdown:hover .dropdown-content` rule sets `display: block`, exposing the content while the pointer is over the wrapper. [S1] - **Visual depth** β a `box-shadow` is used to give the dropdown box a floating, layered appearance. [S1] ## π§© μΆμΆλ ν¨ν΄ (Extracted patterns) - **Relative-parent / absolute-child** β pair a `position: relative` wrapper with a `position: absolute` content box so the box anchors to the wrapper. [S1] - **Hover toggle** β switch a child from `display: none` to `display: block` via a parent `:hover` descendant selector, achieving show/hide without scripting. [S1] - **Styled trigger button** β a `.dropbtn` class styles the trigger (background color, padding, no border, pointer cursor) and changes color on parent hover. [S1] ## π μΈλΆ λ΄μ© (Details) **What is a CSS dropdown?** A CSS dropdown is a UI element that displays content when users click or hover over a trigger element like a button or link. The trigger can be a `div`, `button`, `p`, or `a` tag, and the hidden dropdown content displays on interaction. [S1] **Example 1 β Dropdown Box with Text** A basic hoverable dropdown. The parent uses `position: relative`; the `.dropdown-content` is hidden (`display: none`) and absolutely positioned, with a `min-width` of `130px` and a `box-shadow` for depth. The `:hover` selector reveals it: [S1] ```html