How to Add Gradient Text Effect in C#
To add gradient text effects in C#, use IronWord's TextStyle class with its TextEffect property's GradientEffect member, which allows you to apply smooth color transitions across text characters using either the built-in gradient 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 IronWordHere'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.
-
1Install IronWord with NuGet Package Manager
-
2Copy 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");C# -
3Deploy 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 the built-in presetGradient.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.
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 a single built-in gradient preset, Gradient.DefaultGray, accessible as a static field of the Gradient class that can be applied instantly without custom configuration. For any other color combination, build a custom gradient using the StopPoints, LinearShadeAngle, and LinearShadeScaled properties, as shown in the custom gradient example below. The built-in preset works with standard document templates and maintains 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 licensing 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.
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 options 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
What is a gradient text effect in C# Word documents?
A gradient text effect in C# Word documents is a feature available in IronWord that allows you to apply smooth color transitions across text characters. It can be linear or radial, adding depth and visual interest to your documents.
How do I create a gradient text effect using IronWord?
To create a gradient text effect using IronWord, you can use the `TextStyle` class and set its `TextEffect` property to a `GradientEffect`. This can be done by applying a built-in gradient or creating custom gradient stops for more personalized styling.
What are the built-in gradient options available in IronWord?
IronWord provides a single built-in gradient preset called `Gradient.DefaultGray`. For additional color combinations, you can create custom gradients using properties like `StopPoints`, `LinearShadeAngle`, and `LinearShadeScaled`.
How can I customize gradient effects for text in IronWord?
You can customize gradient effects in IronWord by creating a `Gradient` object with properties such as `StopPoints` for the gradient stop colors, `LinearShadeAngle` for the direction, and `LinearShadeScaled` for scaling the gradient to fit text boundaries.
What are gradient stops and how do they work?
Gradient stops are points within a gradient where specific colors are defined. They determine the color transitions in a gradient, with spacing between stops affecting how smooth or abrupt the transitions appear.
Can I use custom RGB values for gradient stops in IronWord?
Yes, you can define custom colors for gradient stops using IronWord's predefined color constants or by specifying custom RGB values for more precise color control.
What angle values can produce different effects for linear gradients?
In IronWord, `LinearShadeAngle` values range from 0° to 360°. For example, 0° creates a left-to-right gradient, 90° creates a top-to-bottom gradient, and 45° produces a diagonal gradient effect.
What should I consider for best practices when applying gradient text effects?
When applying gradient text effects, ensure readability with strong contrast, choose complementary colors, use subtle gradients for formal documents, and consider performance impacts and cross-platform compatibility.
Is there a way to create radial gradients in IronWord?
Currently, IronWord primarily supports linear gradients. Radial gradients, which transition colors from a central point outward, require custom manipulation of gradient properties for similar effects.
Do gradient effects in IronWord maintain compatibility across different document formats?
Yes, the built-in gradient presets and custom gradients in IronWord are designed to work with standard document templates, ensuring readability across various Word formats and PDF exports.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.