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#

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronWord with NuGet Package Manager

    PM > Install-Package IronWord

  2. Copy and run this code snippet.

    // Quick example
    using IronWord;
    using IronWord.Models;
    
    // Initialize a new Word document
    WordDocument doc = new WordDocument();
    
    // Create a Run with styled text
    Run textRun = new Run(new TextContent("Styled text"));
    
    // Apply styling properties to the Run
    textRun.Style = new TextStyle()
    {
        IsBold = true,
        Color = Color.Red,
        FontSize = 16,
        TextFont = new Font()
        {
            FontFamily = "Arial"
        }
    };
    
    // Create paragraph and add the styled Run
    Paragraph paragraph = new Paragraph();
    paragraph.AddChild(textRun);
    
    // Add paragraph to document and save
    doc.AddParagraph(paragraph);
    doc.SaveAs("styled.docx");
  3. Deploy to test on your live environment

    Start using IronWord in your project today with a free trial
    arrow pointer

How Do I Add Text Style to DOCX?

Applying text styles in IronWord requires using the Run wrapper pattern. Create a WordDocument object, then create a Run object containing TextContent with your text. Apply a TextStyle to the Run (not the TextContent) using properties such as IsBold, Color, or FontSize.

Once styled, add the Run to a Paragraph using AddChild, 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.

Please noteIronWord's document hierarchy follows the structure: Document → DocumentSection → Paragraph → Run → TextContent. Styles are applied at the Run level, not on TextContent directly.

:path=/static-assets/word/content-code-examples/how-to/add-style-text-simple.cs
using IronWord;
using IronWord.Models;
using IronWord.Models.Enums;

// Load docx
WordDocument doc = new WordDocument("sample.docx");

// Configure text
Run textRun = new Run(new TextContent("Add text using IronWord"));

// Configure text style settings
textRun.Style = new TextStyle()
{
    FontSize = 24, // Text Size is 24
    TextFont = new Font()
    {
        FontFamily = "Calibri" // Text Font is "Calibri"
    },
    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.AddChild(textRun);

// Add paragraph to document
doc.AddParagraph(paragraph);

// Save document
doc.SaveAs("add-text-style.docx");
$vbLabelText   $csharpLabel

What Output Will This Generate?

Microsoft Word interface showing Layout ribbon and document with red strikethrough text formatting applied

The TextStyle class provides essential formatting options including font properties, text color, bold, italic, and underline. Note that FontSize is configured at the TextStyle level (not inside Font), while FontFamily is set within the TextFont property. The Run object wraps the TextContent and holds the style, following IronWord's document hierarchy pattern. The example demonstrates how multiple styling properties combine to create richly formatted text when applied to a Run.


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.cs
using IronWord;
using IronWord.Models;

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

// Add colored text
Run textRun = new Run(new TextContent("This text is olive-colored!"));
textRun.Style = new TextStyle()
{
    Color = IronWord.Models.Color.Olive // defining text to be colored olive
};

Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);
doc.AddParagraph(paragraph);

// Save document
doc.SaveAs("colored-text.docx");
$vbLabelText   $csharpLabel

What Does Colored Text Look Like?

Microsoft Word showing olive-colored text formatting with Home tab ribbon displaying font and paragraph tools

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.cs
using IronWord;
using IronWord.Models;

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

// Add text with custom font family and size
Run textRun = new Run(new TextContent("This text uses Arial at 24pt!"));
textRun.Style = new TextStyle()
{
    FontSize = 24,  // Set font size in points
    TextFont = new IronWord.Models.Font()
    {
        FontFamily = "Arial"  // Set font family
    }
};

Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);
doc.AddParagraph(paragraph);

// Save document
doc.SaveAs("font-styled-text.docx");
$vbLabelText   $csharpLabel

What Does Custom Font Styling Look Like?

Microsoft Word showing Arial font at 24pt selected in toolbar with formatted sample text displayed

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.cs
using IronWord;
using IronWord.Models;

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

// Add bold text
Run textRun = new Run(new TextContent("this is bold!"));
textRun.Style = new TextStyle()
{
    IsBold = true  // Make text bold
};

Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);
doc.AddParagraph(paragraph);

// Save document
doc.SaveAs("bold-text.docx");
$vbLabelText   $csharpLabel

What Does Bold Text Look Like?

Microsoft Word interface showing bold text formatting with 'this is bold!' text displayed in the document

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.cs
using IronWord;
using IronWord.Models;

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

// Add italic text
Run textRun = new Run(new TextContent("this is italic."));
textRun.Style = new TextStyle()
{
    IsItalic = true  // Make text italic
};

Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);
doc.AddParagraph(paragraph);

