Auto-embed URLs in MDX
The astro-oembed-integration package automatically converts standalone oEmbed URLs in
your MDX files into <Oembed> components at build time — no manual imports required.
Installation
Section titled “Installation”npm install astro-oembed astro-oembed-integrationpnpm add astro-oembed astro-oembed-integrationyarn add astro-oembed astro-oembed-integrationAdd the integration to your astro.config.mjs before @astrojs/mdx (or before Starlight,
which registers MDX internally):
import { defineConfig } from 'astro/config';import oembed from 'astro-oembed-integration';import mdx from '@astrojs/mdx';
export default defineConfig({ integrations: [ ...oembed(), mdx(), ],});With the integration enabled, any standalone oEmbed URL on its own line in an .mdx file is
automatically converted to an <Oembed> component. No import needed.
For example, this MDX will render a YouTube embed in place of the bare URL:
# My post
Here is an embedded Bluesky post:
https://bsky.app/profile/astro.build/post/3mlbttjkvzi2w
Here is an embedded YouTube video:
https://youtu.be/0mKNSwi7Wvk?t=39Only URLs on their own line — forming a standalone paragraph with no surrounding text — are transformed. A URL embedded within a sentence will not be processed.
A URL is also only converted when it matches a known oEmbed provider in the bundled provider list. Unrecognised URLs remain as plain links.
Live example
Section titled “Live example”The above code example will render as the following in your Astro page:
Here is an embedded Bluesky post:
Here is an embedded YouTube video:
