> Markdown version of [Styling](https://vaadin.com/docs/latest/it/flow/component-internals/templates/styling-templates). Section index: [llms.txt](https://vaadin.com/docs/latest/it/flow/llms.txt)

# Styling Templates

Poiché i template lato client sono Web Components, il loro contenuto si trova all’interno dello shadow DOM. Per progettazione, lo shadow DOM definisce un ambito di stile locale che è isolato dagli stili globali. Vedere [Shadow DOM Styling](https://vaadin.com/docs/latest/it/styling/advanced/shadow-dom-styling.md) per ulteriori informazioni.

È possibile aggiungere stili con ambito specifico del componente direttamente nella proprietà template statica `styles`.

`my-view.ts`

```javascript
import { css, html, LitElement } from 'lit';

class MyView extends LitElement {

  static get styles() {
    return css`
      :host {
        /* Styles for the <my-view> host element */
        display: block;
      }

      .my-view-title {
        font-weight: bold;
        border-bottom: 1px solid gray;
      }
    `;
  }

  render() {
    return html`
      <h2 class="my-view-title">My view title</h2>
    `;
  }
}

customElements.define('my-view', MyView);
```

Per fare in modo che il vostro [Application Theme](https://vaadin.com/docs/latest/it/styling/application-theme.md) venga applicato all’interno di un template lato client, utilizzare la funzione di utilità `applyTheme()`, come segue:

`my-view.ts`

```javascript
import { css, html, LitElement } from 'lit';
// tag::snippet[]
import { applyTheme } from 'Frontend/generated/theme';
// end::snippet[]

class MyView extends LitElement {

  // tag::snippet[]
  protected override createRenderRoot() {
    const root = super.createRenderRoot();
    applyTheme(root);
    return root;
  }
  // end::snippet[]

  render() {
    return html`
      <h2 class="my-view-title">My view title</h2>
    `;
  }
}

customElements.define('my-view', MyView);
```

Se si desidera evitare di usare lo shadow DOM nel vostro template, crearlo invece in questo modo:

```typescript
import { css, html, LitElement } from 'lit';

class MyView extends LitElement {
  // tag::snippet[]
  protected override createRenderRoot() {
    return this;
  }
  // end::snippet[]

  render() {
    return html`
      <h2 class="my-view-title">My view title</h2>
    `;
  }
}

customElements.define('my-view', MyView);
```

Un template senza shadow DOM consente al tema dell’applicazione di influenzare gli elementi all’interno del template.

`42AE001F-6D1F-456E-B072-27B883C19920`
