QP School
CSS Custom properties (Variables) - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: CSS3 Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=5)
+--- Thread: CSS Custom properties (Variables) (/showthread.php?tid=5170)



CSS Custom properties (Variables) - Qomplainerz - 07-26-2023

Example:

<!DOCTYPE html>
<html>
<head>
  <title>Custom Properties Example</title>
  <style>
    /* Define a custom property */
    :root {
      --primary-color: blue;
    }
    /* Use the custom property to apply styles */
    p {
      color: var(--primary-color);
    }
  </style>
</head>
<body>
  <p>This is a paragraph with a custom primary color.</p>
</body>
</html>

Explanation:

CSS Custom Properties, also known as CSS Variables, allow you to define reusable values. In this example, we define a custom property --primary-color with the value blue. The p element then uses this custom property to set its text color, resulting in blue text.