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 new Word document
WordDocument doc = new WordDocument();

// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
    GradientEffect = Gradient.DefaultGray,
};

// Add text with style
doc.AddText("Hello World").Style = textStyle;

// Export new Word document
doc.SaveAs("gradientEffect.docx");
Imports IronWord
Imports IronWord.Models

' Create new Word document
Private doc As New WordDocument()

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

' Add text with style
doc.AddText("Hello World").Style = textStyle

' Export new Word document
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;

// Create new Word document
WordDocument doc = new WordDocument();

// Create gradient stops
GradientStop firstGradientStop = new GradientStop()
{
    Color = IronWord.Models.Color.Aqua,
    StopPoint = 1
};
GradientStop secondGradientStop = new GradientStop()
{
    Color = IronWord.Models.Color.OrangeRed,
    StopPoint = 10
};

// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
    GradientEffect = new Gradient()
    {
        StopPoints = new List<GradientStop> { firstGradientStop, secondGradientStop },
        LinearShadeAngle = 45,
        LinearShadeScaled = true,
    }
};

// Add text with style
doc.AddText("Hello World").Style = textStyle;

// Export new Word document
doc.SaveAs("customizedGradientEffect.docx");
Imports IronWord
Imports IronWord.Models
Imports System.Collections.Generic

' Create new Word document
Private doc As New WordDocument()

' Create gradient stops
Private firstGradientStop As New GradientStop() With {
	.Color = IronWord.Models.Color.Aqua,
	.StopPoint = 1
}
Private secondGradientStop As New GradientStop() With {
	.Color = IronWord.Models.Color.OrangeRed,
	.StopPoint = 10
}

' Create and configure text style
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 with style
doc.AddText("Hello World").Style = textStyle

' Export new Word document
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. Use IronWord to implement these effects in your Word documents.

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. IronWord allows for the application of both types in Word documents.

How do you start adding gradient effects to text?

To start adding gradient effects, use IronWord to 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?

Using IronWord, 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 in IronWord?

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?

In IronWord, 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 in IronWord.

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.
Talk to an Expert Five Star Trust Score Rating

Ready to Get Started?

Nuget Passed