Skip to content

Utilities

Icon

Bit.BlazorUIGlyphSymbol

An icon draws one glyph: a concept or a meaning shown rather than spelled out. It renders any of the 2,300 built-in Fabric MDL2 glyphs by name, or a glyph from any other icon set you have linked - FontAwesome, Bootstrap Icons, Material Icons and Material Symbols each have a factory of their own, and anything else is a matter of naming its CSS classes. It takes one of the theme's colors and one of its three sizes (or a font size of your own), is drawn plain, filled, outlined or in a circle, can be turned by a quarter or by any angle, mirrored, mirrored only in right-to-left, given a fixed width so a column of icons lines up, and set spinning, beating or bouncing at a speed of your own while something is happening. It is hidden from screen readers until you name it, becomes a real keyboard-operable button when you give it a click handler, and can hold an inline SVG of your own instead of a glyph.

Notes

An icon is decorative by default and is hidden from assistive technology, because the overwhelming majority of icons sit beside a label that already says the same thing. Give it an AriaLabel or a Title the moment it is the only thing carrying the meaning.

Usage

Every example is live. Open its code to see exactly what produced the component running underneath.

Basic

IconName is the name of a glyph in the built-in Fabric MDL2 set, and the iconography page is where all 2,300 of them are listed and searchable. IsEnabled draws the icon in the disabled color of whatever role it is painted in, which is how an icon standing for something unavailable stops looking actionable.




Disabled

Variant

Variant decides how much of the icon's color is painted. Text, the default, is the glyph alone with no box around it and no padding, which is what an icon sitting inside a sentence or beside a label should be. Outline and Fill put the glyph in a box of its own - a rule around it, or the role's color behind it with the glyph reversed out - which is how an icon becomes a badge that stands on its own. Circular rounds that box all the way and squares it off at the same time, so a narrow glyph and a wide one are drawn in circles of the same size - the shape of a status dot or an avatar placeholder.




Disabled



Circular

Rotate & Flip

Rotate turns the glyph by a quarter, a half or three quarters of a turn, RotateAngle turns it by any angle in degrees (negative for counter-clockwise, and it replaces Rotate when both are given), and Flip mirrors it on either axis or both. All three are drawn as one transform, so they combine rather than cancel each other out - which is what lets one arrow glyph stand in for all eight directions instead of eight glyphs - and they are written with the individual rotate and scale properties, so an Animation can play on top of them. FlipRtl is the one to reach for in a bilingual app: it mirrors the icon only where the writing runs right-to-left, following the direction of the rendered document rather than a parameter, and it multiplies with an explicit Flip rather than replacing it. Give it to a glyph that points somewhere - an arrow, a chevron, a reply - and never to a clock, a checkmark or a media rewind button, none of which mirror in RTL.


Rotate



RotateAngle



Flip



FlipRtl (the second row is the same icon inside a right-to-left container)


Animation

Animation sets the icon looping. Spin and SpinReverse turn it at the speed of every other loader in the library, Pulse ticks it around in eight steps the way a segmented spinner does, and Beat, BeatFade, Fade, Shake and Bounce draw the eye to something that just changed or needs attention. Each of them is a claim that something is still happening, so none of them belongs on an icon that is merely decorative. They all slow down instead of stopping when the reader has asked for reduced motion, and ForceAnimation restores their full speed for an icon whose motion carries the meaning. AnimationDuration replaces the length of one cycle with a CSS time of your own - the reduced motion factor still multiplies it - AnimationDelay holds the icon still for a CSS time before the first cycle, which is what turns a row of identical icons into a wave, and the turn a Rotate, a RotateAngle or a Flip gives the icon is drawn beside the animation rather than under it, so a mirrored arrow still spins.


Spin
SpinReverse
Pulse
Beat
Fade
Shake
Bounce
BeatFade


AnimationDuration, and a turn the animation plays on top of

Spin 4s
Spin 0.4s
Shake 2s
Beat, turned 45


AnimationDelay: the same animation on three icons, each starting a little after the one before it

Fixed width

The glyphs of an icon font are not all the same width, which is what makes the labels of a menu or a nav start at a different place on every row. FixedWidth gives every icon the same box and centers the glyph inside it, so the labels line up. The first list below is without it and the second with it.


  • Home
  • Settings
  • Profile
  • Sign out
  • Home
  • Settings
  • Profile
  • Sign out

Clickable

