DEV Community

VICTOR OMONDI
VICTOR OMONDI

Posted on

3 2

CSS Variables for beginners

CSS Variables for beginners

:root {
    --primary-color: #f03d06;
  }

  .main-header {
    color: var(--primary-color);
  }
  .main-footer {
    background-color: var(--primary-color);
  }
Enter fullscreen mode Exit fullscreen mode

To declare a CSS variable we will have to add a double dash before the name of that variable.

To access a CSS variable try:
var(--your-variable-name)

CSS variables declared in :root will make sure that all selectors can gain access to them

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs