How to Add Style to Text in DOCX with C
IronWord's TextStyle class enables .NET developers to apply professional text formatting to Word documents programmatically, including fonts, colors, bold, italic, underline, and more. Whether you're generating reports, creating templates, or automating document creation, IronWord provides comprehensive styling tools that replicate Microsoft Word's formatting options.
Quickstart: Style Text in DOCX with C#
- Install IronWord via NuGet:
Install-Package IronWord - Create a
WordDocumentobject - Create
TextContentwith your text - Apply
TextStylewith desired properties (font, color, bold, etc.) - Add text to paragraph and save document
Get started making PDFs with NuGet now:
Install IronWord with NuGet Package Manager
Copy and run this code snippet.
// Quick example using IronWord; using IronWord.Models; // Initialize a new Word document WordDocument doc = new WordDocument(); // Create styled text content TextContent text = new TextContent("Styled text"); // Apply styling properties text.Style = new TextStyle() { IsBold = true, Color = Color.Red, TextFont = new Font() { FontFamily = "Arial", FontSize = 16 } }; // Create paragraph and add the styled text Paragraph paragraph = new Paragraph(); paragraph.AddText(text); // Add paragraph to document and save doc.AddParagraph(paragraph); doc.SaveAs("styled.docx");Deploy to test on your live environment
Get started with IronWord
How to Add Style to Text in DOCX
- Download and install the IronWord C# library
- Create a new Word document or load an existing file
- Specify font family using
FontFamily - Apply bold or italic formatting to text
- Save the document with applied styles
How Do I Add Text Style to DOCX?
Applying text styles in IronWord is straightforward. Create a WordDocument object, then create a TextContent object with your text. Apply a TextStyle using properties such as IsBold, Color, or TextFont, and enhance styling with options like underline or strikethrough.
Once styled, add text to a Paragraph, insert the paragraph into the document, and save the result. This approach provides programmatic control over text formatting for automated document generation scenarios requiring consistent styling.
:path=/static-assets/word/content-code-examples/how-to/add-style-text-simple.csusing IronWord;
// Load docx
WordDocument doc = new WordDocument("sample.docx");
// Configure text
TextContent text = new TextContent();
text.Text = "Add text using IronWord";
// Configure text style settings
text.Style = new TextStyle()
{
TextFont = new Font()
{
FontFamily = "Calibri", // Text Font is "Calibri"
FontSize = 24, // Text Size is 24
},
Color = Color.Red, // Set text color to red
IsBold = true, // Make text bold
IsItalic = true, // Make text italic
Underline = new Underline(), // Have an underline
Strike = StrikeValue.DoubleStrike, // No strike-through
};
Paragraph paragraph = new Paragraph();
// Add text to paragraph
paragraph.AddText(text);
// Add paragraph to document
doc.AddParagraph(paragraph);
// Save document
doc.SaveAs("add-text-style.docx");What Output Will This Generate?

The TextStyle class provides essential formatting options including font properties, text color, bold, italic, and underline. The example demonstrates how multiple styling properties combine to create richly formatted text.
What Specific Styles Can I Add?
How Do I Change Text Color?
The Color property in TextStyle sets text color using predefined colors from IronWord.Models.Color or custom hex values. This emphasizes specific content or matches brand colors. IronWord supports a wide range of colors including Red, Blue, Green, Olive, Navy, and Maroon.
:path=/static-assets/word/content-code-examples/how-to/add-style-text-add-text.csusing IronWord;
// Create document
WordDocument doc = new WordDocument();
// Add colored text
TextContent text = new TextContent("This text is olive-colored!");
text.Style = new TextStyle()
{
Color = IronWord.Models.Color.Olive // defining text to be colored olive
};
Paragraph paragraph = new Paragraph();
paragraph.AddText(text);
doc.AddParagraph(paragraph);
// Save document
doc.SaveAs("colored-text.docx");What Does Colored Text Look Like?

