On the lwc lifecycle hook the documentation reads

The constructor() method fires when a component instance is created. Don’t add attributes to the host element during construction. You can add attributes to the host element in any other lifecycle hook.

What does host element mean here? sorce

1 Answer 1


The host element is the Custom Element that is attached to the browser's DOM in order for your component to be rendered. You can think of this as an input or div type element, except that is a custom Web Component. When you use its attributes, such as classList, the browser understands those properties as they would be in an HTMLElement (e.g. modifying classList updates the element's CSS classes, which in turn can cause the component to be rendered differently). You cannot access these attributes in the constructor phase, as the underlying Custom Element doesn't exist yet.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .