Check this out
Components
Dette indhold er ikke tilgængeligt i dit sprog endnu.
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.
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.
Built-in components
Starlight provides some built-in components for common documentation use cases.
These components are available from the @astrojs/starlight/components
package.
Tabs
You can display a tabbed interface using the <Tabs>
and <TabItem>
components.
Each <TabItem>
must have a label
to display to users.
The code above generates the following tabs on the page:
Cards
You can display content in a box matching Starlight’s styles using the <Card>
component.
Wrap multiple cards in the <CardGrid>
component to display cards side-by-side when there’s enough space.
A <Card>
requires a title
and can optionally include an icon
attribute set to the name of one of Starlight’s built-in icons.
The code above generates the following on the page:
Stars
Sirius, Vega, Betelgeuse
Moons
Io, Europa, Ganymede
Link Cards
Use the <LinkCard>
component to link prominently to different pages.
A <LinkCard>
requires a title
and an href
attribute. You can optionally include a short description
or other link attributes such as target
.
Group multiple <LinkCard>
components in <CardGrid>
to display cards side-by-side when there’s enough space.
The above code generates the following on the page:
Icon
Starlight provides a set of common icons that you can display in your content using the <Icon>
component.
Each <Icon>
requires a name
and can optionally include a label
, size
, and color
attribute.
The code above generates the following on the page:
All icons
A list of all available icons is shown below with their associated names. Click an icon to copy the component code for it.
Code
Starlight uses Expressive Code to render code blocks with extended formatting possibilities. In addition to fenced code blocks in markdown & MDX documents, Expressive Code can display syntax-highlighted code snippets using its <Code>
component.
The <Code>
component provides props like code
, lang
or meta
that allow you to dynamically define a code block’s contents. Using this component, you can render code blocks from variables or data coming from external sources like files, databases or APIs.
The code above generates the following on the page: