HtmlTextWriter.Indent Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets or sets the number of tab positions to indent the beginning of each line of markup.

Namespace:   System.Web.UI
Assembly:  System.Web (in System.Web.dll)

public int Indent { get; set; }

Property Value

Type: System.Int32

The number of tab positions to indent each line.

Indentation is performed by writing the string that is specified by the tabString parameter of the HtmlTextWriter(TextWriter, String) constructor the number of times that are specified by the Indent property.

If the Indent property is set to a negative value, it is changed to 0 before being saved.

The following code example demonstrates how to increment the value that is assigned to the Indent property when attributes have been added to the opening tag of a <span> element and the RenderBeginTag method has been called. This increases the indentation for any markup that is rendered inside the <span> element.

// Set attributes and values along with attributes and styles  
// attribute defined for a <span> element.
writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "alert('Hello');");
writer.AddAttribute("CustomAttribute", "CustomAttributeValue");
writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "Red");
writer.AddStyleAttribute("Customstyle", "CustomStyleValue");
// Create a space and indent the markup inside the 
// <span> element.

.NET Framework
Available since 1.1
Return to top