You are here: Reference > JavaScript > client-side > HTML DOM > properties > color (basefont, font, hr)

color property (basefont, font, hr)

Browser support:
Sets or retrieves the color of the text or line.
This property is deprecated. Use the color style property instead.

Syntax:

object.color;
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: color

Possible values:

A legal color value. It can be a hexadecimal, RGB or predefined color value. For more information, see the page for colors.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the color attribute:
<font color="#FF0000">red text</font>
Did you find this example helpful? yes no

Example HTML code 2:

Recommendation:
<span style="color:#FF0000">red text</span>
Did you find this example helpful? yes no

Example HTML code 3:

This example illustrates the use of the color property:
<head>
    <script type="text/javascript">
        function ChangeColor () {
            var font = document.getElementById ("myFont");

            if ('color' in font) {
                font.color = (font.color.toLowerCase() == "#ff0000")? "#00FF00" : "#FF0000";
            } else {
                alert ("Your browser doesn't support this example!");
            }
        }
    </script>
</head>
<body>
    <font id="myFont" color="#FF0000">red text</font>
    <br />
    <button onclick="ChangeColor ();">Change color!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content