Files
2nd/10_Wiki/Topic_Programming/Topic_CSS/CSS_Variables.md
T
Antigravity Agent e9cbf23ab5 docs(10_Wiki): Dev 폴더 누락분 반영 — Topic_Programming으로 통합
이전 재구성 작업에서 Dev/ 폴더가 누락되었던 것을 반영.

- Dev/Topic_Programming(중첩 폴더, 78개)은 Dev 자체 최상위 폴더들
  (Architecture/Conventions/Engineering_Intelligence 등)과 완전 중복이라 제거.
- Dev 최상위 엔지니어링 지식 폴더(Architecture/Conventions/Engineering_Intelligence/
  Failure_Library/Generalized_Principles/Language/Pattern_Catalog/Platform_Guides/
  Subsystems, 77개)는 이미 Topic_Programming/Topic_Programming에 더 최신 버전이
  존재해 중복 제거(고유 콘텐츠 1개는 예외 처리하여 이동 보존).
- Dev의 W3Schools 언어 튜토리얼 폴더(Topic_C/CPP/CSS/CSharp/HOWTO/HTML/Java/
  JavaScript/PHP/Python/SQL/W3CSS, 1201개)는 전부 Topic_Programming 하위로 이동.
- 에이전트 운영 상태(.astra/docs)는 그대로 유지, 콘텐츠 폴더만 정리.
- Topic_Programming 최종 문서 수: 2784 → 3985.
2026-07-05 00:39:13 +09:00

5.5 KiB

id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
id title category status verification_status canonical_id aliases duplicate_of source_trust_level confidence_score created_at updated_at review_reason merge_history tags raw_sources applied_in github_commit
css-variables-var CSS Variables var() Frontend draft conceptual
CSS variables
var() function
custom properties
CSS custom properties
root variables
--variable
B 0.89 2026-06-23 2026-06-23
css
web
frontend
w3schools
variables
custom-properties
var
https://www.w3schools.com/css/css3_variables.asp

CSS Variables var()

🎯 한 줄 통찰 (One-line insight)

CSS variables (custom properties) are declared with a --name and read back with var(--name); declaring them once in :root gives document-wide reusable values that make stylesheets easier to maintain and update. [S1]

🧠 핵심 개념 (Core concepts)

  • Global vs local — global variables are declared in the :root selector for document-wide access; local variables are declared within a specific selector for limited scope. [S1]
  • Naming rules — variable names must begin with two dashes (--) and are case-sensitive. [S1]
  • The var() function — the syntax is var(--name, value), where the name is required and value is an optional fallback. [S1]
  • Why use them — the main advantages are easier maintenance, improved readability, and simplified color updates across an entire page. [S1]

🧩 추출된 패턴 (Extracted patterns)

  • Theme tokens in :root — declaring colors as :root variables creates a single place to change a whole page's palette. [S1]
  • Reuse via var() — the same var(--primary-bg-color) reference reused across selectors keeps related values in sync. [S1]
  • Fallback safetyvar(--name, value) supplies a default when the named variable is not defined. [S1]

📖 세부 내용 (Details)

Declaring variables [S1] Global variables are declared in the :root selector; local variables within a specific selector. Names start with -- and are case-sensitive:

:root {
  --primary-bg-color: green;
}

.note {
  --note-bg: yellow;
}

The var() Function [S1] The var() function is used to insert the value of a CSS variable. Its syntax is var(--name, value)--name is the required variable name, and value is an optional fallback used if the variable is not found.

Example — global variables used across selectors [S1]

:root {
  --primary-bg-color: #1e90ff;
  --primary-color: #ffffff;
}

body {
  background-color: var(--primary-bg-color);
}

.container {
  color: var(--primary-bg-color);
  background-color: var(--primary-color);
  padding: 15px;
}

.container h2 {
  border-bottom: 2px solid var(--primary-bg-color);
}

.container .note {
  border: 1px solid var(--primary-bg-color);
  padding: 10px;
}

Example — swapping the color scheme by changing only the variables [S1]

:root {
  --primary-bg-color: #8FBC8F;
  --primary-color: #FFFAF0;
}

body {
  background-color: var(--primary-bg-color);
}

.container {
  color: var(--primary-bg-color);
  background-color: var(--primary-color);
  padding: 15px;
}

.container h2 {
  border-bottom: 2px solid var(--primary-bg-color);
}

.container .note {
  border: 1px solid var(--primary-bg-color);
  padding: 10px;
}

Benefits [S1] The page highlights three main advantages of CSS variables: easier maintenance, improved readability, and simplified color updates across entire pages.

🛠️ 적용 사례 (Applied in summary)

The page's examples are the applied cases: a :root palette referenced by body, .container, .container h2, and .container .note, and a second version showing how changing only the :root values re-themes the entire layout. No external project/commit applications found in the source.

💻 코드 패턴 (Code patterns)

Declare and use a global variable (language: CSS):

:root {
  --primary-bg-color: #1e90ff;
}

body {
  background-color: var(--primary-bg-color);
}

var() with fallback (language: CSS):

.example {
  color: var(--name, value);
}

⚖️ 비교 및 선택 기준 (Comparison & decision criteria)

  • Global (:root) variables — accessible through the entire document; use for site-wide theme tokens such as the primary palette. [S1]
  • Local variables — declared inside a specific selector and usable only within it; use when a value should only apply to one section. [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.89
  • 중복 검사 결과: 신규 생성 (New discovery)

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-06-23: Initial draft synthesized from the W3Schools "CSS Variables var()" page (Astra wiki-curation, P-Reinforce v3.1 format).