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#

  1. Install IronWord via NuGet: Install-Package IronWord
  2. Create a WordDocument object
  3. Create TextContent with your text
  4. Apply TextStyle with desired properties (font, color, bold, etc.)
  5. Add text to paragraph and save document

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 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");
  3. Deploy to test on your live environment

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

Get started with IronWord


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.cs
using 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");
$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. 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.cs
using 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");
$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;

// 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");
$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;

// 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");
$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;

// 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");
$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 MethodDescriptionExample
TextFontCustomizes text appearance with a Font object, setting font family and size in points.text.Style.TextFont = new Font() { FontFamily = "Calibri", FontSize = 24 };
ColorSets text color using predefined colors from IronWord.Models.Color or custom hex values.text.Style.Color = IronWord.Models.Color.Red;
IsBoldMakes text bold when set to true, commonly used for headings or emphasis.text.Style.IsBold = true;
IsItalicApplies italic styling to text when set to true, typically used for emphasis or titles.text.Style.IsItalic = true;
UnderlineAdds an underline to text using an Underline object with various underline styles.text.Style.Underline = new Underline();
StrikeApplies strikethrough to text using StrikeValue enum (Strike or DoubleStrike).text.Style.Strike = StrikeValue.Strike;
CapsApplies capitalization effects to text, converting all characters to uppercase display.text.Style.Caps = true;
CharacterScaleAdjusts the proportional width of characters as a percentage of their normal size.text.Style.CharacterScale = 150;
EmbossApplies an embossed effect to text, creating a raised appearance.text.Style.Emboss = true;
EmphasisAdds emphasis marks to styled text using EmphasisMarkValues enum values.text.Style.Emphasis = EmphasisMarkValues.Dot;
LineSpacingControls spacing between lines of text for improved readability using a LineSpacing object.text.Style.LineSpacing = new LineSpacing() { Value = 1.5 };
OutlineRenders text with an outline effect, displaying only the character borders.text.Style.Outline = true;
ShadingApplies background color or shading to text using a Shading object.text.Style.Shading = new Shading() { Color = Color.Yellow };
SmallCapsConverts lowercase letters to small capital letters while maintaining case distinction.text.Style.SmallCaps = true;
VerticalPositionAdjusts vertical placement of text relative to its baseline, measured in points.text.Style.VerticalPosition = 5.0;
VerticalTextAlignmentPositions 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");
$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 29,064 | Version: 2025.12 just released