using System.Web.UI; HtmlTextWriter writer = new HtmlTextWriter(Response.Output); writer.AddStyleAttribute("color", "red"); writer.RenderBeginTag("span"); writer.Write("This text is red"); writer.RenderEndTag();
using System.Web.UI; HtmlTextWriter writer = new HtmlTextWriter(Response.Output); writer.AddStyleAttribute("color", "red"); writer.AddStyleAttribute("font-size", "16px"); writer.RenderBeginTag("span"); writer.Write("This text is red and 16px"); writer.RenderEndTag();In this example, we create a new HtmlTextWriter object, add two style attributes of "color:red" and "font-size:16px" to a span element, write text inside the span, and close the span tag. This will output HTML that displays the text in red and with a font size of 16 pixels. Most likely, the HtmlTextWriter class is included in the System.Web.dll package library of C#.