Click here to Skip to main content
15,312,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone. I'm trying to get "Hello World" to be blue by using a CSS variable but it isn't working and I don't know why. Any assistance would be appreciated. Thanks for your help.

What I have tried:

<style> 
--textcolor: blue; 
</style>

<body>

<h2 style="color:var(--textcolor)">
Hello World
</h2>

</body>
Posted
Updated 15-Aug-21 5:53am

1 solution

Try this:
HTML
<style>
:root{
--textcolor: blue; 
}
</style>

<body>

<h2 style="color:var(--textcolor)">
Hello World
</h2>

</body>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900