Using web components in MDX
Widely compatibleRendering:Prerendered: WorksOn-demand: WorksAstro>=4.0.0
Works across all listed Astro environments.
If you have a web component defined in a separate JavaScript file, you can include it in your MDX file by importing the script and adding a <script> tag with type="module".
The script will be executed on the client side.
class MyEl extends HTMLElement { ... }customElements.define('my-el', MyEl);Then in your .mdx file you can import it
import webComponent from "./web-component.js?url";
<script src={webComponent} type="module"></script>
<my-el />Compatibility
| Environment | Support | Version |
|---|---|---|
| Framework | ||
| Astro | Works | >=4.0.0 |
| RenderingAstro docs | ||
| Prerendered | Works | Any version |
| On-demand | Works | Any version |
Compatibility legend:Recommended — Best practiceWorks — SupportedDoesn't work — Unsupported