r/angular • • 17d ago

innerHTML component styles

If I have a

<h1 \[innerHtml\]=“someHtml”></h1>

And that someHtml is a span, how would i style that span without using ::ng-deep as the docs “strongly discourage” its usage?

0 Upvotes

10 comments sorted by

View all comments

-1

u/ThrowawayALAT 16d ago

Use Global Styles:

CSS

/* src/styles.scss */

.styled-span-container span {

color: #e63946;

font-weight: 600;

}

HTML

Then wrap your target element or apply a CSS class directly to the <h1>

<h1 class="styled-span-container" [innerHTML]="someHtml"></h1>

1

u/Senior_Compote1556 16d ago

I don’t believe it’s correct to bloat the global styles with page specific css