R

ReflexKR

Reflex Docs

Reflex Basics, Hands-On

·

Course overview

1

Click and it changes: State and events

2

Now you see it: conditional rendering

3

Drawing lists: rx.foreach

4

Why doesn't if work? Compile time vs. runtime

5

Making it look good: components, props and style

6

Apps, pages and a fruit basket

Reflex Basics, Hands-On
Lesson 5

Time 0:28–0:34

Making it look good: components, props and style

So far you've been using components like rx.button, rx.heading and rx.box without giving them much thought. In this lesson, we'll lay out the rules for creating, composing and styling components. There are just two.

5-1. A component is what a function returns (1 min)

A component is a building block of the page, like a button, some text or an image. Reflex ships with plenty of built-in components, and any function that returns a component becomes a component of your own.

def my_button():
    return rx.button("Click Me")

localhost:3000

Live preview
A function that returns a single rx.button is itself a component.

5-2. Rule 1: positional arguments are children (2 min)

To put components inside another component, pass them as positional arguments. Below, rx.text and my_button() are children of rx.box. Components built in other functions go in the same way: just call them.

def my_container():
    return rx.box(
        rx.text("This is a page"),
        # Reference components defined in other functions.
        my_button(),
    )

localhost:3000

Live preview

This is a page

The text and my_button sit inside rx.box, one after the other.

When there's no component for what you need, you can use HTML tags directly with rx.el. rx.el.div is <div>, and rx.el.p is <p>.

def my_div():
    return rx.el.div(
        rx.el.p("Use base html!"),
    )

localhost:3000

Live preview

Use base html!

Plain HTML elements built with rx.el.

And if that's still not enough, you can wrap React components from npm and use them too.

5-3. Rule 2: keyword arguments are props and style (2 min)

You control how a component behaves and looks with keyword arguments, called props. Every component has its own props, so when you use one for the first time, check the docs to see what's available.

def half_filled_progress():
    return rx.progress(value=50)

localhost:3000

Live preview
A progress bar filled halfway with the value=50 prop.

Besides a component's own props, you can also pass CSS properties directly as props to style it.

def round_button():
    return rx.button("Click Me", border_radius="15px", font_size="18px")

localhost:3000

Live preview
A button with its corners and font size changed via border_radius and font_size.

Good to know — Write CSS property names in snake_case: border-radius → border_radius, font-size → font_size. The styling guide covers more options.

To sum up, a component is made of children and props.

ChildrenProps
WhatText or other components that go insideProperties that set behavior and appearance
How to passPositional argumentsKeyword arguments
Examplerx.box(rx.text("hi"), my_button())rx.button("Go", color_scheme="green")

In Lesson 1, when you passed Vars both as children and as props, as in rx.heading(MyState.count, color=MyState.color), you were following exactly these two rules.

Exercises

  1. Add color_scheme="green" and size="3" to round_button.
  2. Give the rx.box in my_container padding="16px", border="1px solid #ccc" and border_radius="12px" to turn it into a card.
  3. What happens if you set the value of rx.progress to CounterState.count from Lesson 1? Make the bar fill up with every button click.

Checkpoint

  • You can say what positional and keyword arguments each become.
  • You can rewrite CSS properties as snake_case props.
  • You can reach for rx.el when the component you need doesn't exist.

← Previous

Lesson 4 · Why doesn't if work? Compile time vs. runtime

Next →

Lesson 6 · Apps, pages and a fruit basket

Get news about new lessons

We'll email you when this course gets new lessons or a follow-up course opens.

We collect: your email address · Purpose: news about new lessons or the launch of this course · Kept until: you ask us to remove it. We never use it for anything else or share it. Reply to any notice email and we'll delete it right away.

Questions & answers

Ask anything about this lesson. Questions from every language version of this page appear together.

Shown as plain text, without links or formatting.

R

ReflexKR

Learn Python and Reflex by doing. Every example was run and verified on Reflex 0.10.0.

ReflexKR is free, with no banner ads. If it helped you, you can support it with a coffee. ☕ Buy us a coffee

Affiliate disclosure
한국어English日本語简体中文EspañolDeutsch

© 2026 ReflexKR · Since 2026 · CC BY-NC 4.0

Built with Reflex