--- id: web-anchor-positioning-css title: CSS Anchor Positioning / @scope / Speculation Rules category: Coding status: draft source_trust_level: B verification_status: conceptual created_at: 2026-05-09 updated_at: 2026-05-09 tags: [web, css, vibe-coding] tech_stack: { language: "CSS", applicable_to: ["Frontend"] } applied_in: [] aliases: [CSS anchor, anchor positioning, @scope, speculation rules, prerender, modern CSS] --- # Modern CSS Features > Floating UI / scoped CSS / prerender 의 native. **Anchor (Chrome 125+), @scope (Chrome 118+), Speculation Rules (Chrome 110+)**. ## πŸ“– 핡심 κ°œλ… - Floating element 의 native (anchor). - CSS-in-JS 의 scoped CSS native. - Speculative prerender / preload. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ ### Anchor positioning ```html
Hello
``` ```css #trigger { anchor-name: --my-trigger; } .tooltip { position: absolute; position-anchor: --my-trigger; top: anchor(bottom); /* λ§€ anchor 의 bottom */ left: anchor(center); /* λ˜λŠ” */ position-area: bottom; } ``` β†’ JS / Floating UI 없이 popover position. ### position-area (λ‹¨μˆœ) ```css .tooltip { position-anchor: --trigger; position-area: bottom; } ``` β†’ "anchor 의 bottom" 식 declarative. ### Try alternatives (fallback) ```css .tooltip { position-anchor: --trigger; position-area: bottom; position-try-fallbacks: bottom right, top left, top right; } ``` β†’ Viewport edge μ‹œ λ‹€λ₯Έ position. ### Popover + anchor ```html
Content
``` β†’ Popover + anchor = native modal. ### @scope (CSS scoping) ```html

Title

Body

