How to Add Style to Text in DOCX

This article was translated from English: Does it need improvement?
Translated
View the article in English

Customizing text styling in Word documents is essential for creating professional and visually appealing content. IronWord offers industry-grade text styling options similar to what's available in your favorite DOCX editor, allowing you to apply formatting programmatically with ease.

In this how-to, we'll explore how to stylize text content with custom settings using IronWord's TextStyle class.

Get started with IronWord

Comience a usar IronWord en su proyecto hoy con una prueba gratuita.

Primer Paso:
green arrow pointer


Adding Text Style Example

Applying text styles in IronWord is straightforward. Create a WordDocument object, then create a TextContent object with your text. Apply a TextStyle to it using properties such as IsBold, Color, or TextFont, and enhance the styling further with options like underline or strikethrough.

Once the text is fully styled, add it to a Paragraph, insert the paragraph into the document, and save the final result.

: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");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

Add style to text in DOCX

The TextStyle class provides essential formatting options, including font properties, text color, bold, italic, and underline, giving you the flexibility to create professional-looking documents quickly.


Adding Specific Styles

Text Color

The Color property in TextStyle allows you to set text color using predefined colors from IronWord.Models.Color or custom hex values. This is useful for emphasizing specific content or matching brand colors in your documents.

: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");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

Add text color in DOCX

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 allows you to match document styles or establish a clear visual hierarchy.

: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");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

Add font style to text in DOCX

Bold

Use the IsBold property set to true to make text bold. Bold text is commonly used for headings, emphasis, or highlighting important information in your documents.

: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");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

Add bold text in DOCX

Italic

The IsItalic property set to true applies italic styling to text. Italic text is typically used for emphasis, titles, foreign words, or technical terms.

: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");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

Add italic text in DOCX

Styling Properties

Expore more styling options in the below table.

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;

Preguntas Frecuentes

¿Qué es IronWord?

IronWord es una biblioteca .NET que permite a los desarrolladores crear, editar y manipular documentos de Word mediante programación. Ofrece funciones completas para el estilo y formato de texto.

¿Cómo puedo cambiar el color del texto en un archivo DOCX usando IronWord?

IronWord ofrece métodos para modificar estilos de texto, incluyendo el cambio de color. Puede especificar el código de color que desea aplicar al texto seleccionado en su documento de Word.

¿Puede IronWord poner el texto en negrita en un documento de Word?

Sí, IronWord admite opciones de formato de texto estándar, incluyendo la negrita. Puede aplicar negrita a elementos de texto específicos en sus archivos DOCX.

¿Es posible aplicar múltiples estilos al texto usando IronWord?

Por supuesto, IronWord te permite aplicar múltiples opciones de estilo al texto. Puedes combinar diferentes estilos como negrita, cursiva y subrayado para personalizar completamente tu documento de Word.

¿Qué tipos de estilos de texto se pueden aplicar usando IronWord?

IronWord admite una variedad de opciones de estilo de texto, incluido el tamaño de fuente, el color de fuente, negrita, cursiva, subrayado y más, lo que le permite personalizar la apariencia de su documento DOCX.

¿IronWord admite estilos de fuente personalizados?

Sí, IronWord te permite usar estilos de fuente personalizados en tus documentos de Word. Puedes especificar las fuentes instaladas en tu sistema para mejorar la apariencia del documento.

¿Puedo automatizar la creación de documentos de Word con estilo usando IronWord?

IronWord está diseñado para facilitar la automatización de la creación y el estilo de documentos de Word. Permite aplicar y modificar estilos de texto mediante programación para generar documentos de forma eficiente.

¿Cómo maneja IronWord la alineación de texto en archivos DOCX?

IronWord ofrece la función de ajustar la alineación del texto en sus documentos de Word. Puede configurar el texto para que se alinee a la izquierda, a la derecha, al centro o justificado según sus necesidades de diseño.

¿Cuáles son los beneficios de usar IronWord para darle estilo al texto DOCX?

El uso de IronWord para diseñar texto DOCX proporciona beneficios como facilidad de integración en aplicaciones .NET, flexibilidad en la aplicación de varios estilos de texto y la capacidad de automatizar tareas de procesamiento de documentos.

¿Es IronWord compatible con diferentes versiones de Microsoft Word?

IronWord está diseñado para trabajar con archivos DOCX, compatibles con varias versiones de Microsoft Word. Ofrece un soporte sólido para crear y editar estos archivos en diferentes versiones de Word.

Ahmad Sohail
Desarrollador Full Stack

Ahmad es un desarrollador full-stack con una sólida base en C#, Python y tecnologías web. Tiene un profundo interés en construir soluciones de software escalables y disfruta explorando cómo el diseño y la funcionalidad se encuentran en aplicaciones del mundo real.

Antes ...

Leer más
¿Listo para empezar?
Nuget Descargas 25,807 | Versión: 2025.11 recién lanzado