You are here: Reference > JavaScript > client-side > HTML DOM > properties > fgColor (document)

fgColor property (document)

Browser support:
Sets or retrieves the text color for the document.
It is no longer recommended to use. You can set the text color with CSS styling. Example 2 shows how to get or manipulate the text color from JavaScript.

Syntax:

object.fgColor;
You can find the related objects in the Supported by objects section below.
This property is read/write.

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: #0000FF.

Example HTML code 1:

This example illustrates the use of the fgColor property:
<head>
    <script type="text/javascript">
        document.fgColor = "blue";
    </script>
</head>
<body>
    The color of the text is blue.
</body>
Did you find this example helpful? yes no

Example HTML code 2:

Recommendation (color):
<head>
    <style>
        BODY {
            color:#00FFFF;
        }
    </style>
    <script type="text/javascript">
        function ChangeTextColor () {
            document.body.style.color = "#00FF00";
        }
    </script>
</head>
<body>
    <button onclick="ChangeTextColor();">Change text 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