Skip to main content

Code

Function Code 

Source
pub fn Code(props: CodeProps) -> impl IntoView
Expand description

Monospace code block for CLI commands, API identifiers, and short config samples.

Pass text for plain content. Pass inner_html only when you control the markup (for example pre-highlighted output from a trusted highlighter) — do not pass unsanitized user input to inner_html.

§When to use

  • Single-line or multi-line code snippets in docs and settings panels - Inline monospace copy inside prose (wrap in a short text value)

§Examples

§Code snippet

A plain code block with a distinct code surface color from the theme.

view! {
    <div data-testid="code-preview">
        <Code text="cargo leptos watch".to_string() />
    </div>
}

§Multi-line block

Multi-line plain text for shell commands or config samples.

view! {
    <div data-testid="code-multiline">
        <Code text="cargo leptos build --release\ncargo leptos serve".to_string() />
    </div>
}

§Optional Props