Built-in Components Reference
Este conteúdo não está disponível em sua língua ainda.
Astro includes several built-in components for you to use in your projects. All built-in components are available in .astro
files and may require an import statement.
You can reference the Props
of these components using the ComponentProps
type utility.
<Code />
Section titled <Code />This component provides syntax highlighting for code blocks at build time (no client-side JavaScript included). The component is powered internally by Shiki and it supports all popular themes and languages. Plus, you can add your custom themes, languages, transformers, and default colors by passing them to the theme
, lang
, transformers
, and defaultColor
attributes respectively.
This component does not inherit the settings from your Shiki configuration. You will have to set them using the component props.
Transformers
Section titled Transformers
Adicionado em:
astro@4.11.0
Shiki transformers can optionally be applied to code by passing them in through the transformers
property as an array. Since Astro v4.14.0, you can also provide a string for Shiki’s meta
attribute to pass options to transformers.
Note that transformers
only applies classes and you must provide your own CSS rules to target the elements of your code block.
<Fragment />
Section titled <Fragment />A component used with set:*
directives to render HTML content without any additional wrapping elements:
See more about using fragments in Astro syntax.
<Prism />
Section titled <Prism />To use the Prism
highlighter component, first install the @astrojs/prism
package:
This component provides language-specific syntax highlighting for code blocks by applying Prism’s CSS classes. Note that you need to provide a Prism CSS stylesheet (or bring your own) for syntax highlighting to appear! See the Prism configuration section for more details.
See the list of languages supported by Prism where you can find a language’s corresponding alias. And, you can also display your Astro code blocks with lang="astro"
!
<Image />
Section titled <Image />Properties
Section titled Properties- src (required)
- alt (required)
- width and height (required for
public/
and remote images) - format
- quality
- densities
- widths
In addition to the properties above, the <Image />
component accepts all properties accepted by the HTML <img>
tag.
See more in the Images Guide.
<Picture />
Section titled <Picture />
Adicionado em:
astro@3.3.0
Use the built-in <Picture />
Astro component to display a responsive image with multiple formats and/or sizes.
See more in the Images Guide.
Properties
Section titled Properties<Picture />
accepts all the properties of the <Image />
component, plus the following:
formats
Section titled formatsAn array of image formats to use for the <source>
tags. By default, this is set to ['webp']
.
fallbackFormat
Section titled fallbackFormatFormat to use as a fallback value for the <img>
tag. Defaults to .png
for static images, .gif
for animated images, and .svg
for SVG files.
pictureAttributes
Section titled pictureAttributesAn object of attributes to be added to the <picture>
tag. Use this property to apply attributes to the outer <picture>
element itself. Attributes applied to the <Picture />
component directly will apply to the inner <img>
element, except for those used for image transformation.
<Content />
Section titled <Content />A generic component used to render the content of a content collection entry.
First, query one or more entries using getCollection()
or getEntry()
. Then, the entry.render()
function can return the <Content />
component for use in a .astro
file template.
<ViewTransitions />
Section titled <ViewTransitions />
Adicionado em:
astro@2.9.0
Opt in to using view transitions on individual pages by importing and adding the <ViewTransitions />
routing component to <head>
on every desired page.
See more about how to control the router and add transition directives to page elements and components.
<Debug />
Section titled <Debug />This component provides a way to inspect values on the client-side, without any JavaScript.
Reference