The CDN build does not include decorators. Use the static properties getter or static styles instead when working without a build step and TypeScript decorator support.
Alternatively, import Lit directly by URL without an import map:
my-element.js
import { LitElement, html, css,} from 'https://unpkg.com/lit@3/index.js?module';
Importing by URL without an import map can result in multiple copies of Lit being loaded if different packages resolve to different URLs. Prefer import maps in production.
Lit is written in TypeScript and ships type definitions. No additional @types packages are required.
useDefineForClassFields must be false. When set to true, class field declarations override the property accessor that Lit installs via @property, breaking reactivity.
experimentalDecorators: true enables the TypeScript decorator syntax. Lit’s decorators are compatible with TypeScript’s legacy decorator implementation (stage 2).
If you need to support older browsers (e.g., legacy Edge or IE 11 is not supported), load the Web Components polyfills before your components.
npm install @webcomponents/webcomponentsjs
index.html
<!doctype html><html lang="en"> <head> <!-- Load polyfills before any web component scripts --> <script src="node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script> <!-- Then load Lit's polyfill support module --> <script type="module"> import 'lit/polyfill-support.js'; </script> <script type="module" src="./my-element.js"></script> </head> <body> <my-element></my-element> </body></html>
The webcomponents-loader.js script detects which polyfills are needed and loads only those, minimizing the payload for browsers that already have native support.
You must also import lit/polyfill-support.js to patch Lit’s rendering pipeline to work correctly with the polyfilled custom elements and shadow DOM implementations.