Skip to content

Authoring Content

Astro is a perfect choice for your content-focused site: blogs, marketing sites, portfolios, and more!

Astro helps you author and present your content. You can write a blog post directly in Astro using Markdown/MDX, or fetch your content from a headless CMS. Astro lets you build a site around your content: you can add a layout to your pages, create an index of posts, and set up an RSS feed to allow readers to subscribe.

In Astro, you can author your content in a variety of ways:

  • In Markdown files (.md or alternative extensions), designed to make it easy to write rich text content.
  • In MDX (.mdx) files, which let you include components and dynamic expressions in your document.
  • Using a third-party content management system (CMS), then pulling that content into a .astro page.
  • Other options (less commonly used for content-heavy pages) include .astro files and .html files.

Markdown is a convenient syntax for writing rich text with basic formatting and common elements like headers, lists, and images. Astro has built-in support for Markdown files in your project.

Create and write a new .md file in your code editor or bring in an existing file written in your favorite Markdown editor. Some online Markdown editors like StackEdit and Dillinger will even allow you to edit and sync your work with your Astro repository stored on GitHub.

If you add the MDX integration to your project, you can also write content using .mdx files, which let you include JavaScript expressions and custom components within your Markdown. This includes both static Astro components and interactive framework components. Add UI elements such as a banner or an interactive carousel right in your text to turn your content into full-fledged web pages.

Write and edit .mdx files directly in your code editor, alongside your project files.

Learn more about using MDX with Astro.

Write blog posts in your existing Content Management System (CMS) such as Storyblok, WordPress, or Contentful. Some CMSes, like Storyblok, provide an official Astro integration. Others expose a JavaScript SDK that Astro pages can use to fetch your remote content.

Markdown and MDX files that live in your src/pages directory will automatically generate pages on your site using Astro’s file-based routing, built at a URL corresponding to the post’s file path.

You can also choose to keep your Markdown and MDX files outside of the src/pages directory, and instead import their content into .astro pages.

If you’re writing your content in a CMS, you can fetch your posts and use dynamic routing to use one .astro file to generate a route for each post. In Astro’s default static mode, these routes are generated at build time. If you opt-in to SSR mode, you respond to a request at runtime and fetch the content on demand.

To build common features to organize and display your content, such as a blog archive or a page for each blog tag, Astro allows you to fetch filenames and metadata from your Markdown and MDX frontmatter and use these to generate page content and routes.

Related recipe: Add an RSS feed

In addition to the official @astrojs/mdx integration, there are several third-party community integrations for working with content in your Astro project.