OnClick turns the icon into a real control: it joins the tab order, shows the focus ring, reacts to the pointer on hover and while it is pressed, answers Enter and Space as well as the pointer without letting Space scroll the page under it, and is announced as a button. A small glyph is also a small target, so the area that answers the pointer is grown to the 24 by 24 pixels WCAG asks of one while the icon keeps the size it was given. Because it is announced as a button it needs a name, so give it an AriaLabel or a Title; and because a disabled control still has to be found by whatever pointed at it, an icon with IsEnabled false leaves the tab order and refuses the click rather than disappearing - and keeps answering the pointer, so the Title saying why the action is unavailable is still there to be read. It is still an icon and not a BitButton - there is no label, no pressed state and no busy state - so reach for a button whenever the action deserves one.




Clicked 0 times.

Custom content

Anything put inside the icon is rendered in place of a glyph, which is how a set that is neither a font nor a class - an inline SVG, a sprite reference, a picture - still gets the icon's color, size and variant. An SVG drawn with fill="currentColor" follows the color role exactly as a glyph does, and FontSize or Size scales it as long as its own dimensions are given in em. A glyph sits on the baseline the way a letter does, but an SVG or an image is aligned by the bottom edge of its box and rides high next to the text around it; Inline is the quarter of an em that drops it back onto the line.




Aligned by its box and dropped onto the line with Inline

Accessibility

An icon is decorative until something names it. Left unnamed it carries aria-hidden and no role, so a screen reader skips it - which is right for the overwhelming majority of icons, since they sit beside a label that already says the same thing, and an unnamed image is a node a reader stops at with nothing to read out. AriaLabel names it for assistive technology only, Title names it and shows a native tooltip on hover as well, and an aria-labelledby of your own names it from somewhere else on the page. Any of the three gives the icon the img role and takes the hiding away. Give one of them to an icon that is the only thing carrying its meaning - a status dot, an icon-only control - and to nothing else. A native tooltip never appears for a keyboard or a touch user, so use a BitTooltip when the text is meant to be seen rather than only read out.


Attachment

Color

Color paints the icon in one of the theme's roles rather than in a literal color, so every preset and both schemes re-skin it. The first eight are the semantic roles - the ones that mean something, and that a status or a validation icon should be painted in - while the background, foreground and border roles are the neutral tiers of the surface itself, for an icon that has to sit on a colored panel or match the text around it.



Primary

   



Secondary

   



Tertiary

   



Info

   



Success

   



Warning

   



SevereWarning

   



Error

   



PrimaryBackground

   



SecondaryBackground

   



TertiaryBackground

   




PrimaryForeground

   



SecondaryForeground

   



TertiaryForeground

   



PrimaryBorder

   



SecondaryBorder

   



TertiaryBorder

   

External Icons

Icon takes a BitIconInfo, which is how a glyph from any other icon set is named. A set that names its glyphs with CSS classes - FontAwesome, Bootstrap Icons, and almost everything else - is described by a base class, a prefix and a name, and the factories put those together for you: Fa for FontAwesome (which fills in the fa- prefixes you leave out), Bi for Bootstrap Icons, Bit for the built-in set, and Css for the classes of any set at all, spelled out. A set that names its glyphs with a ligature written as the element's text - Material Icons and Material Symbols - is covered by Mi and Ms, which put the family on the class and the name inside the element. A ligature is the icon's own text, which a page translator would otherwise translate into a word that draws nothing, so an icon that renders one is marked as text not to translate. A plain string assigned to Icon is taken as the complete class list, which is the shortest way to write one out. Linking the set's own stylesheet is up to your app; the icon only names the glyph.

An app that draws all of its icons from one other set should not have to write that set out at every icon: IconResolver takes an IconName and answers with the icon it stands for, so a plain name goes on being a plain name. Give it to one icon, or cascade it to a whole subtree through BitParams. An Icon still wins over it, and a resolver that answers with nothing leaves the name to the built-in set - which is what lets one resolver cover the names it knows and fall through for the rest.


FontAwesome



Bootstrap Icons



Material Symbols



IconResolver (plain names, read as FontAwesome ones)

Size

Size is one of the three icon sizes of the design system, so an icon scales with the preset rather than with a number written into the page. FontSize is for everything in between: any CSS length, or the inherit keyword, which makes the icon exactly as big as the text it sits in. It overrides Size when both are given.


Small



Medium



Large



FontSize


Sized by the text around it

Style & Class

Style and Class land on the icon element itself, which is the whole component - there is nothing inside it to reach - so anything CSS can do to a glyph is done from here. A rule of your own wins over the component's, because it is written later in the stylesheet.


RTL

