Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MislavNovalic's avatar

Livewire only supports one HTML element per component. Multiple root elements detected for component:[greet

Hi. I am following video "Livewire from scratch" and when I add second element in greeter.blade.php I get this error in the title. What can be the issue ?

0 likes
11 replies
LaryAI's avatar
Level 58

The error you're encountering is due to Livewire's requirement that each component must have a single root HTML element. This means that your greet.blade.php file should wrap all its content within a single parent element.

Here's how you can resolve the issue:

  1. Ensure that all your HTML content in greet.blade.php is wrapped in a single root element, such as a <div>, <section>, or any other suitable HTML element.

For example, if your current greet.blade.php looks like this:

<h1>Hello, World!</h1>
<p>Welcome to Livewire.</p>

You should wrap it in a single root element like this:

<div>
    <h1>Hello, World!</h1>
    <p>Welcome to Livewire.</p>
</div>

By doing this, you ensure that Livewire can properly manage the component's lifecycle and updates, as it expects a single root element to work with. This should resolve the error you're seeing.

1 like
vincent15000's avatar

You can only have one unique root element for a component.

If you need more root element, you have to create a unique root element and write your elements inside it.

Instead of this ...

<div>
	...
</div>

<div>
	...
</div>

... you need to write this.

<div>
	<div>
		...
	</div>

	<div>
		...
	</div>
</div>
1 like
Tray2's avatar
Tray2
Best Answer
Level 73

As @vincent15000 says you need to wrap the elements with a single element, however you should consider using something other than a div, div is what you would use pre html5, but in html5 there are elements better suited for creating your page/component structures.

  • section
  • article
  • header
  • footer
  • aside
  • main
  • nav

are just a few of the semantic structure tags that was introduced in html5.

https://www.w3schools.com/html/html5_semantic_elements.asp

2 likes
vincent15000's avatar

@Tray2 I just used div to give an example of wrapping ;) ... but sure semantic tags are better suited.

Tray2's avatar

@vincent15000 I know, I would likely have done the same, but I wanted to point out that there are other options.

1 like
Snapey's avatar

@MislavNovalic select the answer that helped most. Hover over the comment and a button appears. A comment selected as best answer marks the question as solved.

1 like

Please or to participate in this conversation.