ScriptsApr 15, 2026·3 min read

egui — Easy-to-Use Immediate Mode GUI in Pure Rust That Runs Anywhere

egui is a pure-Rust immediate-mode GUI library that compiles to native, web (WASM), and embedded targets. The Rust ecosystem's answer to Dear ImGui — with a more modern API and first-class WASM support.

TL;DR
egui is a pure-Rust immediate mode GUI library that runs on native, WASM, and embedded targets with a simple API.
§01

What it is

egui is a pure-Rust immediate mode GUI library. Unlike retained mode frameworks where you build a widget tree and the framework manages updates, egui redraws the entire UI every frame. You call functions like ui.button('Click me') and handle the result inline. No widget state management, no callback registration.

egui compiles to native desktop (via eframe), web browsers (via WASM), and embedded targets. It is the Rust ecosystem's answer to Dear ImGui, with a more idiomatic Rust API and first-class WebAssembly support.

§02

How it saves time or tokens

egui's immediate mode API eliminates the complexity of widget lifecycle management. In retained mode frameworks, you create widgets, register callbacks, manage state, and handle updates. In egui, the UI logic is just Rust code that runs every frame. This makes prototyping tools and debug UIs fast.

Cross-platform compilation means one codebase for desktop and web. Write your UI once, compile to native with eframe or to WASM for browser deployment.

§03

How to use

  1. Add egui to your Cargo.toml:
[dependencies]
eframe = "0.28"
  1. Write your UI:
use eframe::egui;

fn main() -> eframe::Result {
    eframe::run_simple_native(
        "My App",
        eframe::NativeOptions::default(),
        move |ctx, _frame| {
            egui::CentralPanel::default().show(ctx, |ui| {
                ui.heading("Hello egui");
                if ui.button("Click me").clicked() {
                    println!("Button clicked");
                }
            });
        },
    )
}
  1. Run with cargo run for native, or compile to WASM with trunk serve for web.
§04

Example

A counter app with slider and label:

use eframe::egui;

struct MyApp {
    counter: i32,
    speed: f32,
}

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            ui.heading(format!("Counter: {}", self.counter));
            if ui.button("+1").clicked() {
                self.counter += 1;
            }
            ui.add(egui::Slider::new(&mut self.speed, 0.0..=10.0).text("Speed"));
        });
    }
}

No widget IDs, no event handlers, no state synchronization. The UI is a function of your data.

§05

Related on TokRepo

§06

Common pitfalls

  • Expecting retained mode patterns. egui redraws every frame. Do not cache widget references or register callbacks. Instead, put your UI logic in the update function and let egui handle rendering.
  • Performance on complex UIs. Immediate mode redraws everything each frame. For UIs with thousands of widgets, use egui's built-in ScrollArea with lazy rendering or profile with puffin.
  • WASM bundle size. A minimal egui WASM app is around 2MB. Use wasm-opt and trunk optimizations to reduce this for production web deployments.

Frequently Asked Questions

What is immediate mode GUI and how is it different from retained mode?+

In immediate mode, you call UI functions every frame and handle results inline. There is no persistent widget tree. In retained mode (Qt, GTK), you create widgets once, register callbacks, and the framework manages updates. Immediate mode is simpler for tools and prototypes but redraws everything each frame.

Can egui build production web applications?+

Yes, for tool-like applications (dashboards, editors, configuration UIs). egui compiles to WebAssembly and runs in the browser via a canvas element. It is not designed for content-heavy websites where HTML/CSS would be more appropriate.

How does egui compare to Dear ImGui?+

Both are immediate mode GUI libraries. Dear ImGui is C++ with bindings for many languages. egui is pure Rust with an idiomatic Rust API. egui has better WASM support and does not require a C++ toolchain. Dear ImGui has a larger ecosystem of widgets and extensions.

Does egui support custom styling and themes?+

Yes. egui provides a Style struct that controls colors, spacing, rounding, and fonts. You can create light/dark themes or fully custom visual styles. The catppuccin-egui crate provides popular color schemes.

What platforms does egui support?+

egui runs on Windows, macOS, Linux (native via eframe), web browsers (via WASM), and embedded targets. The eframe wrapper handles platform-specific windowing and input. For mobile, community support exists but is less mature than desktop.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets