Hackforge Academy

Category: html_css

how to define css variable in json format

Published on 08 Jun 2026

Explanation

CSS variables can be overridden inside specific elements to create component-level styling.

Code:

:root {
  --text-color: black;
}

.card {
  --text-color: darkblue;
  color: var(--text-color);
}

Explanation

Provide a fallback value if the variable is not defined.

Code:

.title {
  color: var(--heading-color, green);
}

Explanation

CSS variables are useful for themes such as light and dark mode.

Code:

:root {
  --bg-color: white;
}

.dark-theme {
  --bg-color: #222;
}

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

๐Ÿš€ Learn Spring Boot with real-world projects

๐Ÿ’ก Build REST APIs step by step

๐Ÿง  Improve backend development skills

๐ŸŽฏ Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

๐Ÿ

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
โš›๏ธ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
โ˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community