Change Color of Paragraph and Text in Word with Python [Tutorial]
Changing text color in a Word document might sound simple, but doing it manually can be time-consuming—especially when you need to update multiple paragraphs or highlight specific words across dozens of files. Whether you’re customizing document themes, emphasizing keywords, or creating visually clear reports, automating the process with Python can save you hours of repetitive work. In this guide, you’ll learn how to change the color of both entire paragraphs and specific text in Word using just a few lines of Python code.
Install Python Library
To change text color in Word with Python, you’ll need a reliable library that can handle Word documents efficiently. Spire.Doc for Python is a great choice because it allows you to create, edit, and format Word files without relying on Microsoft Word or other third-party tools. It’s lightweight, fast, and supports a wide range of Word operations, including text styling, paragraph formatting, and document conversion.
You can install it easily using pip:
pip install Spire.Doc
Once installed, you’re ready to start modifying Word documents programmatically with just a few lines of code.
How to Change Paragraph Color in a Word Document with Python
If a paragraph contains key information or you simply want to make it stand out, changing its text color is an easy and effective way to draw attention. For example, you might want to highlight important notes in a report, emphasize warnings in a technical document, or visually separate different sections in a proposal. With Spire.Doc for Python, you can change the color of one or multiple paragraphs instantly—no more manual formatting in Word. It’s a quick, automated solution that keeps your documents clean, consistent, and professional.
Code example: change the color of the third paragraph in a Word document
from spire.doc import *
from spire.doc.common import *
inputFile = "/AI-Generated Art.docx"
outputFile = "/ChangeParagraphFontColor.docx"
# Create a Document object and load the document
doc = Document()
doc.LoadFromFile(inputFile)
# Set the target paragraph index and color
target_paragraph_index = 2
target_color = Color.get_DarkOrange()
# Get the target paragraph
section = doc.Sections[0]
if target_paragraph_index < section.Paragraphs.Count:
paragraph = section.Paragraphs[target_paragraph_index]
# Loop through the text objects in the paragraph
for i in range(paragraph.ChildObjects.Count):
child = paragraph.ChildObjects.get_Item(i)
if isinstance(child, TextRange):
child.CharacterFormat.TextColor = target_color
else:
print("The target paragrph is not found.")
# Save the result
doc.SaveToFile(outputFile, FileFormat.Docx)
doc.Close()

Key steps explained:
Load a Word document using the Document.LoadFromFile() method.
Access the target paragraph through the Section.Paragraphs[] collection.
Iterate through the paragraph’s ChildObjects and identify text elements (TextRange objects).
Change the text color by setting the CharacterFormat.TextColor property.
Save the modified document using the SaveToFile() method.
How to Change Text Color in Word Documents with Python
Besides changing the color of an entire paragraph, you can also change the color of specific text within a paragraph. This is especially useful when you want to highlight a particular term or phrase without altering the rest of the document’s layout. It helps readers quickly notice key information while keeping the overall formatting intact.
Unlike changing a paragraph’s color, modifying specific text requires first locating the target text using the FindString() or FindAllString() methods.
Here’s a complete code example that demonstrates how to change the color of every occurrence of the phrase “AI-generated art” in a Word document:
from spire.doc import *
from spire.doc.common import *
inputFile = "/AI-Generated Art.docx"
outputFile = "/ChangeTextFontColor.docx"
# Create a Document object and load the document
doc = Document()
doc.LoadFromFile(inputFile)
# Set the target text and color
search_text = "AI-generated art"
target_color = Color.get_BlueViolet()
# Find all matching text
textSelections = doc.FindAllString(search_text, False, True)
# Loop through all matches and modify color
for selection in textSelections:
textRange = selection.GetAsOneRange()
textRange.CharacterFormat.TextColor = target_color
# Save the result
doc.SaveToFile(outputFile, FileFormat.Docx)
doc.Close()

Key steps explained:
Load a Word document using the Document.LoadFromFile() method.
Find all occurrences of the target text with the Document.FindAllString() method. If you only need to change the color of the first matched text, use the Document.FindString() method instead.
Iterate through all matched results and retrieve each as a TextRange object.
Change the color of the text by setting the TextRange.CharacterFormat.TextColor property.
Save the updated document using the SaveToFile() method.
The Conclusion
By using Spire.Doc for Python, you can easily control text and paragraph colors in Word documents without manual formatting. Whether you need to highlight key terms, emphasize important sections, or improve readability, automating these tasks with Python makes your workflow faster and more consistent.