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.

C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development: Build applications with C#, .NET Core, Entity Framework Core, ASP.NET Core, and ML.NET using Visual Studio Code, 4th Edition
ASP.NET Core 3 and Angular 9: Full stack web development with .NET Core 3.1 and Angular 9, 3rd Edition
C# in Depth, 4th Edition


<%@ 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;