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.
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 previewTo 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 previewThis is a page
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 previewUse base html!
And if that's still not enough, you can wrap React components from npm and use them too.
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 previewBesides 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 previewGood 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.
| Children | Props | |
|---|---|---|
| What | Text or other components that go inside | Properties that set behavior and appearance |
| How to pass | Positional arguments | Keyword arguments |
| Example | rx.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.
color_scheme="green" and size="3" to round_button.rx.box in my_container padding="16px", border="1px solid #ccc" and border_radius="12px" to turn it into a card.value of rx.progress to CounterState.count from Lesson 1? Make the bar fill up with every button click.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.
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© 2026 ReflexKR · Since 2026 · CC BY-NC 4.0
Questions & answers
Ask anything about this lesson. Questions from every language version of this page appear together.