Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Custom Content and HTML | Building and Customizing Alerts
Interactive Alerts in React with SweetAlert2

bookCustom Content and HTML

When you want to make your alerts more engaging or informative in your React application, SweetAlert2 allows you to customize the content in several ways. You can set a custom title, add descriptive text, or even embed HTML for richer formatting. The title and text options accept simple strings, while the html option lets you add formatted content, such as bold text, lists, or links. This flexibility means you can communicate more clearly with users or display additional information directly within the alert dialog.

Suppose you want to show an alert that includes an image and some formatted HTML to highlight important details. You can use the imageUrl option to display an image, and the html option to include HTML tags for formatting. Here is how you might set up such an alert in your React component:

import Swal from 'sweetalert2';

function showCustomAlert() {
  Swal.fire({
    title: 'Profile Updated!',
    html: '<strong>Your changes have been saved successfully.</strong><br><a href="/profile">View your profile</a>',
    imageUrl: 'https://example.com/success.png',
    imageWidth: 100,
    imageHeight: 100,
    imageAlt: 'Success image'
  });
}

In this example, the title displays a simple message, while the html property uses HTML tags to emphasize the text and provide a clickable link. The imageUrl property shows an image above the text, and you can control its size and alternative text. Using these options, you can create visually rich alerts that better match your application's design and user experience goals.

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 2

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Suggested prompts:

Can you explain more about the `html` option and what kind of HTML is supported?

How can I customize the appearance of the alert further, like changing colors or buttons?

Are there any best practices for using images in SweetAlert2 alerts?

bookCustom Content and HTML

Swipe um das Menü anzuzeigen

When you want to make your alerts more engaging or informative in your React application, SweetAlert2 allows you to customize the content in several ways. You can set a custom title, add descriptive text, or even embed HTML for richer formatting. The title and text options accept simple strings, while the html option lets you add formatted content, such as bold text, lists, or links. This flexibility means you can communicate more clearly with users or display additional information directly within the alert dialog.

Suppose you want to show an alert that includes an image and some formatted HTML to highlight important details. You can use the imageUrl option to display an image, and the html option to include HTML tags for formatting. Here is how you might set up such an alert in your React component:

import Swal from 'sweetalert2';

function showCustomAlert() {
  Swal.fire({
    title: 'Profile Updated!',
    html: '<strong>Your changes have been saved successfully.</strong><br><a href="/profile">View your profile</a>',
    imageUrl: 'https://example.com/success.png',
    imageWidth: 100,
    imageHeight: 100,
    imageAlt: 'Success image'
  });
}

In this example, the title displays a simple message, while the html property uses HTML tags to emphasize the text and provide a clickable link. The imageUrl property shows an image above the text, and you can control its size and alternative text. Using these options, you can create visually rich alerts that better match your application's design and user experience goals.

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 2
some-alt