0

Is there a way to display my CSS-Variable's Content to my HTML webpage? My Variable's name is --pick-container-width and its Content is 5vh. Now I want (for testing Reasons) to display the Content to an <h1> but idk how...

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
DNAScanner
  • 74
  • 7
  • 1
    You would have to use JavaScript to do that. See [Accessing a CSS custom property (aka CSS variable) through JavaScript](https://stackoverflow.com/q/36088655/215552) To get that into HTML, see [how to display a javascript var in html body](https://stackoverflow.com/q/40858456/215552) – Heretic Monkey Nov 08 '21 at 17:52
  • 1
    Does this answer your question? [Accessing a CSS custom property (aka CSS variable) through JavaScript](https://stackoverflow.com/questions/36088655/accessing-a-css-custom-property-aka-css-variable-through-javascript) – Heretic Monkey Nov 08 '21 at 17:53

1 Answers1

0

You would use the var() function. Below is an example.

:root {
  --color: crimson;
}

.title {
  color: var(--color);
}
<h1 class="title">I am a title tag!</h1>
JayDev95
  • 777
  • 2
  • 5
  • 18