How to justify the text in a Label in

Justify text in a Label control
The Label class Represents a label control, which displays text on a Web page. The developers can use the Label control to display text in a set location on the web page. Unlike static text, c# developers can customize the displayed text through the Text property.

The following c# tutorial code demonstrates how we can justify the text on a Label web server control. To justify text in a Label control, the c# developers have to apply a custom CSS style to a Label control.

The Label CssClass property gets or sets the Cascading Style Sheet (CSS) class rendered by the Web server control on the client. The CssClass property is inherited from WebControl. The CssClass property value is a String which is the CSS class rendered by the Label server control on the client. The default value of this property is Empty.

So using this CssClass property the c# developers can justify text in a Label control. The developers just have to set the CSS text-align style value to justify.

There is another way to justify Label web server control’s text. The c# developers have to add a Style property to a Label control where they can use the Style property Add() method to add the text-align CSS style with justify value.

The Label Style property gets a collection of text attributes that will be rendered as a style attribute on the outer tag of the Web server control. This property is also inherited from WebControl. The Style property value is a CssStyleCollection that contains the HTML style attributes to render on the outer tag of the Web server control.

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

        //another way to apply label justify text.
<html xmlns="">      
<head id="Head1" runat="server">      
    <style type="text/css">
        .LabelJustifyTextStyle {
    <title> example - label justify text</title>
    <form id="form1" runat="server">      
        <h2 style="color:MidnightBlue; font-style:italic;">      
   example - label justify text
        <hr width="550" align="left" color="Gainsboro" />      
            Text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's..."
        <br /><br /><br />
            Text="label justify text"  
More examples