Using components
Questi contenuti non sono ancora disponibili nella tua lingua.
Components let you easily reuse a piece of UI or styling consistently. Examples might include a link card or a YouTube embed. Starlight supports the use of components in MDX files and provides some common components for you to use.
Learn more about building components in the Astro Docs.
Using a component
You can use a component by importing it into your MDX file and then rendering it as a JSX tag.
These look like HTML tags but start with an uppercase letter matching the name in your import
statement:
Because Starlight is powered by Astro, you can add support for components built with any supported UI framework (React, Preact, Svelte, Vue, Solid, Lit, and Alpine) in your MDX files. Learn more about using components in MDX in the Astro docs.
Built-in components
Starlight provides some built-in components for common documentation use cases.
These components are available from the @astrojs/starlight/components
package.
See the components group in the sidebar for a list of available components and how to use them.
Compatibility with Starlight’s styles
Starlight applies default styling to your Markdown content, for example adding margin between elements.
If these styles conflict with your component’s appearance, set the not-content
class on your component to disable them.
Component props
Use the ComponentProps
type from astro/types
to reference the Props
accepted by a component even if they are not exported by the component.
The following example uses ComponentProps
to reference the props accepted by a Callout
component: