How to set font color using css?

Hi there

I want to change font color of a particular element using CSS style how can I do this?

I know I can do this like

  <p><font color="red">This is some text!</font></p>
  <p><font color="blue">This is some text!</font></p>

but i want a global css that will change color of an element whenever it is in document?

Thanks

CSS

.classname {color: red;}
.anothername {color: blue;}

HTML

<p class="classname">This text will be red.</p>
<p class="anothername">This text will be blue.</p>

(Obviously, you choose class names whoich are meaningful in the context of your site. )

2 Likes

Done

You can set the default for any element, such as ā€œpā€ then use a class only where wanted.
CSS

p { color: red; }
.blue { color: blue; }

HTML

<p>A paragraph in red by default.</p>
<p class="blue">A paragraph that is blue.</p>

Thanks @SamA74

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.