How can I help you?
Toast configuration
20 Feb 202624 minutes to read
This section explains how to customize Toast appearance, layout, and behavior using built-in properties and events. Configure titles, content, positioning, progress display, and stacking order to match your application’s notification requirements.
Title and content
Toast notifications display messages using the title property for headlines and the content property for message body. Both properties are responsive and adapt to various screen sizes and orientations. You can provide titles and content as plain text, HTML strings, or element references for flexible content presentation.
[Class-component]
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { ToastComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
class App extends React.Component {
toastInstance;
position = { X: 'Center' };
toastCreated() {
this.toastInstance.show();
}
toastShow() {
this.toastInstance.show();
}
render() {
return (<div>
<ButtonComponent cssClass="e-primary" onClick={this.toastShow = this.toastShow.bind(this)}> Show Toast </ButtonComponent>
<ToastComponent ref={toast => this.toastInstance = toast} title="Matt sent you a friend request" content="Hey, wanna dress up as wizards and ride our hoverboards?" position={this.position} created={this.toastCreated = this.toastCreated.bind(this)}/>
</div>);
}
}
export default App;import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { ToastComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
class App extends React.Component<{}, {}> {
public toastInstance: ToastComponent;
public position = { X: 'Center' };
public toastCreated(): void {
this.toastInstance.show();
}
public toastShow() {
this.toastInstance.show();
}
public render() {
return (
<div>
<ButtonComponent cssClass="e-primary" onClick={this.toastShow = this.toastShow.bind(this)}> Show Toast </ButtonComponent>
<ToastComponent ref={toast => this.toastInstance = toast!} title="Matt sent you a friend request" content="Hey, wanna dress up as wizards and ride our hoverboards?" position={this.position} created={this.toastCreated = this.toastCreated.bind(this)} />
</div>
);
}
}
export default App;[Functional-component]
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { ToastComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
function App() {
let toastInstance;
let position = { X: 'Center' };
function toastCreated() {
toastInstance.show();
}
function toastShow() {
toastInstance.show();
}
return (<div>
<ButtonComponent cssClass="e-primary" onClick={toastShow.bind(this)}> Show Toast </ButtonComponent>
<ToastComponent ref={toast => toastInstance = toast} title="Matt sent you a friend request" content="Hey, wanna dress up as wizards and ride our hoverboards?" position={position} created={toastCreated.bind(this)}/>
</div>);
}
export default App;import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { ToastComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App(){
let toastInstance: ToastComponent;
let position = { X: 'Center' };
function toastCreated(): void {
toastInstance.show();
}
function toastShow() {
toastInstance.show();
}
return (
<div>
<ButtonComponent cssClass="e-primary" onClick={toastShow.bind(this)}> Show Toast </ButtonComponent>
<ToastComponent ref={toast => toastInstance = toast!} title="Matt sent you a friend request" content="Hey, wanna dress up as wizards and ride our hoverboards?" position={position} created={toastCreated.bind(this)} />
</div>
);
}
export default App;Custom target container
By default, toasts render within the document body. Render toasts within a specific container element using the target property. Specifying a custom target enables scoped notifications within modal dialogs, panels, or specific application regions. Toast position is calculated relative to the target container.
Close button
Enable manual toast dismissal by setting showCloseButton to true. This adds a close button allowing users to dismiss toasts before automatic timeout expiration. Close buttons are particularly useful for persistent notifications or static toasts where manual dismissal is the primary interaction method.
Progress bar
Display visual timeout feedback using the showProgressBar property. When enabled, a progress bar appears indicating remaining toast display time, helping users anticipate dismissal. Configure progress bar direction using progressDirection to display from right-to-left (RTL, default) or left-to-right (LTR).
Stacking order
Control the order toasts appear on screen using the newestOnTop property. When enabled, new toasts appear above existing ones. When disabled (default), new toasts append below existing notifications, creating a growing stack.
Here below sample demonstrates the combination of target, showCloseButton, showProgressBar and newestOnTop properties in toast.
[Class-component]
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { ToastComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
class App extends React.Component {
toastInstance;
position = { X: 'Center' };
toastCreated() {
this.toastShow();
}
toastShow() {
setTimeout(() => {
this.toastInstance.show();
}, 600);
}
render() {
return (<div>
<ButtonComponent cssClass="e-primary" onClick={this.toastShow = this.toastShow.bind(this)}> Show Toast </ButtonComponent>
<ToastComponent ref={toast => this.toastInstance = toast} title="File Downloading" content="<div class='progress'><span style='width: 80%'></span></div>" position={this.position} showCloseButton='true' target="#toast_target" newestOnTop='true' showProgressBar='true' progressDirection='Ltr' created={this.toastCreated = this.toastCreated.bind(this)}/>
</div>);
}
}
export default App;import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { ToastComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
class App extends React.Component<{}, {}> {
public toastInstance: ToastComponent;
public position = { X: 'Center' };
public toastCreated(): void {
this.toastShow();
}
public toastShow() {
setTimeout(
() => {
this.toastInstance.show();
}, 600);
}
public render() {
return (
<div>
<ButtonComponent cssClass="e-primary" onClick={this.toastShow = this.toastShow.bind(this)}> Show Toast </ButtonComponent>
<ToastComponent ref={toast => this.toastInstance = toast!} title="File Downloading" content="<div class='progress'><span style='width: 80%'></span></div>" position={this.position} showCloseButton='true' target="#toast_target" newestOnTop='true' showProgressBar='true' progressDirection='Ltr' created={this.toastCreated = this.toastCreated.bind(this)} />
</div>
);
}
}
export default App;[Functional-component]
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { ToastComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
function App() {
let toastInstance;
let position = { X: 'Center' };
function toastCreated() {
toastShow();
}
function toastShow() {
setTimeout(() => {
toastInstance.show();
}, 600);
}
return (<div>
<ButtonComponent cssClass="e-primary" onClick={toastShow.bind(this)}> Show Toast </ButtonComponent>
<ToastComponent ref={toast => toastInstance = toast} title="File Downloading" content="<div class='progress'><span style='width: 80%'></span></div>" position={position} showCloseButton={true} target="#toast_target" newestOnTop={true} showProgressBar={true} progressDirection='Ltr' created={toastCreated.bind(this)}/>
</div>);
}
export default App;import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { ToastComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
let toastInstance: ToastComponent;
let position = { X: 'Center' };
function toastCreated(): void {
toastShow();
}
function toastShow() {
setTimeout(
() => {
toastInstance.show();
}, 600);
}
return (
<div>
<ButtonComponent cssClass="e-primary" onClick={toastShow.bind(this)}> Show Toast </ButtonComponent>
<ToastComponent ref={toast => toastInstance = toast!} title="File Downloading" content="<div class='progress'><span style='width: 80%'></span></div>" position={position} showCloseButton={true} target="#toast_target" newestOnTop={true} showProgressBar={true} progressDirection='Ltr' created={toastCreated.bind(this)} />
</div>
);
}
export default App;Width and height
we can set toast dimensions through width and height property. The height and width can be applied for specific set of toasts. So you can create different toasts with custom dimension.
In default toast can be rendered with ‘300px’ width with ‘auto’ height
In mobile device toast default width gets ‘100%’ width of the page.
When we sets toast width as ‘100%’ toast will occupies full width and displayed top or bottom based on positionYproperty.
Both width and height property allows setting pixels/numbers/percentage. The number value is considered as pixels.
[Class-component]
import { ButtonComponent, CheckBoxComponent, RadioButtonComponent } from '@syncfusion/ej2-react-buttons';
import { ToastComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
class App extends React.Component {
toastInstance;
checkboxObj;
constructor(props) {
super(props);
this.state = {
content: 'Hey, wanna dress up as wizards and ride our hoverboards?',
position: { X: 'Center', Y: "Bottom" },
title: 'Matt sent you a friend request',
width: 300
};
}
toastCreated() {
this.toastShow(600);
}
toastShow(timeOutDelay) {
setTimeout(() => {
this.toastInstance.show();
}, timeOutDelay);
}
checkboxChange(e) {
if (e.event.target.checked) {
this.setState({ position: { Y: "Top" } });
this.toastInstance.hide('All');
this.toastShow(700);
}
}
checkboxChange1(e) {
if (e.event.target.checked) {
this.setState({ position: { Y: "Bottom" } });
this.toastInstance.hide('All');
this.toastShow(700);
}
}
onChange(e) {
if (e.checked) {
this.toastInstance.hide('All');
this.setState({
content: "<div class='e-custom'>Take a look at our next generation <b>Javascript</b> <a href='https://ej2.syncfusion.com/home/index.html' target='_blank'>LEARN MORE</a></div>",
width: '100%',
title: ''
});
this.toastShow(500);
}
else {
this.toastInstance.hide('All');
this.setState({
content: 'Hey, wanna dress up as wizards and ride our hoverboards?',
width: 300,
title: 'Matt sent you a friend request'
});
this.toastShow(500);
}
}
render() {
return (<div id="container">
<div id="toast_full_width" className='row'>
<table>
<tbody>
<tr>
<td>
<div>
<RadioButtonComponent checked={true} label='Top' name="toast" change={this.checkboxChange = this.checkboxChange.bind(this)}/>
</div>
</td>
<td>
<div>
<RadioButtonComponent checked={true} label='Bottom' name="toast" change={this.checkboxChange1 = this.checkboxChange1.bind(this)}/>
</div>
</td>
</tr>
<tr>
<td>
<div>
<CheckBoxComponent label='100% Width' ref={scope => this.checkboxObj = scope} change={this.onChange = this.onChange.bind(this)}/>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<ButtonComponent cssClass="e-primary" onClick={this.toastShow = this.toastShow.bind(this, 500)}> Show Toast </ButtonComponent>
<ToastComponent ref={toast => this.toastInstance = toast} width={this.state.width} title={this.state.title} content={this.state.content} position={this.state.position} created={this.toastCreated = this.toastCreated.bind(this)}/>
</div>);
}
}
export default App;import { ButtonComponent, ChangeEventArgs, CheckBoxComponent, RadioButtonComponent } from '@syncfusion/ej2-react-buttons';
import { ToastComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
class App extends React.Component<{}, {}> {
public toastInstance: ToastComponent;
public checkboxObj: CheckBoxComponent;
constructor(props: any) {
super(props);
this.state = {
content: 'Hey, wanna dress up as wizards and ride our hoverboards?',
position: { X: 'Center', Y: "Bottom" },
title: 'Matt sent you a friend request',
width: 300
}
}
public toastCreated(): void {
this.toastShow(600);
}
public toastShow(timeOutDelay: number) {
setTimeout(
() => {
this.toastInstance.show();
}, timeOutDelay);
}
public checkboxChange(e: any): void {
if (e.event.target.checked) {
this.setState({ position: { Y: "Top" } });
this.toastInstance.hide('All');
this.toastShow(700);
}
}
public checkboxChange1(e: any): void {
if (e.event.target.checked) {
this.setState({ position: { Y: "Bottom" } });
this.toastInstance.hide('All');
this.toastShow(700);
}
}
public onChange(e: ChangeEventArgs): void {
if (e.checked) {
this.toastInstance.hide('All');
this.setState({
content: "<div class='e-custom'>Take a look at our next generation <b>Javascript</b> <a href='https://ej2.syncfusion.com/home/index.html' target='_blank'>LEARN MORE</a></div>",
width: '100%',
title: ''
});
this.toastShow(500);
} else {
this.toastInstance.hide('All');
this.setState({
content: 'Hey, wanna dress up as wizards and ride our hoverboards?',
width: 300,
title: 'Matt sent you a friend request'
});
this.toastShow(500);
}
}
public render() {
return (
<div id="container">
<div id="toast_full_width" className='row'>
<table>
<tr>
<td>
<div>
<RadioButtonComponent checked={true} label='Top' name="toast" change={this.checkboxChange = this.checkboxChange.bind(this)} />
</div>
</td>
<td>
<div>
<RadioButtonComponent checked={true} label='Bottom' name="toast" change={this.checkboxChange1 = this.checkboxChange1.bind(this)} />
</div>
</td>
</tr>
<tr>
<td>
<div>
<CheckBoxComponent label='100% Width' ref={scope => this.checkboxObj = scope!} change={this.onChange = this.onChange.bind(this)} />
</div>
</td>
</tr>
</table>
</div>
<ButtonComponent cssClass="e-primary" onClick={this.toastShow = this.toastShow.bind(this, 500)}> Show Toast </ButtonComponent>
<ToastComponent ref={toast => this.toastInstance = toast!} width={this.state.width} title={this.state.title} content={this.state.content} position={this.state.position} created={this.toastCreated = this.toastCreated.bind(this)} />
</div>
);
}
}
export default App;[Functional-component]
import { ButtonComponent, CheckBoxComponent, RadioButtonComponent } from '@syncfusion/ej2-react-buttons';
import { ToastComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
function App() {
let toastInstance;
let checkboxObj;
const [status, setStatus] = React.useState({ content: 'Hey, wanna dress up as wizards and ride our hoverboards?', title: 'Matt sent you a friend request', width: '600', position: { X: 'Center', Y: "Bottom" } });
function toastCreated() {
toastShow(600);
}
function toastShow(timeOutDelay) {
setTimeout(() => {
toastInstance.show();
}, timeOutDelay);
}
function checkboxChange(e) {
if (e.event.target.checked) {
setStatus({
content: '',
width: '',
title: '',
position: { Y: "Top", X: '' }
});
toastInstance.hide('All');
toastShow(700);
}
}
function checkboxChange1(e) {
if (e.event.target.checked) {
setStatus({
content: '',
width: '',
title: '',
position: { Y: "Bottom", X: '' }
});
toastInstance.hide('All');
toastShow(700);
}
}
function onChange(e) {
if (e.checked) {
toastInstance.hide('All');
setStatus({
content: "<div class='e-custom'>Take a look at our next generation <b>Javascript</b> <a href='https://ej2.syncfusion.com/home/index.html' target='_blank'>LEARN MORE</a></div>",
width: '100%',
title: '',
position: { X: '', Y: '' }
});
toastShow(500);
}
else {
toastInstance.hide('All');
setStatus({
content: 'Hey, wanna dress up as wizards and ride our hoverboards?',
width: '300',
title: 'Matt sent you a friend request',
position: { X: '', Y: '' }
});
toastShow(500);
}
}
return (<div id="container">
<div id="toast_full_width" className='row'>
<table>
<tr>
<td>
<div>
<RadioButtonComponent checked={true} label='Top' name="toast" change={checkboxChange.bind(this)}/>
</div>
</td>
<td>
<div>
<RadioButtonComponent checked={true} label='Bottom' name="toast" change={checkboxChange1.bind(this)}/>
</div>
</td>
</tr>
<tr>
<td>
<div>
<CheckBoxComponent label='100% Width' ref={scope => checkboxObj = scope} change={onChange.bind(this)}/>
</div>
</td>
</tr>
</table>
</div>
<ButtonComponent cssClass="e-primary" onClick={toastShow.bind(this, 500)}> Show Toast </ButtonComponent>
<ToastComponent ref={toast => toastInstance = toast} width={status.width} title={status.title} content={status.content} position={status.position} created={toastCreated.bind(this)}/>
</div>);
}
export default App;import { ButtonComponent, ChangeEventArgs, CheckBoxComponent, RadioButtonComponent } from '@syncfusion/ej2-react-buttons';
import { ToastComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
let toastInstance: ToastComponent;
let checkboxObj: CheckBoxComponent;
const [status, setStatus] = React.useState({ content: 'Hey, wanna dress up as wizards and ride our hoverboards?' , title: 'Matt sent you a friend request' ,width:'600' , position: { X: 'Center', Y: "Bottom" } });
function toastCreated(): void {
toastShow(600);
}
function toastShow(timeOutDelay: number) {
setTimeout(
() => {
toastInstance.show();
}, timeOutDelay);
}
function checkboxChange(e: any): void {
if (e.event.target.checked) {
setStatus({
content: '',
width: '',
title: '',
position: { Y: "Top", X:''}
});
toastInstance.hide('All');
toastShow(700);
}
}
function checkboxChange1(e: any): void {
if (e.event.target.checked) {
setStatus({
content: '',
width: '',
title: '',
position: { Y: "Bottom", X:''}
});
toastInstance.hide('All');
toastShow(700);
}
}
function onChange(e: ChangeEventArgs): void {
if (e.checked) {
toastInstance.hide('All');
setStatus({
content: "<div class='e-custom'>Take a look at our next generation <b>Javascript</b> <a href='https://ej2.syncfusion.com/home/index.html' target='_blank'>LEARN MORE</a></div>",
width: '100%',
title: '',
position: {X:'',Y:''}
});
toastShow(500);
} else {
toastInstance.hide('All');
setStatus({
content: 'Hey, wanna dress up as wizards and ride our hoverboards?',
width: '300',
title: 'Matt sent you a friend request',
position: {X:'',Y:''}
});
toastShow(500);
}
}
return (
<div id="container">
<div id="toast_full_width" className='row'>
<table>
<tr>
<td>
<div>
<RadioButtonComponent checked={true} label='Top' name="toast" change={ checkboxChange.bind(this)} />
</div>
</td>
<td>
<div>
<RadioButtonComponent checked={true} label='Bottom' name="toast" change={checkboxChange1.bind(this)} />
</div>
</td>
</tr>
<tr>
<td>
<div>
<CheckBoxComponent label='100% Width' ref={scope => checkboxObj = scope!} change={onChange.bind(this)} />
</div>
</td>
</tr>
</table>
</div>
<ButtonComponent cssClass="e-primary" onClick={toastShow.bind(this, 500)}> Show Toast </ButtonComponent>
<ToastComponent ref={toast => toastInstance = toast!} width={status.width} title={status.title} content={status.content} position={status.position} created={ toastCreated.bind(this)} />
</div>
);
}
export default App;