Early developmentPre-1.0: syntax may change.Release historyGitHub

Rune-Web guide

Views and selection bindings

Switch between a trip summary and itinerary using state, match and small components. This is a view switch inside one page.

i18n.Guide.syntax

bindings: .active <-> tab connects a selector to selection state. A button with .active when 'schedule' gets an active class and assigns tab on click.

match tab: chooses which component to render. This selection does not create URL routes, browser history or a full accessible tab widget; the demo uses ordinary navigation buttons.

Choose Schedule, then Summary. Notice the active button and content change together without reloading the page.

Run this lesson locally

cargo run -- examples/rune-web/guide/navigation.rune
cargo run -- examples/rune-web/guide/navigation.rune -o html > index.html

Each example is a complete Rune-Web app and imports parts/style.rune. Open the source below to inspect both files. Demo data stays in this browser and resets when the preview reloads.

Live Rune-Web app

Views and selection bindings

This preview is compiled from the actual Rune example, including its styles and actions. Interact with the app, then explore its source files.

View source code
navigation.rune
#!RUNE
# A selection binding supplies both the active class and click assignment.
import "parts/style.rune"
@App
name = Trip planner
type = REST
@Frontend
type = rune-web
path = %ROOT%
page = trip
@Component/TripSummary
view:
    section .panel:
        h2 "A weekend by the coast"
        p "Walk the shore, visit the market, and leave time for coffee."
@Component/TripSchedule
view:
    section .panel:
        h2 "A simple itinerary"
        ul:
            li "Saturday: harbor walk and market"
            li "Sunday: lighthouse trail and lunch"
@Page/trip
title = Trip planner
style = guide
state:
    tab = "summary"
bindings:
    .active <-> tab
view:
    main:
        h1 "Plan a small adventure"
        nav .choices aria-label="Trip sections":
            button {.active when 'summary'} "Summary"
            button {.active when 'schedule'} "Schedule"
        match tab:
            "summary" -> TripSummary
            "schedule" -> TripSchedule
parts/style.rune
@Style/guide
tokens:
    brand = #166b73
    ink = #143841
    surface = #ffffff
    space = 1rem
presets:
    panel:
        background = {surface}
        border = 1px solid #c7e2e4
        border-radius = 16px
        padding = {space}
rules:
    body:
        margin = 0
        font-family = system-ui, sans-serif
        color = {ink}
        background = #edf7f7
    main:
        max-width = 900px
        margin = 0 auto
        padding = 1rem
    .grid:
        display = grid
        grid-template-columns = repeat(auto-fit, minmax(min(100%, 220px), 1fr))
        gap = {space}
    .panel:
        use = (panel)
        margin-bottom = 1rem
    .choices:
        display = flex
        flex-wrap = wrap
        gap = 0.5rem
        margin-bottom = 1rem
    button:
        padding = 0.75rem 1rem
        background = {brand}
        color = white
        border = 0
        border-radius = 8px
        cursor = pointer
        font = inherit
    button:focus-visible:
        outline = 3px solid #d56c45
        outline-offset = 3px
    button.active:
        background = #a94022
    input, select:
        display = block
        box-sizing = border-box
        width = 100%
        padding = 0.75rem
        margin = 0.5rem 0 1rem
        font = inherit
        border = 1px solid #8baeb3
        border-radius = 8px
    .muted:
        color = #44646b
    .done:
        text-decoration = line-through
    h1:
        font-size = clamp(1.5rem, 5vw, 2.2rem)
    p, li:
        line-height = 1.6
Built entirely with Rune-Web