Export (0) Print
Expand All
14 out of 18 rated this helpful - Rate this topic

text-decoration property

Specifies a value that indicates whether the text in the object has blink, line-through, overline, or underline decorations.

Internet Explorer 9

Syntax

text-decoration: none | underline | overline | line-through | blink

Property values

A variable of type String that specifies or receives one of the following values.

none

Default. Text has no decoration.

underline

Text is underlined.

overline

Text has a line over it.

line-through

Text has a line drawn through it.

blink

Not implemented.

CSS information

Applies ToAll elements
Mediavisual
Inheritedno
Initial Valuenone

Remarks

The default value is different for the following tags.

  • Default value is underline for a when used with href, u, and ins.
  • Default value is line-through for strike, s, and del.

If the value none is placed at the end of the values, all values are cleared. For example, setting {text-decoration: underline overline blink none} causes none of the decorations to render.

If the object has no text (for example, the img object in HTML) or is an empty object (for example, "<em></em>"), this property has no effect.

If you set the text-decoration attribute to none on the body object, the a objects are still underlined. To remove the underline from the a objects, either set the style inline or use a as a selector in the global style sheet.

Specifying the text-decoration property for block elements affects all inline children. If it is specified for, or affects, an inline element, it affects all boxes generated by the element.

The overline and blink possible values are available as of Microsoft Internet Explorer 4.0. Although blink is exposed, it is not rendered.

In Windows Internet Explorer 8 and later, when the text-decoration property is set to overline and/or underline, the line will remain at the same vertical level and the same thickness across all child elements of the parent element on which the text decoration has been set. (This does not apply to the line-through value.) In Windows Internet Explorer 7 and earlier, the text decoration adjusts to correspond to the size and thickness of each child element.

Examples

The following examples use the text-decoration attribute and the text-decoration property to decorate text within the object.

This example uses an inline style sheet to draw a line through the text within the object.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/text-decoration.htm


<div style="text-decoration: line-through">
...
</div>

This example uses inline scripting to underline the text within the span object when the user moves the mouse over the span.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/textDecoration.htm


<span style="font-size: 14px" onmouseover="this.style.textDecoration='underline'" 
    onclick="this.style.textDecoration='overline'" 
    ondblclick="this.style.textDecoration='line-through'">
...
</span>

This example demonstrates that, though text-decoration is not inheritable, its child elements are formatted with the same decoration (for instance, an underline) as their parent. Even if descendant elements have different color values, the color of the decoration will remain the same as that of the parent element.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/textDecoration_2.htm



<!DOCTYPE html>
<html>
<head>
  <style type="text/css">
    .redunderline {
      color: red;
      text-decoration: underline;
    }
    .blueoverline {
      color: blue;
      text-decoration: overline;
    }
  </style>
</head>
<body>
  <div class="redunderline">
    This <strong>div</strong> has text decoration set to underline,
    <span class="blueoverline">but this<strong>span</strong> has it set to overline.</span>
    The<strong>div</strong> continues here.
  </div>
</body>
</html>

See also

CSSStyleDeclaration
currentStyle
defaults
runtimeStyle
style
Reference
textDecorationLineThrough
textDecorationNone
textDecorationOverline
textDecorationUnderline

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.