Open In App

SVG text-decoration Attribute

The text-decoration attribute defines whether text is written with a strike-through, overline and/or underline. The main difference between CSS text-decoration property and SVG text-decoration attribute is that, SVG uses the ‘fill‘ and ‘stroke‘ values to paint the text decorations. It has effect only on the following elements <altGlyph>, <text>, <textPath>, <tref>, and <tspan>.

Syntax:



text-decoration = "text-decoration-line" | "text-decoration-style" 
                 | "text-decoration-color"

Attribute Values: The text-decoration attribute accepts the values mentioned above and described below

Example 1: Below examples illustrate the use of text-decoration attribute.






<!DOCTYPE html>
<html>
  
<body>
    <h1 style="color: green; font-size: 40px;">
        GeeksforGeeks
    </h1>
  
    <p>
        Example for text-decoration="underline"
    </p>
  
    <svg viewBox="0 0 450 250" 
        xmlns="http://www.w3.org/2000/svg">
          
        <text y="20" text-decoration="underline">
            GeeksforGeeks
        </text>
    </svg>
</body>
  
</html>

Output:

Example 2:




<!DOCTYPE html>
<html>
  
<body>
    <h1 style="color: green; font-size: 40px;">
        GeeksforGeeks
    </h1>
  
    <p>
        Example for text-decoration="line-through"
    </p>
  
    <svg viewBox="0 0 450 250" 
        xmlns="http://www.w3.org/2000/svg">
          
        <text x="0" y="40" 
            text-decoration="line-through">
            GeeksforGeeks
        </text>
    </svg>
</body>
  
</html>

Output:


Article Tags :