Base64 Image Example
· 3 min read
You can use these components to display base64 encoded images and SVG strings in your MDX files.
Base64Image Component
Basic Usage (Left Aligned - Default)
Center Aligned Image
Right Aligned Image
With Custom Dimensions
With Custom Styling
With CSS Class
SvgImage Component
Using SVG from Constants
// In src/data/svgConstants.ts
export const SKY = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<rect width="100" height="100" fill="#87CEEB"/>
<circle cx="20" cy="20" r="10" fill="#FFD700"/>
</svg>`;
import SvgImage from '@site/src/components/SvgImage';
import { SKY } from '@site/src/data/svgConstants';
<SvgImage svg={SKY} width={200} />
Inline SVG String
SVG Import from constant
SVG with Different Alignments
Left Aligned:
Center Aligned:
Right Aligned:
Usage Examples
Import from constants:
import Base64Image from '@site/src/components/Base64Image';
import SvgImage from '@site/src/components/SvgImage';
import { HOUSE } from '@site/src/data/imageConstants';
import { SKY } from '@site/src/data/svgConstants';
<Base64Image
src={HOUSE}
alt="House"
align="center"
width={400}
caption="My house image"
/>
<SvgImage
svg={SKY}
width={200}
align="center"
caption="Beautiful sky"
/>
Use inline:
<SvgImage
svg={`<svg>...</svg>`}
width={300}
align="right"
caption="Custom SVG graphic"
/>
