--- id: css-linear-gradients title: "CSS Linear Gradients" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["linear-gradient", "CSS gradients", "repeating-linear-gradient", "gradient background", "CSS color transitions"] 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", "gradients", "linear-gradient", "background-image"] raw_sources: ["https://www.w3schools.com/css/css3_gradients.asp"] applied_in: [] github_commit: "" --- # [[CSS Linear Gradients]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) CSS gradients let you display smooth transitions between two or more specified colors; a linear gradient (`linear-gradient()`) runs along a straight line whose direction you set with keywords or an angle, and it is applied through the `background-image` property. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Gradients = smooth color transitions** β€” CSS gradients display smooth transitions between two or more specified colors. [S1] - **Three gradient types** β€” CSS defines linear gradients (going straight in a line), radial gradients (defined by a center point), and conic gradients (rotated around a center point). [S1] - **Applied via `background-image`** β€” gradient functions are used as the value of the `background-image` property. [S1] - **Linear gradient needs β‰₯ 2 color stops** β€” you must define at least two color stops; the gradient transitions between them. [S1] - **Direction is optional** β€” you can specify a direction (with keywords like `to bottom`/`to right`) or an angle; if omitted, the default is top to bottom. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Direction-keyword pattern** β€” `linear-gradient(to , color1, color2)` to flow toward a side or corner. [S1] - **Angle pattern** β€” `linear-gradient(, color1, color2)` for precise gradient angles. [S1] - **Multi-stop pattern** β€” list more than two colors to create banded/rainbow transitions. [S1] - **Transparency pattern** β€” use `rgba()` colors whose alpha varies to fade a gradient in or out. [S1] - **Repeating pattern** β€” `repeating-linear-gradient()` repeats a percentage-defined color sequence. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **Syntax** [S1] ``` background-image: linear-gradient(direction, color-stop1, color-stop2, ...); ``` A linear gradient requires at least two color stops, and you may specify a direction or an angle. **Top to Bottom (this is default)** [S1] ```css #grad { background-image: linear-gradient(to bottom, red, yellow); } ``` **Bottom to Top** [S1] ```css #grad { background-image: linear-gradient(to top, red, yellow); } ``` **Left to Right** [S1] ```css #grad { background-image: linear-gradient(to right, red, yellow); } ``` **Diagonal (top-left to bottom-right)** [S1] ```css #grad { background-image: linear-gradient(to bottom right, red, yellow); } ``` **Using Angles** [S1] If you want more control over the direction of the gradient, you can define an angle instead of the predefined directions. The angle is specified as an angle between a horizontal line and the gradient line. Reference values: `0deg` = bottom to top, `90deg` = left to right, `180deg` = top to bottom, `270deg` = right to left. ```css #grad { background-image: linear-gradient(180deg, red, yellow); } ``` **Using Multiple Color Stops** [S1] ```css #grad { background-image: linear-gradient(red, yellow, green); } ``` Rainbow example: ```css #grad { background-image: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet); } ``` **Using Transparency** [S1] CSS gradients also support transparency, which can be used to create fading effects. To add transparency, use the `rgba()` function to define the color stops. The last parameter in the `rgba()` function is the alpha value, defining the opacity: 0 indicates full transparency, 1 indicates full color (no transparency). ```css #grad { background-image: linear-gradient(to right, rgba(255,0,0,0), rgba(255,0,0,1)); } ``` **Repeating a linear-gradient** [S1] The `repeating-linear-gradient()` function is used to repeat linear gradients. ```css #grad { background-image: repeating-linear-gradient(red, yellow 10%, green 20%); } ``` ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own demonstrations (the `#grad` element styled with each direction, angle, multi-stop, transparency, and repeating example) serve as the applied examples. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Linear gradient with a direction keyword (language: CSS): ```css #grad { background-image: linear-gradient(to right, red, yellow); } ``` Linear gradient by angle: ```css #grad { background-image: linear-gradient(180deg, red, yellow); } ``` Repeating linear gradient: ```css #grad { background-image: repeating-linear-gradient(red, yellow 10%, green 20%); } ``` ## βš–οΈ 비ꡐ 및 선택 κΈ°μ€€ (Comparison & decision criteria) - **Direction keyword vs angle** β€” keywords (`to bottom`, `to right`, `to bottom right`) cover the common axes and corners; an explicit angle (`0deg`/`90deg`/`180deg`/`270deg`) gives more precise control over the gradient direction. [S1] - **Single gradient vs repeating** β€” use `linear-gradient()` for a one-time transition across the box; use `repeating-linear-gradient()` when the percentage-defined color sequence should tile/repeat. [S1] - **Solid color stops vs `rgba()`** β€” use `rgba()` color stops when a fading (transparency) effect is desired rather than an opaque transition. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (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 Radial Gradients]], [[CSS Conic Gradients]], [[CSS Box Shadow]] - **μ°Έμ‘° λ§₯락:** Referenced whenever a smooth, direction-based color background is needed via `background-image`. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” CSS Linear Gradients β€” https://www.w3schools.com/css/css3_gradients.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "CSS Linear Gradients" page (Astra wiki-curation, P-Reinforce v3.1 format).