HTML is a markup language that is used to create and design web pages. They can include text in different forms like paragraphs, lists, tables, etc. Likewise, it can contain images, videos, animations and any kind of graphical object. In certain cases, you may need to format text by changing the text color. Accordingly, this article covers how to change text color in HTML using C#.
- HTML Text Color Formatting – C# API Installation
- Change Text Color in HTML using Inline CSS using C#
- Change Text String Color in HTML using Internal CSS in C#
HTML Text Color Formatting – C# API Installation
Aspose.HTML for .NET API supports creating or manipulating HTML pages and other file formats in C#. Simply configure the API by accessing the DLL file from the Downloads page or running the NuGet installation command below:
PM> Install-Package Aspose.Html
Change Text Color in HTML using Inline CSS using C#
You can change the text color in an HTML file using inline CSS with the following steps:
- Create an instance of HTMLDocument class.
- Find the first paragraph element to set a style attribute.
- Set the style attribute with the color property.
- Save the HTML document.
The following code snippet demonstrates how to change text color in HTML using inline CSS in C#:
Change Text String Color in HTML using Internal CSS in C#
You can change text color in an HTML file using internal CSS with the steps below:
- Initialize HTMLDocument class instance.
- Create a style element and assign the text color value for all paragraph elements.
- Find the document head element and append style.
- Save the HTML document.
The code snippet below shows how to change text color in an HTML file using internal CSS programmatically in C#:
Explore Aspose.HTML for .NET
You can take a look at the documentation section to understand many other features included in the API.
Get Free License
Eager to test the API without any limitations? Please feel free to request a free temporary license.
Conclusion
In this article, you have learned how to change text string color in an HTML file programmatically in C#. It covers different approaches which can cater to different requirements and scenarios based on your requirements. In case you want to discuss any of your concerns or queries, please reach out to us at forum.