concept Shadow DOM in category aurelia

This is an excerpt from Manning's book Aurelia in Action.
Including the styles in this way works well if you don’t mind your styles being applied to the entire Aurelia application (the default behavior for referenced CSS files). But what if you wanted to create a component (such as an email sign-up widget) that would be styled in its own way, with the styles outside of the component not leaking into it and vice versa? In Aurelia, you can achieve this using an exciting feature called scoped CSS resources. Scoped CSS resources inject your CSS into the Shadow DOM (a new feature available as a part of the Web Components Specification). CSS injected into the Shadow DOM is only applied to the contents of the shadow root element (the root node of a Shadow DOM tree) for the component. We’ll delve into scoped CSS resources in chapter 12. Now that you’ve included these CSS resources, modify each of the views to make use of these styles.
The Shadow DOM is useful for creating encapsulated components that are easily transferable between different Aurelia projects. In this section, you’ll create a templated Bootstrap 4 card component with slots for the header, an image, content, and a footer. You’ll then create a share-book-card component that will use the ux-card, injecting book-specific content (such as the book-cover image, title, and description) into slots defined by the ux-card component. To indicate that these are reusable components, prefix them with a ux- dash and place them in a new /components directory. By the end of this section, users will be able to share books by clicking the Share button on a specific book row, as shown in figure 12.2.
Aurelia provides four key features that allow you to use the Shadow DOM in your projects: the CSS as="scoped" require option, the @useShadowDOM decorator, Shadow DOM slots, and layouts. In this section, we’ll review the kinds of problems that each of these features helps to solve. In the next section, you’ll apply what you’ve learned to introduce a reusable ux-card component to the my-books application.