Rendered from variables/allowed.md

CSS Variables — Allowed

This gauge covers Chapter 16 after the combined practical projects.

Learning goal

Define reusable colour values with CSS custom properties, use them through var(), and override them deliberately without losing readable contrast — including following the system light/dark preference.

Inherited tools

Everything allowed through ./phase10-allowed.html remains available.

New CSS

Learning rules

  1. Use meaningful names such as --color-surface and --color-text that describe a role rather than one specific colour.
  2. Put values in :root when the whole document should be able to use them.
  3. Read a custom property with var(). Declaring a custom property alone does not apply it to any visual CSS property.
  4. Custom properties participate in the cascade and normally inherit. A value declared on a nearer ancestor can override the same name from :root.
  5. Keep related theme overrides together on one container class so descendants receive a coherent palette.
  6. Use a fallback when a missing or invalid custom property would otherwise make a declaration invalid.
  7. A fallback is used only when the referenced custom property is missing or invalid, not merely because its colour has weak contrast.
  8. Re-check text, border, focus, hover, and active contrast after changing a palette. Variables reduce repetition but do not guarantee accessibility.
  9. Avoid creating a variable for every single literal. Extract values that are repeated or represent a clear design role.
  10. Prefer overriding the same role tokens under prefers-color-scheme rather than inventing a parallel set of dark-only property names.

Not allowed

Limited exception — HTML→CSS data channel

Lesson 04-html-data-channel.html may use an inline style attribute only to set custom properties (for example style="--progress: 80%"). Do not use inline styles for ordinary colours or spacing in that lesson either — only the data channel variable(s).

Pages

Rules to lean on

Rules 2, 11–12, 43–45, 49–50, 121, 155–162, and 244.