How to align text to center in a Label in example - label text align center
Label is an web server control. label control allow us to display text on web page. label control has no built in property or method to align its displayed text on web page. so we need to take help from core css style to align label control text to center.

label control Style property get a collection of text attributes that will be rendered as a style attribute on the outer tag (label control). this property value type is System.Web.UI.CssStyleCollection which represent a CssStyleCollection that contains the html style attributes to render on the outer tag of the label web server control. so we can add css style to label control by using its Style property's Add() method.

we added the css style 'text-align' and its value 'center' to the label control by using its Style property Add() method. so the label control display its text as center aligned.

we also can apply label text to center aligned by attaching a css class to label control, after declaring a css class on web page header section. in this css section we set a css style 'text-align' and its value to 'center'.

the following c# example code demonstrate us how can we apply label text align center in an application.

<%@ Page Language="C#" AutoEventWireup="true"%>  
<!DOCTYPE html>
<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
        Label1.CssClass = "LabelTextAlignStyle";

        //another way to apply css style in label control.
<html xmlns="">      
<head id="Head1" runat="server">      
    <style type="text/css">
        .LabelTextAlignStyle {
    <title> example - label text align center</title>
    <form id="form1" runat="server">      
        <h2 style="color:MidnightBlue; font-style:italic;">      
   example - label text align center
        <hr width="550" align="left" color="Gainsboro" />      
            Text="sample label to test label text align center."
        <br /><br /><br />
            Text="label text align center"  
More examples