Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende 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.

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 2

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

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

Desliza para mostrar el menú

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.

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 2
some-alt