Skip to content

Buttons ​

Live demo
Every ButtonVariant plus a disabled primary button and three icon buttons.Open in a tab ↗

Button ​

rust
use egui_workbench::components::prelude::*;

if Button::new("Save").variant(ButtonVariant::Primary).show(ui).clicked() {
    save();
}

Button::new("Cancel").variant(ButtonVariant::Ghost).show(ui);
Button::new("Delete").variant(ButtonVariant::Destructive).show(ui);
Button::new("Documentation").variant(ButtonVariant::Link).show(ui);

Variants ​

VariantFillBorderText
Primary (default)Selection tokenNoneSelection text token
SecondaryInactive widget fill1 ptPrimary text
OutlineTransparent1 ptPrimary text
GhostTransparent; hover fill onlyNonePrimary text
DestructiveDanger tokenNoneWhite or black, whichever reads better
LinkTransparentNoneHyperlink token

selected(true) paints the selection fill and text regardless of the variant. A ghost button keeps its padding but shows no frame until hover.

API ​

APITypeDefaultDescription
Button::new(label)ButtonPrimary, MdA primary button at the default size.
.variant(v)ButtonVariantPrimaryVisual role.
.size(s)SizeMdSm = 24 pt, Md = 30 pt, Lg = 36 pt.
.enabled(bool)booltrueDisabled buttons are faded and never report clicks.
.selected(bool)boolfalsePaint as a selected toggle.
.width(pt)f32Size::min_widthMinimum width in points.
.tooltip(text)&strNoneHover text and accessible description.
.fill(color)Color32Variant fillOverride the background.
.text_color(color)Color32Variant textOverride the label color.
.stroke(stroke)StrokeVariant strokeOverride the border; Stroke::NONE removes it.
.radius(r)u8Style control radiusOverride the corner radius.
.show(ui)Response—Paint and return the egui response.

IconButton ​

An icon-only button is named by its tooltip in AccessKit. The glyph comes from the shared Icons cache.

rust
if IconButton::new("save", "Save").show(ui, &mut icons).clicked() {
    save();
}

IconButton::new("sidebar", "Explorer")
    .active(self.sidebar)
    .show(ui, &mut icons);

IconButton::new("close", "Close tab")
    .size(IconButtonSize::Tool)
    .show(ui, &mut icons);
SizeSideGlyphTypical use
Action (default)28 pt16 ptTitle-bar actions
Tool26 pt18 ptTab strip and toolbars
Small21 pt16 ptExplorer and card headers

active(true) paints the toggled fill; on Action size it also draws the title-bar underline. open(true) keeps a popup button lit while its popup is open. color tints the glyph; radius overrides the hover-fill radius.

APITypeDefaultDescription
IconButton::new(icon, tooltip)IconButtonActionAn icon button; the tooltip is the accessible name and hover text.
.size(s)IconButtonSizeAction28, 26, or 21 pt side.
.active(bool)boolfalseToggled fill (and title-bar underline).
.open(bool)boolfalseLit while a popup is open.
.enabled(bool)booltrueFaded and inert when false.
.color(color)Color32Text colorTint the glyph.
.radius(r)u8Style item radiusOverride the hover-fill radius.
.show(ui, icons)Response—Paint and return the response.

CloseButton ​

A borderless × for dialog headers and custom panels. It returns bool, not a Response.

rust
if CloseButton::new("Close").size(14.0).show(ui) {
    open = false;
}

Accessibility ​

  • Text buttons expose Role::Button and their label.
  • Icon buttons expose Role::Button and their tooltip; the glyph itself is decorative.
  • Selected buttons announce the selected state.
  • Disabled buttons are faded and ignored by pointer and keyboard input.

Common mistakes ​

  • No tooltip on an icon button. The AccessKit name comes from it, and kittest fails tests when it is missing.
  • A raw ui.button. It bypasses the style's density, radius, and variant tokens.
  • Hard-coded width for a label that can grow. Let the button measure its text, or set a minimum width and let it wrap in horizontal_wrapped.

Released under MIT OR Apache-2.0. Icons: Lucide (ISC) and Material Icon Theme (MIT).