Skip to content
FrontDepth, Home

Back to the topic

Practice: Design tokens and theming

Answer first, then compare. Rate yourself honestly — it drives your weak-areas list.

4 predict-output · 3 open

Questions up to level

Shows questions up to the selected level.

No practice questions for this level yet.

  1. Predict the outputJunior

    Tokens are set on :root, on a [data-theme="dark"] section and on a card inside it. What does this code log?

    JavaScript
    const style = document.createElement("style");
    style.textContent = `
      :root { --color-bg: white; --color-text: black; }
      [data-theme="dark"] { --color-bg: black; --color-text: white; }
      .card { --color-bg: gray; }
    `;
    document.head.append(style);
    document.body.innerHTML = `
      <main id="page">
        <section id="dark" data-theme="dark">
          <p id="text"></p>
          <div id="card" class="card"></div>
        </section>
      </main>
    `;
    const read = (id, name) =>
      getComputedStyle(document.getElementById(id)).getPropertyValue(name).trim();
    console.log(read("page", "--color-bg"));
    console.log(read("text", "--color-bg"));
    console.log(read("card", "--color-bg"));
    console.log(read("card", "--color-text"));
    console.log(read("page", "--color-border") === "");
  2. Open questionJunior

    What is a design token, and why do teams split tokens into primitive and semantic tiers?

    Think it through first

    Answer out loud or in your head as if you were in an interview, then reveal.

  3. Predict the outputMiddle

    Four paragraphs inside a blue parent use var() in different ways. What does this code log?

    JavaScript
    const style = document.createElement("style");
    style.textContent = `
      #parent { color: rgb(0, 0, 255); }
      #a { color: var(--missing, rgb(255, 0, 0)); }
      #b { --size: 20px; color: var(--size, rgb(255, 0, 0)); }
      #c { color: rgb(0, 128, 0); color: var(--missing); }
      #d { color: rgb(0, 128, 0); color: 20px; }
    `;
    document.head.append(style);
    document.body.innerHTML = `
      <div id="parent">
        <p id="a"></p>
        <p id="b"></p>
        <p id="c"></p>
        <p id="d"></p>
      </div>
    `;
    for (const id of ["a", "b", "c", "d"]) {
      console.log(id + ": " + getComputedStyle(document.getElementById(id)).color);
    }
  4. Open questionMiddle

    How would you implement dark mode with a system default, a user override and no flash of the wrong theme?

    Think it through first

    Answer out loud or in your head as if you were in an interview, then reveal.

  5. Predict the outputSenior

    A semantic token --button-bg aliases --brand-primary. Two brands override the primitive in different ways. What does this code log?

    JavaScript
    const style = document.createElement("style");
    style.textContent = `
      :root {
        --brand-primary: rgb(0, 0, 255);
        --button-bg: var(--brand-primary);
      }
      [data-brand="red"] {
        --brand-primary: rgb(255, 0, 0);
      }
      [data-brand="green"] {
        --brand-primary: rgb(0, 128, 0);
        --button-bg: var(--brand-primary);
      }
      button { background-color: var(--button-bg); }
    `;
    document.head.append(style);
    document.body.innerHTML = `
      <div data-brand="red"><button id="red">Buy</button></div>
      <div data-brand="green"><button id="green">Buy</button></div>
    `;
    const css = (id) => getComputedStyle(document.getElementById(id));
    console.log(css("red").getPropertyValue("--brand-primary").trim());
    console.log(css("red").backgroundColor);
    console.log(css("green").backgroundColor);
  6. Predict the outputSenior

    --accent is registered with @property as a non-inherited <color>; --plain is an ordinary custom property. What does this code log?

    JavaScript
    const style = document.createElement("style");
    style.textContent = `
      @property --accent {
        syntax: "<color>";
        inherits: false;
        initial-value: rgb(0, 0, 0);
      }
      #parent { --accent: rgb(255, 0, 0); --plain: rgb(255, 0, 0); }
      #bad { --accent: 20px; }
    `;
    document.head.append(style);
    document.body.innerHTML = `
      <div id="parent">
        <p id="child"></p>
        <p id="bad"></p>
      </div>
    `;
    const read = (id, name) =>
      getComputedStyle(document.getElementById(id)).getPropertyValue(name).trim();
    console.log(read("parent", "--accent"));
    console.log(read("child", "--accent"));
    console.log(read("child", "--plain"));
    console.log(read("bad", "--accent"));
  7. Open questionSenior

    One component library must serve several store brands, each with its own look, fonts, features and markets (the multi-brand-design-system problem). How do you design theming, and do you theme at runtime or at build time?

    Think it through first

    Answer out loud or in your head as if you were in an interview, then reveal.