How to Add Gradient Text Effect in C#
To add gradient text effects in C#, use IronWord's TextStyle class with the GradientEffect property, which allows you to apply smooth color transitions across text characters using either built-in gradients or custom gradient stops.
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). In document processing applications, gradient text effects are commonly used for headers, titles, promotional materials, and any content where visual emphasis is desired.
Quickstart: Add a Gradient Effect to Text with IronWord
Here’s a simple example showing how to use IronWord to apply a built-in gradient effect to text. Before running this code, ensure you have configured your license keys for IronWord.
-
Install IronWord with NuGet Package Manager
PM > Install-Package IronWord -
Copy and run this code snippet.
using IronWord; using IronWord.Models; WordDocument doc = new WordDocument(); TextStyle textStyle = new TextStyle(); textStyle.TextEffect = new TextEffect() { GradientEffect = Gradient.DefaultGray }; Paragraph paragraph = new Paragraph(); Run textRun = new Run(new TextContent("Gradient Text")); textRun.Style = textStyle; paragraph.AddChild(textRun); doc.AddParagraph(paragraph); doc.SaveAs("out.docx"); -
Deploy to test on your live environment
Start using IronWord in your project today with a free trial
How to Add Gradient Effect to Text (5 steps)
- Install IronWord:
Install-Package IronWord - Create a
TextStyleand configureGradientEffectusing presets likeGradient.DefaultGray - Create a
RuncontainingTextContentand assign theTextStyleto theRun - Add the
Runto aParagraphusingAddChild - Save the document
How Do I Add a Gradient Effect?
What Steps Are Required to Create Gradient Text?
To apply a gradient effect, follow IronWord's multi-step pattern: Create a TextStyle and populate its TextEffect property with a GradientEffect. Then create a Paragraph, followed by a Run containing TextContent. Assign the TextStyle to the Run (not the TextContent), then use AddChild to add the Run to the Paragraph. This follows the document hierarchy: Document → Paragraph → Run → TextContent.
: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,
};
// Create paragraph
Paragraph paragraph = new Paragraph();
// Create run with text and style
Run textRun = new Run(new TextContent("Hello World"));
textRun.Style = textStyle;
// Add run to paragraph
paragraph.AddChild(textRun);
// Add paragraph to document
doc.AddParagraph(paragraph);
// Export new Word document
doc.SaveAs("gradientEffect.docx");
Imports IronWord
Imports IronWord.Models
' Create new Word document
Dim doc As New WordDocument()
' Create and configure text style
Dim textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
.GradientEffect = Gradient.DefaultGray
}
' Create paragraph
Dim paragraph As New Paragraph()
' Create run with text and style
Dim textRun As New Run(New TextContent("Hello World"))
textRun.Style = textStyle
' Add run to paragraph
paragraph.AddChild(textRun)
' Add paragraph to document
doc.AddParagraph(paragraph)
' Export new Word document
doc.SaveAs("gradientEffect.docx")
What Built-in Gradient Options Are Available?
IronWord provides several default gradient presets accessible through static properties of the Gradient class, including DefaultGray and other color combinations that can be applied instantly without custom configuration. These presets offer quick styling options similar to those found in Microsoft Word’s text formatting dialog. The built-in gradients work with standard document templates and maintain readability across different document formats.
When working with gradient effects in production environments, consider reviewing the licensing options to ensure your application has the appropriate coverage for your deployment scenarios.
What Properties Can I Customize for Gradient Effects?
How Do Gradient Stops Work?
The gradient effect provides adjustable attributes for various design needs. See the following list for detailed descriptions of each property:
GradientStop
- Color: Gets or sets the scheme color of the gradient stop. Colors can be specified using IronWord’s predefined color constants or custom RGB values.
- StopPoint: Gets or sets the position of the gradient stop. Values typically range from 0 to 100, representing percentage positions along the gradient path.
Gradient stops are points within a gradient where a specific color is defined. Multiple stops create smooth transitions between colors, and the spacing between stops determines how gradual or abrupt the color changes appear.
Gradient
- StopPoints: Gets or sets the list of gradient stops defining the gradient fill. A minimum of two stops is required for a basic gradient.
- LinearShadeScaled: Gets or sets a value indicating whether the linear shade is scaled. When true, the gradient adjusts to fit the text boundaries.
- LinearShadeAngle: Gets or sets the angle of the linear shade. This property controls the direction of the gradient flow across the text.
For teams planning to expand their document processing capabilities, the upgrade options provide flexible paths to scale your implementation across multiple projects and developers.
How Can I Create Custom Gradient Effects?
Creating custom gradient effects allows for unique text styling that matches your brand or design requirements. The following example demonstrates how to build a two-color gradient with specific angle and scaling properties. For the latest features and improvements related to gradient effects, check the product changelog.
: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,
}
};
// Create paragraph
Paragraph paragraph = new Paragraph();
// Create run with text and style
Run textRun = new Run(new TextContent("Hello World"));
textRun.Style = textStyle;
// Add run to paragraph
paragraph.AddChild(textRun);
// Add paragraph to document
doc.AddParagraph(paragraph);
// Export new Word document
doc.SaveAs("customizedGradientEffect.docx");
Imports IronWord
Imports IronWord.Models
Imports System.Collections.Generic
' Create new Word document
Dim doc As New WordDocument()
' Create gradient stops
Dim firstGradientStop As New GradientStop() With {
.Color = IronWord.Models.Color.Aqua,
.StopPoint = 1
}
Dim secondGradientStop As New GradientStop() With {
.Color = IronWord.Models.Color.OrangeRed,
.StopPoint = 10
}
' Create and configure text style
Dim 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
}
}
' Create paragraph
Dim paragraph As New Paragraph()
' Create run with text and style
Dim textRun As New Run(New TextContent("Hello World"))
textRun.Style = textStyle
' Add run to paragraph
paragraph.AddChild(textRun)
' Add paragraph to document
doc.AddParagraph(paragraph)
' Export new Word document
doc.SaveAs("customizedGradientEffect.docx")
What Angle Values Produce Different Effects?
LinearShadeAngle accepts values from 0 to 360 degrees, where 0° creates a horizontal gradient from left to right, 90° creates a vertical gradient from top to bottom, and 45° creates a diagonal gradient effect as shown in the example above. Common angle configurations include:
- 0° (Horizontal Left-to-Right): Creates a side-to-side gradient, ideal for modern headings
- 90° (Vertical Top-to-Bottom): Produces a top-down fade effect
- 45° (Diagonal): Generates a corner-to-corner transition
- 180° (Horizontal Right-to-Left): Reverses the standard horizontal gradient direction
- 270° (Vertical Bottom-to-Top): Creates an upward gradient effect
When implementing gradient effects across multiple documents or templates, consider licensing extensions to ensure continuous access to updates and support.
Best Practices for Gradient Text Effects
When applying gradient effects to text in professional documents, consider these guidelines:
- Readability First: Ensure sufficient contrast between gradient colors and the document background
- Color Harmony: Choose colors that complement your document’s overall design scheme
- Subtlety in Business Documents: For formal documents, use muted gradients rather than bold color transitions
- Performance Considerations: Complex gradients with many stops may impact document rendering speed
- Cross-Platform Compatibility: Test gradient appearance across different Word viewers and PDF exports
Gradient effects work particularly well for document elements like chapter titles, section headers, and callout text where visual emphasis enhances the reader’s navigation experience.
Frequently Asked Questions
How do I add a gradient text effect in C#?
To add gradient text effects in C#, use IronWord's TextStyle class with the GradientEffect property. Create a TextStyle object, populate its GradientEffect property with a Gradient object, and assign this style to your text. IronWord allows you to apply smooth color transitions across text characters using either built-in gradients or custom gradient stops.
What built-in gradient options are available?
IronWord provides several default gradient presets accessible through static properties of the Gradient class, including DefaultGray and other color combinations. These presets can be applied instantly without custom configuration, offering quick styling options similar to those found in Microsoft Word's text formatting dialog.
Can I create custom gradient effects beyond the built-in options?
Yes, IronWord allows you to create custom gradient effects with custom gradient stops. While the built-in gradients like DefaultGray provide quick solutions, you can configure the GradientEffect properties to create your own color transitions and customize the text outline appearance.
What types of gradient effects can be applied to text?
IronWord supports gradient effects that create smooth transitions of colors across text characters. These can include linear gradients (colors transition in a straight line) or radial gradients (colors transition from a central point outward), adding depth and visual interest to headers, titles, and promotional materials.
How do I apply a gradient effect to existing text?
With IronWord, you can apply gradient effects to both newly created and existing text. Simply create a TextStyle object with the desired GradientEffect property and assign it to your text's Style property. The gradient will be applied when you save the document.

