Astro Syntax vs. JSX
Find out how Astro templates differ from JSX and how it provides a simpler syntax.
When it comes to Astro’s template syntax, it closely resembles JSX with a few key differences that we need to cover. However, we also need to point out that Astro components themselves have different structures.
Component structure
Each component in Astro can be divided into the following two sections:
Component script: Anything that needs to be run on the server should be created here. Code written in the component script will not be bundled and included in the final HTML file.
HTML layout: This is the layout of the component itself. It can contain any valid HTML tags and other Astro components. Elements created here will be rendered in the browser.
To get a better understanding of what an Astro component looks like, take a look at the following example. The beginning and end of the component script is denoted by ---
, similar to how frontmatter is formatted in Markdown files.
Get hands-on with 1200+ tech skills courses.