In case we need to change the CSS style of the text going to appear on the page, we can use this approach.
<p><asp:Label ID="Label3" runat="server" Text="My third Label"></asp:Label></p>
protected void Page_Load(object sender, EventArgs e)
{
// writeing text from code behind
Label2.Text = "Written from code behind";
// Applying CSS style from code behind
Label3.Text = "Written from code behind";
Label3.Font.Bold = true;
string[] fontNames = {"Verdana", "Arial"};
Label3.Font.Names = fontNames;
Label3.Font.Size = FontUnit.Larger;
Label3.ForeColor = System.Drawing.Color.Green;
Label3.BackColor = System.Drawing.Color.Yellow;
}
CSS style can be applied from code behind by accessing the properties of the control with the help of its Id. Most of the CSS styles can be applied using the Font property and its sub properties however you can use ForeColor and BackColor directly also.