CSS Variables

by Alessio Michelini

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h1>
  Hello
  </h1>
  <p class="content">
  World!
  </p>
</body>
</html>

CSS

:root {
  --bg-color: white;
  --font-color: blue;
  --heading-color: #AAA;
}

body {
  background-color: var(--bg-color);
  color: var(--font-color);
}

h1 {
  color: var(--heading-color);
}

p {
  color: var(--paragraph-color, red); /* Red if --paragraph-color is not defined */
}