Styling Templates

Since client-side templates are Web Components, their content is inside shadow DOM. By design, shadow DOM defines a local style scope that is isolated from global styles. See Style Scopes for more information.

You can add component-specific scoped styles directly in the static styles template property.

my-view.ts

  1. import {LitElement, html, css} from 'lit-element';
  2. class MyView extends LitElement {
  3. static get styles() {
  4. return css`
  5. :host {
  6. /* Styles for the <my-view> host element */
  7. display: block;
  8. }
  9. .my-view-title {
  10. font-weight: bold;
  11. border-bottom: 1px solid gray;
  12. }
  13. `;
  14. }
  15. render() {
  16. return html`
  17. <h2 class="my-view-title">My view title</h2>
  18. `;
  19. }
  20. }
  21. customElements.define('my-view', MyView);