You can apply CSS style 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 of the Label control. However you can use ForeColor and BackColor directly from the Label control.


<%@ Page Language=”C#” AutoEventWireup=”false” CodeBehind=”TestApplyCSS.aspx.cs”

Inherits=”TestChange.TestApplyCSS” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”>

<html xmlns=””>

<head runat=”server”>

<title>Apply CSS style in the Label control from code-behind</title>



<form id=”form1″ runat=”server”>


<asp:Label ID=”LabelTest” runat=”server” Text=”My test label”></asp:Label>






using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class TestApplyCSS : System.Web.UI.Page

protected void Page_Load(object sender, System.EventArgs e)

string[] FontNames = {

LabelTest.Font.Names = FontNames;
LabelTest.Font.Bold = true;
LabelTest.Font.Size = FontUnit.Large;
LabelTest.ForeColor = System.Drawing.Color.Black;
LabelTest.BackColor = System.Drawing.Color.LightGray;