You are here: Reference > JavaScript > client-side > style handling > properties > textDecoration

textDecoration style property

Browser support:
Specifies or returns the appearance characteristics of text, whether it is underlined, overlined, lined-through or blinking text.
You can specify a space separated list of decoration types, if you want to use more than one for an element.
To manipulate the text-decoration types separately, use the textDecorationBlink, textDecorationLineThrough, textDecorationNone, textDecorationOverline or the textDecorationUnderline properties.

Syntax:

object.textDecoration;
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: text-decoration

Possible values:

The type of this property is string.
 One of the following values: 
 Any of the following values (use the space character to separate them, each value can be used only once): 
underline
overline
line-through
blink
none
-moz-anchor-decoration
inherit

Description of values:

-moz-anchor-decoration
Use default anchor decoration.
blink
The text content of the element blinks.
inherit
Takes the value of this property from the computed style of the parent element.
line-through
The text content of the element is displayed with a line through the middle.
none
No text decoration is used.
overline
The text content of the element is displayed with a line at the top.
underline
The text content of the element is underlined.
Default: none.

Example HTML code 1:

This example illustrates the use of the text-decoration property:
<head>
    <style>
        .example {
            text-decoration: overline line-through;
        }
    </style>
</head>
<body>
    <a class="example">Text decoration: overline line-through</p>
</body>
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the textDecoration property in JavaScript:
<head>
    <script type="text/javascript">
        function ChangeTextDecoration (elem) {
            var anchor = document.getElementById ("myAnchor");
            var checkboxes = document.getElementsByName ("checkboxs");
            var decorValue = "";

            // Checks all checkbox state
            for (var i = 0; i < checkboxes.length; i++) {
               if (checkboxes[i].checked) {
                   decorValue += checkboxes[i].value + " ";
                }
            }

            // If none is checked all other checked out
            var noneCh = document.getElementsByName("nonecheck");
            if (noneCh[0].checked) {
                for (var i = 0; i < checkboxes.length; i++) {
                    checkboxes[i].checked = false;
                }
                decorValue = "none";
            }
            anchor.style.textDecoration = decorValue;
        }
    </script>
</head>
<body>
    <a id="myAnchor">Text decoration sample</a>

    <br /><br />
    Change text-decoration value:
    <br />
    <input type="checkbox" name="checkboxs" value="blink" onclick="ChangeTextDecoration ();"/>blink<br />
    <input type="checkbox" name="checkboxs" value="line-through" onclick="ChangeTextDecoration ();"/>line-through<br />
    <input type="checkbox" name="checkboxs" value="overline" onclick="ChangeTextDecoration ();"/>overline<br />
    <input type="checkbox" name="checkboxs" value="underline" onclick="ChangeTextDecoration ();"/>underline<br />

    <input type="checkbox" name="nonecheck" onclick="ChangeTextDecoration ();" />none
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content