What is the Children Prop?
You'll learn what makes children special in React and how it lets you pass JSX content between component tags.
The Special Prop You Get for Free
The children prop is a special prop that React automatically provides to every component. Unlike props you explicitly pass with the name={value} syntax, children receives whatever JSX content you place between a component's opening and closing tags.
Think of it like a sandwich: the component's opening and closing tags are the bread, and whatever you put between them is the filling—that filling becomes the children prop.
How It Works
When you write this:
<Card>
<h2>Welcome</h2>
<p>This is the content inside.</p>
</Card>
The Card component automatically receives those two elements as its children prop:
function Card(props) {
return (
<div className="card">
{props.children}
</div>
);
}
With destructuring (which you just learned about):
function Card({ children }) {
return (
<div className="card">
{children}
</div>
);
}
The children prop can be anything: text, a single element, multiple elements, or even nothing at all. React bundles whatever is between the tags and hands it to your component.
Why This Matters
The children prop enables component composition—wrapping components around content without needing to know what that content is. A Card component doesn't care what you put inside it; it just provides the card styling and structure.
Key Takeaway: The children prop is React's automatic way of passing JSX content placed between a component's opening and closing tags, enabling powerful composition patterns.