// Save document
doc.SaveAs("italic-text.docx");
$vbLabelText   $csharpLabel

What Does Italic Text Look Like?

Word document showing italicized text with Home tab formatting options visible in ribbon interface

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. Note: FontSize is set at TextStyle level, not inside Font. textRun.Style = new TextStyle() { FontSize = 24, TextFont = new Font() { FontFamily = "Calibri" } };
Color Sets text color using predefined colors from IronWord.Models.Color or custom hex values. textRun.Style.Color = IronWord.Models.Color.Red;
IsBold Makes text bold when set to true, commonly used for headings or emphasis. textRun.Style.IsBold = true;
IsItalic Applies italic styling to text when set to true, typically used for emphasis or titles. textRun.Style.IsItalic = true;
Underline Adds an underline to text using an Underline object with various underline styles. textRun.Style.Underline = new Underline();
Strike Applies strikethrough to text using StrikeValue enum (Strike or DoubleStrike). textRun.Style.Strike = StrikeValue.Strike;
Caps Applies capitalization effects to text, converting all characters to uppercase display. textRun.Style.Caps = true;
CharacterScale Adjusts the proportional width of characters as a percentage of their normal size. textRun.Style.CharacterScale = 150;
Emboss Applies an embossed effect to text, creating a raised appearance. textRun.Style.Emboss = true;
Emphasis Adds emphasis marks to styled text using EmphasisMarkValues enum values. textRun.Style.Emphasis = EmphasisMarkValues.Dot;
LineSpacing Controls spacing between lines of text for improved readability using a LineSpacing object. textRun.Style.LineSpacing = new LineSpacing() { Value = 1.5 };
Outline Renders text with an outline effect, displaying only the character borders. textRun.Style.Outline = true;
Shading Applies background color or shading to text using a Shading object. textRun.Style.Shading = new Shading() { Color = Color.Yellow };
SmallCaps Converts lowercase letters to small capital letters while maintaining case distinction. textRun.Style.SmallCaps = true;
VerticalPosition Adjusts vertical placement of text relative to its baseline, measured in points. textRun.Style.VerticalPosition = 5.0;
VerticalTextAlignment Positions text vertically within its container using VerticalPositionValues enum. textRun.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 header text using Run
Run headerRun = new Run(new TextContent("Professional Document Header"));
headerRun.Style = new TextStyle()
{
    FontSize = 28,
    TextFont = new Font()
    {
        FontFamily = "Georgia"
    },
    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 using AddChild for styled Run
Paragraph headerParagraph = new Paragraph();
headerParagraph.AddChild(headerRun);
doc.AddParagraph(headerParagraph);

// Create body text with different styling
Run bodyRun = new Run(new TextContent("This is professionally formatted body text with custom styling."));
bodyRun.Style = new TextStyle()
{
    FontSize = 11,
    TextFont = new Font()
    {
        FontFamily = "Calibri"
    },
    Color = Color.Black,
    LineSpacing = new LineSpacing() { Value = 1.15 }  // Slightly increased line spacing
};

Paragraph bodyParagraph = new Paragraph();
bodyParagraph.AddChild(bodyRun);
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 header text using Run
Run headerRun = new Run(new TextContent("Professional Document Header"));
headerRun.Style = new TextStyle()
{
    FontSize = 28,
    TextFont = new Font()
    {
        FontFamily = "Georgia"
    },
    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 using AddChild for styled Run
Paragraph headerParagraph = new Paragraph();
headerParagraph.AddChild(headerRun);
doc.AddParagraph(headerParagraph);

// Create body text with different styling
Run bodyRun = new Run(new TextContent("This is professionally formatted body text with custom styling."));
bodyRun.Style = new TextStyle()
{
    FontSize = 11,
    TextFont = new Font()
    {
        FontFamily = "Calibri"
    },
    Color = Color.Black,
    LineSpacing = new LineSpacing() { Value = 1.15 }  // Slightly increased line spacing
};

Paragraph bodyParagraph = new Paragraph();
bodyParagraph.AddChild(bodyRun);
doc.AddParagraph(bodyParagraph);

// Save the document
doc.SaveAs("professional-document.docx");
$vbLabelText   $csharpLabel

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.

Ahmad Sohail
Full Stack Developer

Ahmad is a full-stack developer with a strong foundation in C#, Python, and web technologies. He has a deep interest in building scalable software solutions and enjoys exploring how design and functionality meet in real-world applications.

Before joining the Iron Software team, Ahmad worked on automation projects ...

Read More
Ready to Get Started?
Nuget Downloads 34,633 | Version: 2026.3 just released