How Do I Set Font Family and Size?
Customize text appearance with the TextFont property. Set FontFamily to any installed font name (e.g., "Arial", "Times New Roman") and FontSize in points. This establishes visual hierarchy and ensures readability across different devices and platforms.
:path=/static-assets/word/content-code-examples/how-to/add-style-text-add-font.csusing IronWord;
// Create document
WordDocument doc = new WordDocument();
// Add text with custom font family and size
TextContent text = new TextContent("This text uses Arial at 24pt!");
text.Style = new TextStyle()
{
TextFont = new IronWord.Models.Font()
{
FontFamily = "Arial", // Set font family
FontSize = 24 // Set font size in points
}
};
Paragraph paragraph = new Paragraph();
paragraph.AddText(text);
doc.AddParagraph(paragraph);
// Save document
doc.SaveAs("font-styled-text.docx");What Does Custom Font Styling Look Like?

How Do I Make Text Bold?
Set the IsBold property to true to make text bold. Bold text is commonly used for headings, emphasis, or highlighting important information. Combined with other styling properties, bold text creates visual hierarchy and improves readability.
:path=/static-assets/word/content-code-examples/how-to/add-style-text-add-bold.csusing IronWord;
// Create document
WordDocument doc = new WordDocument();
// Add bold text
TextContent text = new TextContent("this is bold!");
text.Style = new TextStyle()
{
IsBold = true // Make text bold
};
Paragraph paragraph = new Paragraph();
paragraph.AddText(text);
doc.AddParagraph(paragraph);
// Save document
doc.SaveAs("bold-text.docx");
What Does Bold Text Look Like?

How Do I Make Text Italic?
Set the IsItalic property to true for italic styling. Italic text is typically used for emphasis, titles, foreign words, or technical terms. This subtle formatting differentiates text elements without the visual weight of bold formatting.
:path=/static-assets/word/content-code-examples/how-to/add-style-text-add-italic.csusing IronWord;
// Create document
WordDocument doc = new WordDocument();
// Add italic text
TextContent text = new TextContent("this is italic.");
text.Style = new TextStyle()
{
IsItalic = true // Make text italic
};
Paragraph paragraph = new Paragraph();
paragraph.AddText(text);
doc.AddParagraph(paragraph);
// Save document
doc.SaveAs("italic-text.docx");What Does Italic Text Look Like?