Use BitIcon in right-to-left (RTL). A glyph is not mirrored by the direction alone - a checkmark, a clock and a bus look the same either way - so mirroring is opt-in through FlipRtl, which is what turns the glyphs that point somewhere and leaves the rest untouched. Dir sets the direction for one icon; a dir on any ancestor sets it for all of them, and FlipRtl follows either.


API

Every parameter, public member, sub-class and enum this component exposes.

BitIcon parameters

Name Type Default value Description
Animation BitIconAnimation? null Specifies a looping animation to play on the icon. The animation is drawn with a transform of its own while Rotate, RotateAngle and Flip are drawn with the individual rotate and scale properties beside it, so the two compose: a mirrored arrow still spins, and it spins around the angle it was turned to.
AnimationDuration string? null Overrides how long one cycle of the animation takes, as any CSS time. The reduced motion factor still multiplies it, so an animation asked to run fast still slows down for a reader who asked for less motion.
AnimationDelay string? null Waits this long before the animation starts, as any CSS time - which is what turns a row of identical animated icons into a wave. The wait is not stretched under reduced motion the way the cycle is.
ChildContent RenderFragment? null The content rendered inside the icon element, for an icon set that is neither a font nor a class - an inline svg, an image, a ligature of your own. The color, the size and the variant still apply around it.
Circular bool false Draws the icon in a circle rather than in the rounded box of the design system, squaring the box off at the same time so a narrow glyph and a wide one are drawn in circles of the same size.
Color BitColor? null Specifies the color theme of the icon. Default value is BitColor.Primary.
FixedWidth bool false Renders the icon in a box of a fixed width so that a column of icons of different widths lines up.
Flip BitIconFlip? null Mirrors the icon on the horizontal axis, the vertical axis, or both.
FlipRtl bool false Mirrors the icon horizontally when it is rendered in a right-to-left direction. The direction is read off the rendered document, so it follows an ancestor's dir as well as the component's own Dir.
FontSize string? null Specifies the font size of the icon, as any CSS length or the inherit keyword. Overrides Size when both are given.
Icon BitIconInfo? null Specifies the icon configuration for rendering icons from external icon libraries. Takes precedence over IconName when both name a glyph.
IconName string? null Specifies the name of the icon from the built-in Fluent UI icon library. This property is ignored when Icon names a glyph.
IconResolver Func<string, BitIconInfo?>? null Names the icon set that IconName is a name in - name => BitIconInfo.Fa(name), BitIconInfo.Ms, or a lookup of your own. An Icon that names a glyph still wins over it, and a resolver that answers with null leaves the name to the built-in set. Cascades through BitParams to a whole subtree.
Inline bool false Drops the icon a quarter of an em below the baseline so that an inline svg or an image given as ChildContent sits centered on the line of text it is written in. A glyph of an icon font needs none of it.
OnClick EventCallback<MouseEventArgs> The callback for when the icon is clicked. An icon with a click handler joins the tab order, answers Enter and Space, and is announced as a button - so give it an AriaLabel or a Title.
Rotate BitIconRotate? null Turns the icon by a quarter, a half, or three quarters of a turn.
RotateAngle int? null Turns the icon by an angle of your own, in degrees, negative for counter-clockwise. It replaces Rotate when both are given, and composes with Flip and FlipRtl.
Size BitSize? null Specifies the size of the icon. Default value is BitSize.Medium.
Title string? null The text shown in the native tooltip when the pointer rests on the icon. It also names the icon for assistive technology, so an icon that carries one is announced rather than skipped.
Variant BitVariant? null Specifies the visual styling variant of the icon. Default value is BitVariant.Text.

BitIcon public members

Name Type Default value Description
FocusAsync ValueTask Gives focus to the icon element. Only an icon the browser can focus takes it: one with an OnClick handler, or one given a TabIndex of its own.
FocusAsync(bool preventScroll) ValueTask Gives focus to the icon element, leaving the page scrolled where it is instead of bringing the icon into view.

BitComponentBase parameters

Name Type Default value Description
AriaLabel string? null Gets or sets the accessible label for the component, used by assistive technologies.
Class string? null Gets or sets the CSS class name(s) to apply to the rendered element.
Dir BitDir? null Gets or sets the text directionality for the component's content.
ForceAnimation bool false Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested.
HtmlAttributes Dictionary<string, object> new Dictionary<string, object>() Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters.
Id string? null Gets or sets the unique identifier for the component's root element.
IsEnabled bool true Gets or sets a value indicating whether the component is enabled and can respond to user interaction.
Style string? null Gets or sets the CSS style string to apply to the rendered element.
TabIndex string? null Gets or sets the tab order index for the component when navigating with the keyboard.
Visibility BitVisibility BitVisibility.Visible Gets or sets the visibility state (visible, hidden, or collapsed) of the component.

