Bird
Raised Fist0
CSSmarkup~20 mins

Theme implementation basics in CSS - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Theme Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the purpose of CSS custom properties in theme implementation?
CSS custom properties (variables) are often used in themes. What is their main benefit when creating a theme?
AThey allow changing colors and styles dynamically without rewriting all CSS rules.
BThey automatically generate new CSS classes for each theme color.
CThey replace the need for media queries in responsive design.
DThey prevent any CSS from being overridden by other styles.
Attempts:
2 left
💡 Hint
Think about how you can change a color in many places by changing just one value.
📝 Syntax
intermediate
2:00remaining
Which CSS snippet correctly defines a dark theme color variable?
You want to define a dark theme background color using a CSS custom property named --bg-color. Which snippet is correct?
A:root { --bg-color: #121212; }
Broot { bg-color: #121212; }
C:root { --bg-color #121212; }
D:root { bg-color: #121212; }
Attempts:
2 left
💡 Hint
Remember custom properties start with two dashes and are inside a selector.
rendering
advanced
2:00remaining
What color will the background be when this CSS is applied?
Given the CSS below, what will be the background color of the element?
CSS
:root {
  --bg-color: white;
}

[data-theme="dark"] {
  --bg-color: black;
}

body {
  background-color: var(--bg-color);
}
ABlack always, because --bg-color is set to black in the dark theme.
BWhite if no data-theme attribute is set on <html> or <body>.
CTransparent, because var(--bg-color) is not defined.
DRed, because the default color is overridden by the browser.
Attempts:
2 left
💡 Hint
Think about which CSS rule applies when the data-theme attribute is missing.
selector
advanced
2:00remaining
Which CSS selector applies styles only when dark theme is active?
You want to style all paragraphs with a light text color only when the dark theme is active using the data-theme attribute on . Which selector is correct?
Ahtml p[data-theme="dark"] { color: #eee; }
Bp[data-theme="dark"] { color: #eee; }
Chtml[data-theme="dark"] p { color: #eee; }
Dp.dark-theme { color: #eee; }
Attempts:
2 left
💡 Hint
The data-theme attribute is on the element, not on paragraphs.
accessibility
expert
2:00remaining
How to ensure theme colors meet accessibility contrast standards?
When implementing a dark theme, what is the best way to ensure text colors meet accessibility contrast requirements?
AUse any dark background with light text without testing contrast.
BOnly rely on browser default colors for dark themes.
CUse the same colors as the light theme but invert them.
DUse a contrast checker tool to pick colors with sufficient contrast ratio.
Attempts:
2 left
💡 Hint
Accessibility means text must be easy to read against backgrounds.

Practice

(1/5)
1. What is the main purpose of using CSS variables in theme implementation?
easy
A. To write JavaScript code inside CSS
B. To store colors and fonts for easy theme switching
C. To create animations automatically
D. To hide elements on the page

Solution

  1. Step 1: Understand CSS variables role

    CSS variables hold values like colors and fonts that can be reused.
  2. Step 2: Connect variables to theme switching

    Changing these variables changes the look without rewriting CSS rules.
  3. Final Answer:

    To store colors and fonts for easy theme switching -> Option B
  4. Quick Check:

    CSS variables = theme colors/fonts [OK]
Hint: CSS variables hold theme colors and fonts [OK]
Common Mistakes:
  • Thinking CSS variables run JavaScript
  • Confusing variables with animations
  • Believing variables hide elements
2. Which CSS selector is commonly used to define global CSS variables for themes?
easy
A. :root
B. .theme
C. #variables
D. body

Solution

  1. Step 1: Identify global scope selector

    The :root selector targets the top-level element for global variables.
  2. Step 2: Confirm other options

    Classes or IDs are not global by default; body is less specific than :root.
  3. Final Answer:

    :root -> Option A
  4. Quick Check:

    Global CSS variables use :root [OK]
Hint: Use :root to define global CSS variables [OK]
Common Mistakes:
  • Using class selectors for global variables
  • Using body instead of :root
  • Confusing ID selectors with variable scope
3. Given this CSS, what color will the text inside <div class='dark'> be?
:root { --text-color: black; } .dark { --text-color: white; } p { color: var(--text-color); }

<div class='dark'><p>Hello</p></div>

medium
A. Black
B. No color applied
C. Gray
D. White

Solution

  1. Step 1: Check variable default value

    In :root, --text-color is black by default.
  2. Step 2: Check override in .dark class

    The .dark class changes --text-color to white.
  3. Step 3: Apply variable in paragraph

    The p inside .dark uses white color from overridden variable.
  4. Final Answer:

    White -> Option D
  5. Quick Check:

    Class override changes variable color [OK]
Hint: Class variables override :root variables inside that class [OK]
Common Mistakes:
  • Ignoring class variable override
  • Thinking default :root value always applies
  • Confusing variable usage syntax
4. What is wrong with this CSS if the theme colors do not change?
:root { --bg-color: white; } .dark-theme { --bg-color: black; } body { background-color: var(bg-color); }
medium
A. Missing dashes in variable usage: should be var(--bg-color)
B. Wrong selector for .dark-theme class
C. Variables cannot be used in background-color
D. The :root selector is incorrect

Solution

  1. Step 1: Check variable usage syntax

    CSS variables must be used with var(--variable-name), missing dashes cause errors.
  2. Step 2: Confirm other parts are correct

    The selectors and variable definitions are correct; only usage syntax is wrong.
  3. Final Answer:

    Missing dashes in variable usage: should be var(--bg-color) -> Option A
  4. Quick Check:

    Use var(--variable) syntax correctly [OK]
Hint: Always use var(--variable-name) with double dashes [OK]
Common Mistakes:
  • Writing var(bg-color) instead of var(--bg-color)
  • Changing selectors unnecessarily
  • Thinking variables can't be used in background-color
5. How can you implement a light/dark theme toggle using only CSS classes and variables?

Choose the best approach:

hard
A. Create separate CSS files for each theme and reload the page
B. Use JavaScript to rewrite all CSS rules on toggle
C. Define variables in :root and override them in .dark class, then toggle .dark on body
D. Use inline styles on every element to change colors

Solution

  1. Step 1: Understand CSS variable override

    Defining variables in :root sets defaults; overriding in a class like .dark changes theme colors.
  2. Step 2: Toggle class on body element

    Adding or removing .dark on body switches themes without reloading or inline styles.
  3. Step 3: Evaluate other options

    JavaScript rewriting CSS or reloading files is less efficient; inline styles are hard to maintain.
  4. Final Answer:

    Define variables in :root and override them in .dark class, then toggle .dark on body -> Option C
  5. Quick Check:

    Toggle class with CSS variables for themes [OK]
Hint: Toggle a class on body to switch CSS variable themes [OK]
Common Mistakes:
  • Reloading CSS files instead of toggling classes
  • Using inline styles for theme colors
  • Trying to rewrite CSS rules with JavaScript