What are CSS Custom Properties (CSS Variables)?

Instruction: Explain what CSS Custom Properties are and how they can be used.

Context: This question assesses the candidate's knowledge of CSS Variables, their syntax, and their practical applications in making CSS more maintainable and flexible.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

A custom property stores a CSS token value under a case-sensitive name beginning with --. Ordinary unregistered custom properties participate in the cascade and inherit. var() substitutes the chosen value into a property declaration.

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS example</title> <style> :root { --ink: navy; --space: 12px; } .panel { color: var(--ink); padding: var(--space, 8px); } .alternate { --ink:...

Related Questions