BitComponentBase public members

Name Type Default value Description
UniqueId Guid Guid.NewGuid() Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed.
RootElement ElementReference Gets the reference to the root HTML element associated with this component.

BitIconInfo properties

Names a glyph for any icon set. A class-based set (Fabric MDL2, FontAwesome, Bootstrap Icons) is described by BaseClass, Prefix and Name; a ligature-based set (Material Icons, Material Symbols) puts the family on BaseClass and the ligature on Content. The static factories build each of them: Bit(name), Fa(icons), Bi(name), Mi(name, style), Ms(name, style), Css(cssClasses), and From(icon, iconName) which resolves an Icon/IconName pair. A plain string converts implicitly and is taken as the complete class list.

Name Type Default value Description
Name string? null The name of the icon. For an external set this can be the complete CSS class list when BaseClass and Prefix are empty.
BaseClass string? null The base CSS class of the icon set - "bit-icon" for the built-in set, "bi" for Bootstrap Icons, "material-symbols-outlined" for Material Symbols. Leave it empty for a set that needs none.
Prefix string? null The CSS class prefix written before the icon name - "bit-icon--" for the built-in set, "bi-" for Bootstrap Icons. Leave it empty for a set that uses none.
Content string? null The text rendered inside the icon element - the ligature of a ligature-based icon set such as Material Icons or Material Symbols. Class-based sets leave it null. Only a component that renders the icon's content puts it on the page, which BitIcon does; the glyphs the library draws inside its other controls are class-based, so a ligature set has to be given to a BitIcon.
IsEmpty bool Whether this instance names no glyph at all - nothing to put in a class attribute, and nothing to write as the element's text. An empty instance is treated as no icon, so an IconName given beside it is still used.

BitColor enum

Name Value Description
Primary 0 Info Primary general color.
Secondary 1 Secondary general color.
Tertiary 2 Tertiary general color.
Info 3 Info general color.
Success 4 Success general color.
Warning 5 Warning general color.
SevereWarning 6 SevereWarning general color.
Error 7 Error general color.
PrimaryBackground 8 Primary background color.
SecondaryBackground 9 Secondary background color.
TertiaryBackground 10 Tertiary background color.
PrimaryForeground 11 Primary foreground color.
SecondaryForeground 12 Secondary foreground color.
TertiaryForeground 13 Tertiary foreground color.
PrimaryBorder 14 Primary border color.
SecondaryBorder 15 Secondary border color.
TertiaryBorder 16 Tertiary border color.

BitSize enum

Name Value Description
Small 0 Display icon using small size.
Medium 1 Display icon using medium size.
Large 2 Display icon using large size.

BitVariant enum

Name Value Description
Fill 0 Fill styled variant.
Outline 1 Outline styled variant.
Text 2 Text styled variant.

BitIconRotate enum

Name Value Description
Rotate90 0 A quarter turn clockwise.
Rotate180 1 A half turn.
Rotate270 2 A quarter turn counter-clockwise.

BitIconFlip enum

Name Value Description
Horizontal 0 Mirrored left to right.
Vertical 1 Mirrored top to bottom.
Both 2 Mirrored on both axes, which is the same as a half turn for an asymmetric glyph.

BitIconAnimation enum

Name Value Description
Spin 0 Turns continuously clockwise - the loading spinner.
SpinReverse 1 Turns continuously counter-clockwise.
Pulse 2 Turns clockwise in eight discrete steps, the way a segmented spinner ticks around.
Beat 3 Scales up and back down, to draw the eye to something that just changed.
Fade 4 Fades out and back in.
Shake 5 Rocks back and forth, for something that needs attention now.
Bounce 6 Jumps up and lands again, squashing on the way out and on the way back - the heaviest of these.
BeatFade 7 Scales up and fades in together, which reads as a slower, softer Beat.

BitVisibility enum

Name Value Description
Visible 0 The content of the component is visible.
Hidden 1 The content of the component is hidden, but the space it takes on the page remains (visibility:hidden).
Collapsed 2 The component is hidden (display:none).

BitDir enum

Name Value Description
Ltr 0 Ltr (left to right) is to be used for languages that are written from the left to the right (like English).
Rtl 1 Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic).
Auto 2 Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element.

Feedback

Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.