Free Web Development Online Tutorials, Learn to Code
Learn CSS StyleSheet, Free CSS Tutorial for Beginners, Responsive CSS Examples

Use Color using CSS Code Example

We can write CSS Color Codes in three ways.


You need to play with color in webpage very often; Using CSS there are different ways to specify color for any HTML element.

  • Color using Hex Code
  • Color using RGB
  • Color using Name

Color using Hex Code Example

<style>
.splDiv
{
    color: #000;
    background-color: #dcdcdc;
}
</style>

Color using RGB Example

<style>
.splDiv
{
    color:rgb(186,32,24);
    background-color: rgb(255,255,255);
}
</style>

Color Name Example

Color names are NOT case-sensitive (it doesn't matter whether you use lowercase or UPPERCASE)

<style>
.splDiv
{
    color: white;
    background-color: red;
}
</style>

You can define color to any html element, here are some examples

<div class="splDiv"></div>
<span class="splDiv"></span>
<p class="splDiv"></p>
Comment
Name
Email
Website
Subscribe
CSS Style Examples