pub fn Code(props: CodeProps) -> impl IntoViewExpand 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
textvalue)
§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
- class:
impl Into<MaybeProp<String>>- Extra CSS class names merged onto the root
<code>element.
- Extra CSS class names merged onto the root
- text:
impl Into<String>- Plain-text snippet rendered inside
<pre>.
- Plain-text snippet rendered inside
- inner_html:
impl Into<String>- Pre-rendered markup for syntax highlighting; takes precedence over
text.
- Pre-rendered markup for syntax highlighting; takes precedence over