CSS Property: color
[this page | pdf | back links]
The CSS (CSS1) color property indicates the colour of
text within an element. Usually you should choose a combination of background
colour and text colour that makes the text easy to read.
Valid property values
(other than inherit
and initial) are:
Default Value:
|
N/A
|
JavaScript syntax:
|
e.g. object.style.color="red"
|
Inherited:
|
Yes
|
Animatable:
|
Yes
|
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
p {border: thin solid black; width: 200px}
p.x1 {color: red;}
</style>
</head>
<body>
<p>1. Element with default property</p>
<p class="x1">2. Element set using in-file HTML style</p>
<p id="x2">3. Element set using JavaScript</p>
<script>
document.getElementById("x2").style.color = "red";
</script>
</body>
</html>
|
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyColor() {
var x = document.createElement("DIV"); x.style.color = "red"; return (window.getComputedStyle(x, null).color == "red");
} |
NAVIGATION LINKS
Contents | Prev | Next | CSS Properties