Badge Component — sgcHTML | eSeGeCe

Badge

TsgcHTMLComponent_Badge — render a single Bootstrap 5 badge with color, pill shape, an inline icon and a positioned notification-dot mode, in Delphi, C++ Builder and .NET.

TsgcHTMLComponent_Badge

Set the text and color, then read the HTML property — or skip the create/free entirely with the static Build helper.

Component class

TsgcHTMLComponent_Badge

Renders

A single Bootstrap 5 <span class="badge">

Languages

Delphi, C++ Builder, .NET

Build it in one line, or configure it fully

Call the static Build(text, color, pill) for a quick inline badge, or create the component to also set Icon and Positioned, then read HTML.

uses
  sgcHTML_Enums, sgcHTML_Component_Badge;

var
  oBadge: TsgcHTMLComponent_Badge;
begin
  oBadge := TsgcHTMLComponent_Badge.Create(nil);
  try
    oBadge.Text := '3';
    oBadge.Color := bgDanger;
    oBadge.Pill := True;
    oBadge.Positioned := True;

    WebModule.Response := oBadge.HTML;   // <span class="badge bg-danger rounded-pill ...">
  finally
    oBadge.Free;
  end;
end;

// Or the one-line static helper for a simple inline badge:
WebModule.Response := TsgcHTMLComponent_Badge.Build('New', bgSuccess, True);
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_Badge.hpp

TsgcHTMLComponent_Badge *oBadge = new TsgcHTMLComponent_Badge(NULL);
try
{
  oBadge->Text = "3";
  oBadge->Color = bgDanger;
  oBadge->Pill = true;
  oBadge->Positioned = true;

  String html = oBadge->HTML;   // <span class="badge bg-danger rounded-pill ...">
}
__finally
{
  delete oBadge;
}

// Or the one-line static helper:
String html2 = TsgcHTMLComponent_Badge::Build("New", bgSuccess, true);
using esegece.sgcWebSockets;

var badge = new TsgcHTMLComponent_Badge();
badge.Text = "3";
badge.Color = TsgcHTMLBadgeStyle.bgDanger;
badge.Pill = true;
badge.Positioned = true;

string html = badge.HTML;   // <span class="badge bg-danger rounded-pill ...">

// Or the one-line static helper:
string html2 = TsgcHTMLComponent_Badge.Build("New", TsgcHTMLBadgeStyle.bgSuccess, true);

Key properties & methods

The members you reach for most often.

Text & color

Text is the label; Color (TsgcHTMLBadgeStyle: bgPrimary, bgSecondary, bgSuccess, bgDanger, bgWarning, bgInfo, bgLight, bgDark) sets the Bootstrap variant.

Pill

Pill switches the badge to the fully-rounded rounded-pill shape.

Icon

Icon renders an <i> element (e.g. a Bootstrap Icons class) before the text.

Positioned

Positioned adds position-absolute top-0 start-100 translate-middle, turning the badge into a notification dot anchored to a position-relative parent.

Static helper

Build(aText, aColor, aPill) returns the badge HTML directly, with no instance to create or free.

Output

HTML returns a single <span class="badge bg-..."> element, ready to embed inline.

Keep exploring

Online HelpFull API reference and usage guide for this component.
All sgcHTML ComponentsBrowse the full feature matrix of 80+ components.
Download Free TrialThe 30-day trial ships the 60.HTML demo projects.
PricingSingle, Team and Site licenses with full source code.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Get Started?

Download the free trial and start building web UIs in Delphi, C++ Builder and .NET.