What Are the Available Styling Properties?
IronWord provides comprehensive styling properties mirroring Microsoft Word's formatting options. These properties combine to create complex text formatting meeting professional document standards.
| Styling Method | Description | Example |
|---|---|---|
TextFont | Customizes text appearance with a Font object, setting font family and size in points. | text.Style.TextFont = new Font() { FontFamily = "Calibri", FontSize = 24 }; |
Color | Sets text color using predefined colors from IronWord.Models.Color or custom hex values. | text.Style.Color = IronWord.Models.Color.Red; |
IsBold | Makes text bold when set to true, commonly used for headings or emphasis. | text.Style.IsBold = true; |
IsItalic | Applies italic styling to text when set to true, typically used for emphasis or titles. | text.Style.IsItalic = true; |
Underline | Adds an underline to text using an Underline object with various underline styles. | text.Style.Underline = new Underline(); |
Strike | Applies strikethrough to text using StrikeValue enum (Strike or DoubleStrike). | text.Style.Strike = StrikeValue.Strike; |
Caps | Applies capitalization effects to text, converting all characters to uppercase display. | text.Style.Caps = true; |
CharacterScale | Adjusts the proportional width of characters as a percentage of their normal size. | text.Style.CharacterScale = 150; |
Emboss | Applies an embossed effect to text, creating a raised appearance. | text.Style.Emboss = true; |
Emphasis | Adds emphasis marks to styled text using EmphasisMarkValues enum values. | text.Style.Emphasis = EmphasisMarkValues.Dot; |
LineSpacing | Controls spacing between lines of text for improved readability using a LineSpacing object. | text.Style.LineSpacing = new LineSpacing() { Value = 1.5 }; |
Outline | Renders text with an outline effect, displaying only the character borders. | text.Style.Outline = true; |
Shading | Applies background color or shading to text using a Shading object. | text.Style.Shading = new Shading() { Color = Color.Yellow }; |
SmallCaps | Converts lowercase letters to small capital letters while maintaining case distinction. | text.Style.SmallCaps = true; |
VerticalPosition | Adjusts vertical placement of text relative to its baseline, measured in points. | text.Style.VerticalPosition = 5.0; |
VerticalTextAlignment | Positions text vertically within its container using VerticalPositionValues enum. | text.Style.VerticalTextAlignment = VerticalPositionValues.Superscript; |
Combining Multiple Styles
IronWord's text styling power comes from combining multiple properties to achieve complex formatting. Here's an example demonstrating professionally styled text by combining various styling properties:
using IronWord;
using IronWord.Models;
// Create a new document
WordDocument doc = new WordDocument();
// Create richly formatted text
TextContent headerText = new TextContent("Professional Document Header");
headerText.Style = new TextStyle()
{
TextFont = new Font()
{
FontFamily = "Georgia",
FontSize = 28
},
Color = Color.DarkBlue,
IsBold = true,
SmallCaps = true,
Underline = new Underline(),
CharacterScale = 110, // Slightly expand character width
Shading = new Shading()
{
Color = Color.LightGray // Light background
}
};
// Add header to document
Paragraph headerParagraph = new Paragraph();
headerParagraph.AddText(headerText);
doc.AddParagraph(headerParagraph);
// Create body text with different styling
TextContent bodyText = new TextContent("This is professionally formatted body text with custom styling.");
bodyText.Style = new TextStyle()
{
TextFont = new Font()
{
FontFamily = "Calibri",
FontSize = 11
},
Color = Color.Black,
LineSpacing = new LineSpacing() { Value = 1.15 } // Slightly increased line spacing
};
Paragraph bodyParagraph = new Paragraph();
bodyParagraph.AddText(bodyText);
doc.AddParagraph(bodyParagraph);
// Save the document
doc.SaveAs("professional-document.docx");using IronWord;
using IronWord.Models;
// Create a new document
WordDocument doc = new WordDocument();
// Create richly formatted text
TextContent headerText = new TextContent("Professional Document Header");
headerText.Style = new TextStyle()
{
TextFont = new Font()
{
FontFamily = "Georgia",
FontSize = 28
},
Color = Color.DarkBlue,
IsBold = true,
SmallCaps = true,
Underline = new Underline(),
CharacterScale = 110, // Slightly expand character width
Shading = new Shading()
{
Color = Color.LightGray // Light background
}
};
// Add header to document
Paragraph headerParagraph = new Paragraph();
headerParagraph.AddText(headerText);
doc.AddParagraph(headerParagraph);
// Create body text with different styling
TextContent bodyText = new TextContent("This is professionally formatted body text with custom styling.");
bodyText.Style = new TextStyle()
{
TextFont = new Font()
{
FontFamily = "Calibri",
FontSize = 11
},
Color = Color.Black,
LineSpacing = new LineSpacing() { Value = 1.15 } // Slightly increased line spacing
};
Paragraph bodyParagraph = new Paragraph();
bodyParagraph.AddText(bodyText);
doc.AddParagraph(bodyParagraph);
// Save the document
doc.SaveAs("professional-document.docx");This comprehensive styling approach creates documents maintaining consistent branding and professional appearance throughout your application's document generation process.
Frequently Asked Questions
How do I apply text formatting to Word documents programmatically in C#?
IronWord's TextStyle class enables you to apply professional text formatting including fonts, colors, bold, italic, and underline. Simply create a TextContent object with your text, apply a TextStyle with desired properties, add it to a paragraph, and save the document.
What are the basic steps to style text in DOCX files?
To style text with IronWord: 1) Install IronWord via NuGet, 2) Create a WordDocument object, 3) Create TextContent with your text, 4) Apply TextStyle properties like font, color, or bold, 5) Add the text to a paragraph and save.
What text formatting options are available?
IronWord's TextStyle class provides essential formatting options including font properties (FontFamily and FontSize), text color, bold, italic, underline, and strikethrough. These options can be combined to create richly formatted text.
How do I change the font family and size of text?
Use the TextFont property in TextStyle to specify font family and size. Set the FontFamily to fonts like 'Arial' or 'Times New Roman', and FontSize to your desired point size, such as 16 for larger text.
Can I apply multiple text styles simultaneously?
Yes, IronWord allows you to combine multiple styling properties in a single TextStyle object. You can apply bold, italic, color, and font changes all at once to create complex text formatting.
How do I change text color in Word documents using C#?
The Color property in IronWord's TextStyle allows you to set text color using predefined colors from IronWord.Models.Color or custom hex values. This feature helps emphasize specific content or match brand colors in your documents.






