Reflex Logo

Intro

Gallery

Hosting

Components

New

Learn

Components

API Reference

Onboarding

Library

/

Datadisplay

/

Codeblock

The CodeBlock component can be used to display code easily within a website. Put in a multiline string with the correct spacing and specify and language to show the desired code.

1
2
3
4
5
def fib(n):
    if n <= 1:
        return n
    else:
        return(fib(n-1) + fib(n-2))
rx.code_block(
    """def fib(n):
    if n <= 1:
        return n
    else:
        return(fib(n-1) + fib(n-2))""",
    language="python",
    show_line_numbers=True,
)

A code block.

PropTypeDescriptionValues
themeLiteral

The theme to use ("light" or "dark").

languageLiteral

The language to use.

codestr

The code to display.

show_line_numbersbool

If this is enabled line numbers will be shown next to the code block.

starting_line_numberint

The starting line number to use.

wrap_long_linesbool

Whether to wrap long lines.

custom_styleDict

A custom style for the code block.

code_tag_propsDict

Props passed down to the code tag.

Event Triggers

No component specific event triggers

← CalloutDataEditor →

Did you find this useful?