``` ```css @scope (.card) { h2 { color: blue; } p { font-size: 14px; } } ``` β†’ `.card` μ•ˆ 만 적용. CSS-in-JS 없이. ### @scope to (limit) ```css @scope (.card) to (.card-children) { h2 { color: blue; } } ``` β†’ `.card-children` 의 descendant κ°€ μ•ˆ λ°›μŒ. ### CSS nesting (related) ```css .card { padding: 16px; & h2 { font-size: 1.5rem; } } ``` ### Speculation Rules (prerender) ```html ``` β†’ Hover μ‹œ prerender. Click = instant. ### Eagerness ``` - conservative: explicit only (anchor click). - moderate: hover. - eager: visible link. - immediate: λ§€ link. ``` β†’ Cost vs UX trade-off. ### Prefetch (lighter) ```html ``` β†’ HTML / resource preload (no execute). ### Container queries ```css .card { container-type: inline-size; } @container (min-width: 400px) { .card-content { display: grid; grid-template-columns: 1fr 1fr; } } ``` β†’ Component 의 size 따라 layout. ### Container query units ```css .card { container-type: inline-size; container-name: card; } .card h2 { font-size: 5cqw; /* 5% of card width */ } ``` β†’ `cqw, cqh, cqi, cqb` κ°€ container 의 width / height. ### View timeline ```css @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } } .fade { animation: fade-in linear; animation-timeline: view(); animation-range: entry 0% cover 30%; } ``` β†’ Scroll μœ„μΉ˜ 따라 animation. JS 없이. ### Scroll timeline ```css .progress { animation: progress-bar linear; animation-timeline: scroll(); } @keyframes progress-bar { from { width: 0%; } to { width: 100%; } } ``` β†’ Page scroll 따라 progress bar. ### Color modern ```css :root { --primary: oklch(0.7 0.15 270); } .button:hover { background: oklch(from var(--primary) 0.6 c h); /* darker */ } ``` β†’ OKLCH = perceptual uniform color. ### color-mix() ```css .button { background: color-mix(in oklch, var(--primary) 70%, white); } ``` β†’ Mix 2 color. ### relative colors ```css .button:hover { background: oklch(from var(--primary) calc(l * 0.8) c h); } ``` β†’ κΈ°μ‘΄ color 의 lighter / darker μžλ™. ### :has() selector ```css .card:has(img) { padding-top: 0; } form:has(input:invalid) { border-color: red; } ``` β†’ Parent κ°€ child 따라 style. Game-changing. ### subgrid ```css .parent { display: grid; grid-template-columns: 1fr 1fr 1fr; } .child { display: grid; grid-template-columns: subgrid; } ``` β†’ Child κ°€ parent 의 grid μ‚¬μš©. ### Browser support ``` - Anchor: Chrome 125+, FF flag. - @scope: Chrome 118+. - Speculation Rules: Chrome 110+. - Container queries: λͺ¨λ“  modern. - :has(): λͺ¨λ“  modern. - View Timeline: Chrome 115+. - OKLCH: λͺ¨λ“  modern. - Subgrid: λͺ¨λ“  modern (Safari 16+). ``` β†’ Caniuse κ°€ reality. ### Polyfill / fallback ```css .tooltip { /* Fallback */ position: absolute; top: 100%; left: 50%; /* Modern */ position-anchor: --trigger; position-area: bottom; } ``` β†’ Progressive enhancement. ### Use case ``` Anchor: tooltip, popover, dropdown. @scope: component-scoped CSS. Speculation: navigation 빠름. Container: responsive component. :has(): conditional layout. View Timeline: scroll-based animation. ``` ### vs Floating UI library ``` Floating UI: - JavaScript (3 KB). - λͺ¨λ“  browser. - μ •λ°€ control. Native anchor: - 0 JS. - Modern browser only. - CSS declarative. β†’ Modern only = native. Cross-browser = library. ``` ### vs CSS-in-JS ``` CSS-in-JS: - JavaScript runtime. - Dynamic style. - 큰 bundle. @scope: - Native CSS. - Build-time. - μž‘μ€. β†’ Modern = @scope. ``` ### Production examples - **Astro / Next**: View Transitions. - **Tailwind 4**: Lightning CSS + container. - **Vercel docs**: Speculation Rules. - **Apple**: scroll animation. ### LLM / Cursor 도움 ``` Modern CSS κ°€ LLM 의 baked. - Generate anchor positioning. - @scope μž‘μ„±. - :has() pattern. β†’ μž‘μ€ bundle + clean code. ``` ### 함정 ``` - Anchor κ°€ Chrome 만: fallback ν•„μˆ˜. - Container 의 layout κ°€ ambiguous: type λͺ…μ‹œ. - :has() 의 performance: 맀우 큰 tree κ°€ slow. - View Timeline 의 timing μ •λ°€ X. - Speculation Rules cost: prerender κ°€ page render. ``` ## πŸ€” μ˜μ‚¬κ²°μ • κΈ°μ€€ | μž‘μ—… | μΆ”μ²œ | |---|---| | Floating UI | Anchor (modern) / Floating UI | | Component CSS | @scope | | Page navigation | Speculation Rules | | Responsive component | Container queries | | Conditional layout | :has() | | Scroll animation | View Timeline | | Color | OKLCH | ## ❌ μ•ˆν‹°νŒ¨ν„΄ - **Anchor + no fallback**: Safari 깨짐. - **λͺ¨λ“  νŽ˜μ΄μ§€ prerender**: cost. - **Container κ°€ type μ•ˆ**: ignore. - **:has() 큰 tree**: performance. - **CSS-in-JS + @scope λ‘˜ λ‹€**: redundant. ## πŸ€– LLM ν™œμš© 힌트 - Anchor positioning κ°€ Chrome 125+. - @scope κ°€ native CSS-in-JS. - Speculation Rules κ°€ prerender. - :has() κ°€ game-changing parent selector. ## πŸ”— κ΄€λ ¨ λ¬Έμ„œ - [[Frontend_CSS_Modern_Features]] - [[Frontend_Container_Queries]] - [[Web_Origin_Trial_Platform]]