Styling Polymer Templates

Note
Use Lit templates instead
Lit templates are recommended. Polymer templates are available in the next long term supported Vaadin version (LTS), but they are deprecated.

Since Polymer 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 <style> tag in the template getter.

my-view.js

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