CSS color property: 2 Demos of Text Color Animation and Links

CSS color property

The color property is used to define the color of the text in CSS. You may set colors for different sections or elements separately. For example, you may set different colors for paragraph text, text in div elements, anchor text, etc.

You may set the color by using color names like green, blue, red, etc. You may also use the HEX code of the color or RGB values. For example:

Setting by color name:

color: green;

Setting by HEX code:

color: #804040

Setting by RGB value:

color: rgb(64, 128, 128)

See the following demos where the color CSS property is used in text animation and links.

A demo of text color animation

In this demo, the CSS color property is used multiple times as per duration. The div text will show in different colors. The color property is set in the keyframes:

CSS color

The CSS:

.colani {

  font-size:45px; 

  font-family: Helvetica, sans-serif;

  font-weight: 500;

  -webkit-animation: color-animation 15s infinite alternate linear;

  -moz-animation: color-animation 15s infinite alternate linear;

  -o-animation: color-animation 15s infinite alternate linear;

}

 

@-webkit-keyframes color-animation {

    0%   { color: #FF0000; }

    20%  { color: #FF8040; }

    40%  { color: #FFFF00; }

    60%  { color: #008000; }

    80%  { color: #0000FF; }

    100% { color: #8080FF; }

}

 

@-moz-keyframes color-animation {

    0%   { color: #FF0000; }

    20%  { color: #FF8040; }

    40%  { color: #FFFF00; }

    60%  { color: #008000; }

    80%  { color: #0000FF; }

    100% { color: #8080FF; }

}

 

@-o-keyframes color-animation {

    0%   { color: #FF0000; }

    20%  { color: #FF8040; }

    40%  { color: #FFFF00; }

    60%  { color: #008000; }

    80%  { color: #0000FF; }

    100% { color: #8080FF; }

}

The simple markup:

<div class="colani">Color animation demo</div>

An example of using color with a link

In this demo, the HTML links are given a color by using the color property of CSS. The colors for the normal state are different than the hover state. Also, visited links can be shown differently as compared to the unvisited links, as shown in the image below:

CSS color link

The CSS used for the menu where the color property is used:

.color-demo{

    border-radius:5px;

}

.color-demo ul {

    width:185px;

    list-style-type: none;

}

.color-demo ul li a{

    text-decoration: none;

    color: #FFFF37;

    padding: 10.5px 11px;

    background-color: #274E4E;

    display:block;

    border-bottom:solid 1px #000;

}

.color-demo ul li a:visited {

    color: #FFFF37;

}

 

.color-demo ul li a:hover, .color-demo ul li .current {

    color: #800000;

    background-color: #FBE9AC;

}

The markup for the menu containing links:

<h3>The color property demo in links</h3>

<div class="color-demo" id="mainmenu">

<ul>

<li><a href="https://www.jquery-az.com/jquery-tips/">jQuery Tutorials</a></li>

<li><a href="https://www.jquery-az.com/html-tutorials/">HTML Tutorials</a></li>

<li><a href="https://www.jquery-az.com/css-tutorials/">CSS Tutorials</a></li>

<li><a href="https://www.jquery-az.com/bootstrap-tips-tutorials/">Bootstrap Tutorials</a></li>

<li><a href="https://www.jquery-az.com/javascript-tutorials/">JavaScript Tutorials</a></li>

</ul>

</div>

You can see, the CSS class .color-demo ul li a specifies the color of links while underneath that is the color-demo ul li a:visited class that specifies the color for the visited links.

Yet below it are the color-demo ul li a:hover and color-demo ul li .current classes that set the color in the hover state along with the current link.