Button
A JSX email component which styles an anchor element to appear as a button
TIP
Semantics: Quite often in the email world we talk about buttons when we actually mean links. Behind the scenes this component is a <a> element which is styled like a <button> element.
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 { Button } from 'jsx-email';
const Email = () => {
return (
<Button width={160} height={60} href="https://jsx.email" target="_blank">
JOIN US
</Button>
);
};import { Button } from 'jsx-email';
const Email = () => {
return (
<Button width={160} height={60} href="https://jsx.email" target="_blank">
JOIN US
</Button>
);
};Component Props
export interface ButtonProps extends BaseProps<'a'> {
width: number;
height: number;
href?: string;
align?: 'left' | 'center' | 'right';
backgroundColor?: string;
borderColor?: string;
borderRadius?: number;
borderSize?: number;
fontSize?: number;
textColor?: string;
withBackground?: boolean;
}export interface ButtonProps extends BaseProps<'a'> {
width: number;
height: number;
href?: string;
align?: 'left' | 'center' | 'right';
backgroundColor?: string;
borderColor?: string;
borderRadius?: number;
borderSize?: number;
fontSize?: number;
textColor?: string;
withBackground?: boolean;
}TIP
It's highly reccommended for optimal email client compatibility to use the component props below to set styles, rather than CSS, the style property, or Tailwind classes. This is especially important for Outlook.
href?: string;href?: string;The url to navigate to when the button is clicked.
width: number;width: number;Specifies the width of the Button in pixels
height: number;height: number;Specifies the height of the Button in pixels
align?: 'left' | 'center' | 'right';align?: 'left' | 'center' | 'right';Specifies the horizontal alignment of the Button in the container. Default value is left
target?: string;target?: string;Specifies the value of the "target" attribute for the button target.
backgroundColor?: string;backgroundColor?: string;Specifies the hex value for the background-color of the button
borderColor?: string;borderColor?: string;Specifies the hex value border-color for the button
borderRadius?: number;borderRadius?: number;Specifies the border-radius value for the button in pixels
borderSize?: number;borderSize?: number;Specifies the border-width value in pixels
fontSize?: number;fontSize?: number;Specifies the font-size value in pixels
textColor?: string;textColor?: string;Specifies the hex value for the color of the text
withBackground?: boolean;withBackground?: boolean;Set to true if Button is nested in a Background component. Neccessary for good Outlook compatibility.
TIP
This component also expresses all of the Common Component Props for ComponentProps<'a'>.