How Ratatui Widgets Work
Widgets are lightweight values that describe what to draw. You create them inside terminal.draw() on every frame, configure them with builder methods, and render them into a Rect. Stateful widgets keep selection or scroll data in a separate state value owned by your app. The snippets below are bodies of functions with the signature fn ui(frame: &mut Frame, area: Rect) and compile with these imports:
use ratatui::layout::{Constraint, Rect};
use ratatui::style::{Color, Style, Stylize};
use ratatui::symbols::Marker;
use ratatui::text::Line;
use ratatui::widgets::canvas::{Canvas, Circle, Rectangle};
use ratatui::widgets::*;
use ratatui::Frame;
Block
ContainerDraws borders, titles and padding around an area. Almost every other widget accepts a block through .block(), so borders and titles look consistent everywhere.
let block = Block::bordered()
.border_type(BorderType::Rounded)
.title(" Settings ")
.title_bottom(Line::from(" Esc to close ").right_aligned())
.padding(Padding::horizontal(1));
frame.render_widget(block, area);Paragraph
TextRenders styled Text with alignment, wrapping and scrolling. Use it for help screens, logs, status messages and any block of prose.
let text = vec![
Line::from(vec!["Status: ".into(), "online".green().bold()]),
Line::from("Long lines wrap inside the block when wrapping is enabled."),
];
let paragraph = Paragraph::new(text)
.wrap(Wrap { trim: true })
.block(Block::bordered().title(" Info "));
frame.render_widget(paragraph, area);Table
CollectionDisplays rows and columns with a header, column constraints and an optional highlighted row. Pair it with TableState for selection and scrolling.
let rows = [Row::new(["ratatui", "0.30.2"]), Row::new(["crossterm", "0.29.0"])];
let widths = [Constraint::Fill(1), Constraint::Length(8)];
let table = Table::new(rows, widths)
.header(Row::new(["Crate", "Version"]).bold())
.row_highlight_style(Style::new().reversed())
.block(Block::bordered().title(" Dependencies "));
let mut state = TableState::default().with_selected(0);
frame.render_stateful_widget(table, area, &mut state);List
CollectionA vertical list of items with a highlight symbol for the current selection. Ideal for menus, file pickers and sidebars.
let list = List::new(["Inbox", "Drafts", "Sent"])
.block(Block::bordered().title(" Mail "))
.highlight_style(Style::new().black().on_cyan())
.highlight_symbol("> ");
let mut state = ListState::default().with_selected(Some(0));
frame.render_stateful_widget(list, area, &mut state);Chart
DataPlots one or more datasets as lines or scatter points on numeric axes, with labels and an optional legend.
let points = [(0.0, 1.0), (1.0, 3.0), (2.0, 2.0), (3.0, 5.0)];
let dataset = Dataset::default()
.name("latency")
.marker(Marker::Braille)
.graph_type(GraphType::Line)
.cyan()
.data(&points);
let chart = Chart::new(vec![dataset])
.x_axis(Axis::default().bounds([0.0, 3.0]))
.y_axis(Axis::default().bounds([0.0, 5.0]).labels(["0", "5"]))
.block(Block::bordered().title(" Latency "));
frame.render_widget(chart, area);BarChart
DataDraws vertical or horizontal bars, optionally grouped, with labels and values. Good for comparisons across categories.
let bars = [("Mon", 4), ("Tue", 7), ("Wed", 5)]
.map(|(label, value)| Bar::default().label(label).value(value));
let chart = BarChart::default()
.data(BarGroup::default().bars(&bars))
.bar_width(5)
.bar_gap(1)
.block(Block::bordered().title(" Deploys "));
frame.render_widget(chart, area);Gauge
ProgressA filled bar showing progress as a ratio or percentage with a centered label. LineGauge is a thinner single-line variant.
let gauge = Gauge::default()
.block(Block::bordered().title(" Download "))
.gauge_style(Style::new().green().on_black())
.ratio(0.42)
.label("42% of 120 MB");
frame.render_widget(gauge, area);Tabs
NavigationA row of titles with one selected tab, used to switch between views. Your app stores the selected index and renders the matching content below.
let tabs = Tabs::new(["Overview", "Logs", "Settings"])
.select(1)
.highlight_style(Style::new().yellow().bold())
.divider("|")
.block(Block::bordered());
frame.render_widget(tabs, area);Canvas
DrawingA free-form drawing surface with its own coordinate system. Paint lines, rectangles, circles, points and maps using Braille, block or half-block markers.
let canvas = Canvas::default()
.block(Block::bordered().title(" Canvas "))
.marker(Marker::Braille)
.x_bounds([0.0, 100.0])
.y_bounds([0.0, 50.0])
.paint(|ctx| {
ctx.draw(&Rectangle { x: 10.0, y: 10.0, width: 30.0, height: 20.0, color: Color::Cyan });
ctx.draw(&Circle { x: 70.0, y: 25.0, radius: 12.0, color: Color::Yellow });
});
frame.render_widget(canvas, area);Sparkline
DataA compact bar-based trend line for a single series, perfect for CPU, request rates or latency history inside small panels.
let values: Vec<u64> = vec![3, 5, 2, 8, 6, 9, 4, 7];
let sparkline = Sparkline::default()
.block(Block::bordered().title(" Requests "))
.data(&values)
.style(Style::new().magenta());
frame.render_widget(sparkline, area);Scrollbar
NavigationShows the position within scrollable content. It is stateful: ScrollbarState holds the content length and current position, which you update as the user scrolls.
let lines: Vec<Line> = (1..=50).map(|i| Line::from(format!("line {i}"))).collect();
let position = 10;
frame.render_widget(Paragraph::new(lines).scroll((position as u16, 0)), area);
let mut state = ScrollbarState::new(50).position(position);
frame.render_stateful_widget(
Scrollbar::new(ScrollbarOrientation::VerticalRight),
area,
&mut state,
);Beyond the Built-in Widgets
Ratatui also ships LineGauge, Clear (to erase an area before drawing a popup) and a Monthly calendar behind the widget-calendar feature, which is part of the default all-widgets set. When nothing fits, write your own: see how to create custom widgets. The community publishes many more on crates.io, including text inputs, tree views and image renderers; check that a crate supports your Ratatui version before adding it.