Using Image Components in MDX

A demonstration of how to inject images directly into MDX blog posts.

By WiL

July 9, 2025

Guide: Using Image Components in MDX for Astro | Writ In Light | Writ In Light

Switching to MDX

Wanted to use a more modular method to import images in blog articles. Found with general .md files text was easy but images were a bit more difficult to style. With .mdx can directly import the image in as .js

Using Image Components in MDX

This post acts as a template for how to utilise multiple methods to inject images into MDX formatted documents, utilising placehold.co

Full Width Image

A full width image example

Inline Image

An inline image example

Float Left with Text

Float left image

This text wraps around the floated image. You can see how the image is positioned to the left and the text flows around it. This is great for creating more dynamic layouts in your blog posts.

Captioned Image

Captioned image example
A beautiful sunset over the mountains

Image Pair

Before the change
Before the change
After the change
After the change

Pull Quote

“A charming pull quote.”

Initial Colour Palette

Canvas

Dust

Ink

Before & After

Before
Before
After
After

Regular Markdown Still Works

You can still use regular markdown alongside the components:

  • Bold text and italic text
  • Lists work normally
  • Links function as expected
  • Code blocks work too:
console.log("Hello, MDX!");

Benefits of MDX

  1. Component Reusability: Import and use any component in your blog posts
  2. Interactive Content: Add interactive elements to your posts
  3. Consistent Styling: Use your design system components
  4. Better Organization: Keep your content and presentation logic separate

Now you can create rich, interactive blog posts with custom components while maintaining the simplicity of markdown!

Write something in the light

Leave a thought, reflection, or a quiet ripple below.