Image
Displays an image
Install
Install the component from your command line
pnpm add jsx-emailpnpm add jsx-emailbun add jsx-emailbun add jsx-emailnpm add jsx-emailnpm add jsx-emailyarn add jsx-emailyarn add jsx-emailUsage
Add the component to your email template. Include styles where needed.
import { Img } from 'jsx-email';
const Email = () => {
return <Img src="cat.jpg" alt="Cat" width="300" height="300" />;
};import { Img } from 'jsx-email';
const Email = () => {
return <Img src="cat.jpg" alt="Cat" width="300" height="300" />;
};TIP
All email clients can display .png, .gif, and .jpg images. Unfortunately, .svg images are not well supported, regardless of how they're referenced, so avoid using these. See Can I Email for more information.
TIP
To use local images during development, place the images in your templates directory. We recommend using a assets/ or static/ subdirectory. Images can then be accessed from the server root. Just remember, for production, you'll need to host the images somewhere and reference them with a URL.
import { Img } from 'jsx-email';
const baseUrl = import.meta.isJsxEmailPreview ?
? '/assets/'
: 'https://assets.example.com/';
const Email = () => {
return <Img src={`${baseUrl}cat.jpg`} alt="Cat" width="300" height="300" />;
};import { Img } from 'jsx-email';
const baseUrl = import.meta.isJsxEmailPreview ?
? '/assets/'
: 'https://assets.example.com/';
const Email = () => {
return <Img src={`${baseUrl}cat.jpg`} alt="Cat" width="300" height="300" />;
};Component Props
alt?: string;alt?: string;Alternate description for an image
disableDefaultStyle?: boolean;disableDefaultStyle?: boolean;If true, instructs the component not to add default style properties to the component. This can be useful when attempting to override default styles with Tailwind or class names.
height?: string;height?: string;The height of an image in pixels
src?: string;src?: string;The path to the image
width?: string;width?: string;The width of an image in pixels
TIP
This component also expresses all of the Common Component Props for ComponentProps<'img'>.