Css variables not working please help!

I am trying to practice using css variables but i cannot.please help.

i declared this variable to red inside css style in order to change the font color to red in

tag but code it not working please check if it is ok! Thanks in advance!

<style>
-- p - color : red ;


p { 
color : var (--p-color) ;
 }

</style>

You’re defining it wrong. It should be like this:

<style>
p { 
    --p-color: red;
    color: var(--p-color);
}

</style>
1 Like

if you want this variable avaipable everywhere, you need to put it in a selector like for example root:

   :root {
       --p-color: red;
   }
1 Like

Thanks . But can i use this on html or this is only applicable with css, inside style tags!

1 Like

You can use css variables in css only. You can’t use them in html.

1 Like

Thanks I was stuck with this for 2 days also tried to make the penguin , tried a lot of things to figure this on my own but couldn’t. I tried to use it in html. I failed .

Then i realized i need more skills to successfully able to make the Penguin with variables .

1 Like