Skip to content

<Label>

Renders a static caption next to a form control. The For attribute associates the label with a specific input control (by Id), letting screen readers announce the caption when the user focuses the control. The label's text can be set via the Text attribute, or by placing text between <Label> and </Label>.

Example

html
<AddForm>
  ...
  <table>
    <tr>
      <td>
        <Label Id="lblFirstName" For="txtFirstName" Text="First Name" />
        <TextBox Id="txtFirstName" DataField="FirstName" DataType="String" />
      </td>
    </tr>
    <tr>
      <td>
        <Label Id="lblLastName" For="txtLastName" Text="Last Name" />
        <TextBox Id="txtLastName" DataField="LastName" DataType="String" />
      </td>
    </tr>
    <tr>
      <td colspan="2"><AddButton Text="Add" /> <CancelButton Text="Cancel" /></td>
    </tr>
  </table>
</AddForm>

Properties

PropertyValuesDefaultDescription
IdstringUnique identifier for the label within the form
Forcontrol idThe Id of the input control this label captions. Used for accessibility
TextstringCaption text. Alternatively, place the caption between the opening and closing <Label> tags
CssClassstringCSS class name(s) for styling
StylestringInline CSS (e.g. color: red; font-weight: bold;)
VisibleTrue FalseTrueShows or hides the label
Deprecated Properties

These properties use ASP.NET inline styling and are no longer recommended for modern web development. Use the CssClass property to apply CSS classes or the Style property for inline CSS instead.

PropertyValuesDescription
BackColorcolor name | #ddddddBackground color of the control
BorderColorcolor name | #ddddddBorder color of the control
BorderStyleNotSet None Dotted Dashed Solid Double Groove Ridge Inset OutsetBorder style
BorderWidthsizeBorder width
Font-BoldTrue FalseBold text
Font-ItalicTrue FalseItalic text
Font-NamesstringFont family name
Font-OverlineTrue FalseOverline text decoration
Font-SizeXX-Small X-Small Small Medium Large X-Large XX-Large or sizeFont size
Font-StrikeoutTrue FalseStrikethrough text decoration
Font-UnderlineTrue FalseUnderline text decoration
ForeColorcolor name | #ddddddText color

Property Details

  • For: The Id of the input control this label captions. When set, the label renders as an HTML <label for="..."> element pointing to that control. This lets assistive technology read the caption when the user focuses the input, and lets sighted users click the caption to focus the input.

  • Text: The caption to display. Alternatively, you can place the caption between the opening <Label> and closing </Label> tags — useful when the caption needs HTML markup.

    html
    <Label For="txtNotes"><strong>Notes</strong> <em>(optional)</em></Label>