How to Add Gradient Effect to Text

A gradient effect on text involves applying a smooth transition of colors across the characters or background of text, creating a blend from one color to another or multiple colors. This effect adds depth, visual interest, and a dynamic appearance to the text, making it stand out and enhancing its aesthetic appearance. Gradient effects can be linear (colors transition in a straight line) or radial (colors transition from a central point outward).

Get started with IronWord

Start using IronWord in your project today with a free trial.

First Step:
green arrow pointer


Add Gradient Effect

To specify the gradient effect for the text, create the TextStyle object and populate the GradientEffect property with a Gradient object. Finally, add new text with the style by assigning the TextStyle object to the TextEffect property.

:path=/static-assets/word/content-code-examples/how-to/text-effect-gradient-effect.cs
using IronWord;
using IronWord.Models;

// Create an instance of a Word document
WordDocument doc = new WordDocument();

// Create and configure a text style
TextStyle textStyle = new TextStyle
{
    // Configure text effect
    TextEffect = new TextEffect
    {
        // Set the gradient effect for the text
        GradientEffect = GradientEffect.DefaultGray
    }
};

// Add styled text "Hello World" to the document
// AddText returns a WordText object, on which Style is set.
doc.AddText("Hello World").Style = textStyle;

// Save the document with the name "gradientEffect.docx"
doc.SaveAs("gradientEffect.docx");
Imports IronWord
Imports IronWord.Models

' Create an instance of a Word document
Private doc As New WordDocument()

' Create and configure a text style
Private textStyle As New TextStyle With {
	.TextEffect = New TextEffect With {.GradientEffect = GradientEffect.DefaultGray}
}

' Add styled text "Hello World" to the document
' AddText returns a WordText object, on which Style is set.
doc.AddText("Hello World").Style = textStyle

' Save the document with the name "gradientEffect.docx"
doc.SaveAs("gradientEffect.docx")
$vbLabelText   $csharpLabel
Add gradient effect

Gradient Effect Properties

The gradient effect provides a range of adjustable attributes to meet diverse design requirements. See the following list for detailed descriptions of each property:

GradientStop

  • Color: Gets or sets the scheme color of the gradient stop.
  • StopPoint: Gets or sets the position of the gradient stop.

Gradient stops are points within a gradient where a specific color is defined.

Gradient

  • StopPoints: Gets or sets the list of gradient stops defining the gradient fill.
  • LinearShadeScaled: Gets or sets a value indicating whether the linear shade is scaled.
  • LinearShadeAngle: Gets or sets the angle of the linear shade.
:path=/static-assets/word/content-code-examples/how-to/text-effect-customized-gradient-effect.cs
using IronWord;
using IronWord.Models;
using System.Collections.Generic;

// Instantiate a new Word document
WordDocument doc = new WordDocument();

// Create gradient stops for the text
GradientStop firstGradientStop = new GradientStop()
{
    Color = IronWord.Models.Color.Aqua,    // Set the color of the first gradient stop
    StopPoint = 0.0                        // Set start of the gradient (should be between 0 and 1)
};
GradientStop secondGradientStop = new GradientStop()
{
    Color = IronWord.Models.Color.OrangeRed, // Set the color of the second gradient stop
    StopPoint = 1.0                           // Set end of the gradient (should be between 0 and 1)
};

// Create and configure text style with a gradient effect
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
    GradientEffect = new Gradient()
    {
        StopPoints = new List<GradientStop> { firstGradientStop, secondGradientStop }, // Add the gradient stops to the gradient effect
        LinearShadeAngle = 45,  // Angle of the linear gradient
        LinearShadeScaled = true // Scale the gradient
    }
};

// Add text to the document and apply the created style
TextElement textElement = doc.AddText("Hello World");
textElement.Style = textStyle;

// Save the Word document with the customized gradient effect
doc.SaveAs("customizedGradientEffect.docx");
Imports IronWord
Imports IronWord.Models
Imports System.Collections.Generic

' Instantiate a new Word document
Private doc As New WordDocument()

' Create gradient stops for the text
Private firstGradientStop As New GradientStop() With {
	.Color = IronWord.Models.Color.Aqua,
	.StopPoint = 0.0
}
Private secondGradientStop As New GradientStop() With {
	.Color = IronWord.Models.Color.OrangeRed,
	.StopPoint = 1.0
}

' Create and configure text style with a gradient effect
Private textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
	.GradientEffect = New Gradient() With {
		.StopPoints = New List(Of GradientStop) From {firstGradientStop, secondGradientStop},
		.LinearShadeAngle = 45, .LinearShadeScaled = True
	}
}

' Add text to the document and apply the created style
Dim textElement As TextElement = doc.AddText("Hello World")
textElement.Style = textStyle

' Save the Word document with the customized gradient effect
doc.SaveAs("customizedGradientEffect.docx")
$vbLabelText   $csharpLabel
Customized gradient effect

Frequently Asked Questions

What is a gradient effect on text?

A gradient effect on text involves applying a smooth transition of colors across the characters or background of text, creating a blend from one color to another or multiple colors. This effect adds depth, visual interest, and a dynamic appearance to the text.

What are the types of gradient effects?

Gradient effects can be linear, where colors transition in a straight line, or radial, where colors transition from a central point outward.

How do you start adding gradient effects using IronWord?

To start adding gradient effects using IronWord, download a C# library that enables adding gradients to text, and apply the text effect to either newly created or existing text.

How can you apply a preset gradient effect in IronWord?

Use a preset gradient effect by using the static named instance of the Gradient class and configure the GradientEffect properties to customize the text outline.

How do you create a TextStyle object with a gradient effect?

Create a TextStyle object and populate the GradientEffect property with a Gradient object. Then, add new text with the style by assigning the TextStyle object to the TextEffect property.

What are the key properties of the Gradient class?

The key properties of the Gradient class include StopPoints, LinearShadeScaled, and LinearShadeAngle. StopPoints define the gradient stops, LinearShadeScaled indicates whether the linear shade is scaled, and LinearShadeAngle sets the angle of the linear shade.

How do you define gradient stops?

Gradient stops are defined using the GradientStop class, which includes properties such as Color for the scheme color and StopPoint for the position of the gradient stop.

Can you customize the gradient stops?

Yes, you can customize gradient stops by adding GradientStop objects with specific colors and positions to the StopPoints list of a Gradient object.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.