Open
Labels
area: coreIssues related to the framework runtimecore: host and host bindingsfeatureLabel used to distinguish feature request from other issuesfeature: under considerationFeature request for which voting has completed and the request is now under consideration
Milestone
Description
I'm submitting a...
[ ] Regression
[ ] Bug report
[X] Feature request
[ ] Documentation issue or request
[ ] Support request
Current behavior
Component-containers like <app-root>, <app-hero-list>, etc. do break flex layout.
Expected behavior
A component(or whole module) should have the option to create no html-element. Instead Angular should work with comments instead of html-elements, exactly like ng-container.
Minimal reproduction of the problem with instructions
<html style="width: 100%; height: 100%;">
<body style="width: 100%; height: 100%; display: flex; flex-direction: column;">
<app-root>
<div style="flex: 1; background: lightcoral;">I should have full height!</div>
</app-root>
</body>
</html>
Plunker: https://plnkr.co/edit/aOWUciRx2EsRsKwL2zma?p=preview
(Uncomment app-root in styles.css to see currently needed fix)
What is the motivation / use case for changing the behavior?
Using display:flex only affects the child-element which gets broken by any <app-component> tag. To apply the example above with multiple nested components to require ugly, hardcoded stylesheets:
body,
app-root,
app-hero,
app-hero-list,
app-hero-detail {
display: flex;
flex-direction: column;
}
Also, as a frontend developer, i don't like the <app-component> tags either :D
Environment
Angular version: 4.x.x / 5.x.xReacted by Daniel Macák, xp44mm, Sz. Kristóf, Brian Hardy, Yohan Lasorsa, PaulKujawa, Tsvetomir Tsonev, markoh, Acker Dawn Apple, Joost Koehoorn and 270 more
Reacted by Maurizio Cescon
Reacted by Sergiu Bologa, Salathiel Genese, Kyle Cordes, Klemen Oslaj, Mario Gruda, Krzysztof Platis, Sam Claus, Sina Aghajani, Sean Lee, kang king and 4 more
Reacted by Maurizio Cescon
Reacted by Roman K., Salathiel Genese, Klemen Oslaj, Mario Gruda, Sam Claus, Sina Aghajani, Sean Lee, kang king, Alexandre Giard, why520crazy and 2 more
Metadata
Metadata
Assignees
Labels
area: coreIssues related to the framework runtimecore: host and host bindingsfeatureLabel used to distinguish feature request from other issuesfeature: under considerationFeature request for which voting has completed and the request is now under consideration
Activity
ericmartinezr commentedon Aug 25, 2017
Would this https://github.com/angular/flex-layout fix your issue? *
MickL commentedon Aug 25, 2017
This is a totally different framework. I just want to not break the cascade. If i would create the app with plain html an js there would be no unnecessary containers, too.
mlc-mlapis commentedon Aug 25, 2017
@MickL ...
<ng-container>and<ng-template>work with comments. Also attribute components likemy-columnsin<tr my-columns></tr>.If I understand you suggest to Angular does the same for any place, any component, ... and so on.
trotyl commentedon Aug 25, 2017
It would be impossible to keep consistency between
ViewEncapsulation.NativeandViewEncapsulation.Emulated, since comment cannot have shadow root.MickL commentedon Aug 25, 2017
At least :host would not work anymore. Styles could be generated into global css instead.
@mlc-mlapis Im not sure if you understand me right. I wish for replacing component-containers like
<app-name>name works!</app-name>with<!--<app-name>-->name works!<!--</app-name>-->to create no dom-element for the component itself.mlc-mlapis commentedon Aug 25, 2017
@MickL ... yes, I understand what you want, just wanted to be sure. You came probably from another world ...
:hostwould not work, ... all is moving from global scope to an encapsulated form (Emulated or Native) and you go opposite? And also replacing component-containers ... when general custom components concept is under heavy development?MickL commentedon Aug 25, 2017
I do work with Angular a lot and like css encapsulation. It was just an idea to make non-visible-component-containers possible because they disturb. If shadow dom is not possible with comment-containers then screw it, comment-containers may be more important because css will not work correctly anyway.
MickL commentedon Aug 29, 2017
The expected behavior is exactly the same as
ng-containerstaeke commentedon Nov 30, 2017
With a solution to this, I believe you're right @mlc-mlapis -
:hostand Shadow DOM could probably not work. However, when you want something like this - I guess you don't care about Shadow DOM, and:hostshouldn't really apply either. You want HTML "tightness" when, in fact, components produce html that belongs to the same "css system".I guess the case that seems hard (impossible?) to accomplish with angular is
EDIT:
One way to do it is
mlc-mlapis commentedon Nov 30, 2017
@staeke ... and what about to use attribute components like:
staeke commentedon Nov 30, 2017
Well @mlc-mlapis, you’d get trs within trs
mlc-mlapis commentedon Nov 30, 2017
@staeke ... ah, I thought about it from a wrong side. My mistake.
smnbbrv commentedon Jan 7, 2018
@staeke does not work as is for me because the OnInit does not capture the templateRef. However adding a hash-variable on ng-template + reading it by name works fine:
104 remaining items
hungtcs commentedon Sep 25, 2025
I believe the host element is actually part of Angular’s charm. It makes an Angular component look like a real element rather than just a piece of template logic. Many important Angular features are also tied to the host element.
So far, I haven’t seen any functionality that truly requires removing the host element in order to be achieved.
You can always use the :host selector to style the wrapper directly, instead of repeatedly defining a custom wrapper element inside the component.
leoncik commentedon Sep 25, 2025
There are valid cases where the host element becomes more of a liability than a feature:
Invalid or broken semantics
In certain elements (like
<table>,<tr>,<ul>,<select>), inserting a wrapper tag results in HTML that’s technically invalid.Browsers usually try to “fix” this automatically, but it can cause cross-browser quirks, accessibility issues, or break expectations for assistive technologies.
Debugging & maintainability
Wrapping elements makes the DOM harder to read.
Consider this simple custom table:
The same table without extra-markup (and attributes) should be rendered like that:
Styling issues
In many scenarios, adding extra wrapping elements when they are not needed can make styling more difficult. You may for example have to drill through twice as many elements when you want to set an element to have a 100% height or apply inheritance rules with subgrid.
Performance & rendering overhead
Every extra wrapper is an extra DOM node: more memory consumption, more work for the browser when calculating layout, style, and paint.
On large tables or deeply nested components, the accumulated overhead can be significant, especially on mobile devices.
Now, on the suggestions about this issue:
Option 1: curly braces
By default, all Angular components should be rendered without the selector tag wrapper. An option could be provided as fallback for backward compatibility, like adding curly braces in the
selectorto display the wrapping tag:Option 2: Host configuration
For the other way around, (an opt-in mechanism to render a component without its host wrapper), Angular could extend the host configuration:
Option 3: New encapsulation mode
Another possibility would be to introduce a new ViewEncapsulation option, e.g. Hostless, that indicates Angular should not render a host wrapper for this component:
hungtcs commentedon Sep 25, 2025
Actually https://material.angular.dev/components/table/overview has provided a good solution, the angular component supports multiple types of selectors.
leoncik commentedon Sep 25, 2025
You are referring to attribute selector, right? They do indeed remove the wrapping tag but this causes a styling issue: the styling can no longer be encapsulated inside the component, part of the styles must be moved to the parent component.
In your example, the styles of the cell can’t be set in the
TableCellComponent, they have to be moved up to theAppcomponent, which is not viable to create a reusable component.davidbusuttil commentedon Sep 25, 2025
You could in theory do element tag + class name: "[p.paragraph]" as an example. Any
<p class="paragraph"></p>would be a valid component. But this approach has a huge pitfall: namespaces.If you try this approach with an SVG element, the children (paths, etc) would not be rendered properly as the namespace for this would be http://www.w3.org/2000/svg.
davidbusuttil commentedon Sep 25, 2025
There is a very valid use case: CMS based on JSON. Nuxt.js offers a CMS based on Markdown. I have managed to build one using Angular, however, I had to resort to ViewContainerRef's createComponent using HTML element tag + class names as selectors. The big caveat was with SVG elements, as the createComponent thereof does not allow to specify the name space of the created Angular element.
mauriziocescon commentedon Sep 25, 2025
I'm so happy this point is back on the agenda: hooray! 🎉🥁🔝
That said, to me the most difficult part is defining common ground around the meaning of "hostless components," which for me is not limited to "avoiding extra HTML tags", "tailwind class conflicts" etc. (all absolutely legitimate). As I see it, hostless components also imply fixing the following problems:
These points make "template composition" like in React / Vue / Svelte impossible in Angular today (for reference, see #54782 (comment)).
As a consequence, directives (of any nature) are the primary "template composition" tool. But they are complex to use, specific to Angular, and introduce mental overhead along with other problems. As I see it, hostless components would more or less fix the entire template composition issue and align Angular with the industry. Attribute directives would then have a more scoped role.
There's no disagreement that this would be a huge (and multiyear) change compared to the current way of doing things. But I think it's the right move, because it would make Angular templates fully declarative, compositional, and inputs-driven without compromises. And improve type safety.
Conclusion
I really hope hostless components will be considered in the near future. But as I see it, "hostless" doesn't just mean introducing a component flag for host (yes / no). It has profound implications for:
Cheers!
☮️☮️☮️
hungtcs commentedon Sep 26, 2025
Setting styles inside the component is completely fine.
davidbusuttil commentedon Dec 22, 2025
Hello!
I suggest this way forward:
hostlessfor migration;<ng-fragment>&</ng-fragment>to encapsulate the view - however, this poses a problem for CSS encapsulation as comments do not allow this, although the root nodes could all share the same host ID and share the CSS styling.davidbusuttil commentedon Dec 22, 2025
Nevermind - saw that selectorless components are on the road map - me likey. Waiting for the RFC as I've got tonnes of input!
R-Bower commentedon Apr 3, 2026
They were, but they've recently been removed.
It was the first item on the v20 docs
But it's no where to be found on the v21 (current) or next roadmap
davidbusuttil commentedon Apr 3, 2026
dwilches commentedon Apr 3, 2026
@R-Bower @davidbusuttil I know this is not a full replacement, but you can add this to your component, so its tag doesn't get in the way of CSS styles:
davidbusuttil commentedon Apr 3, 2026
The problem is the selector itself. Cannot build a proper dynamic UI library. Also bear in mind correct HTML syntax.
❌
You may mention to use selectors such as
[uiList], but that breaks when usingViewContainerRef.createComponent(), with an<ng-component>being inserted.I will miss Angular.
mauriziocescon commentedon Sep 25, 2026
At a high level, I think this is more or less what I'd like a selectorless / hostless implementation to look like:
<MyComp @MyDir(...) />),ng-container(or something similar in spirit likeng-host),@ifor any other control flow, and it takes over the role of the host for all the host machinery (:host {},host: {},hostDirectives: [],@HostBinding,providers: [], ...),<MyComp --my-background="color()" />),classandstyleon element tags (as opposed to components) behave as they do today: they accept the sugared forms ([class.foo],[style.width], ...), including multiple bindings on the same tag.Here are a few examples to better visualize the idea:
Pros
template: {{ computation() }},ng-containerhost components naturally "reject" directives coming from outside the boundary that expect a real element tag (rootElement: trueworks as a voluntary opt-in),Cons
<MatButton:a ...>...</MatButton:a>),Buttoncannot target both abuttonand anatag at the same time (although there are ways to achieve it, seesvelte:element),FormField, for example),Cheers!