Open In App

React-Bootstrap Badge Contextual variations

React-Bootstrap is a front-end framework that was designed keeping react in mind. Bootstrap was re-built and revamped for React, hence it is known as React-Bootstrap.Badges are used for indication purposes like to show the notifications number, and we can also display messages using variants that come with this framework.We can style the badges differently depending on their context or state. Contextual variation basically allows us to change the visual presentation of React-Bootstrap components to convey different meanings, states or styles, depending on the specific use case or user interaction.
The different types of contextual variations available are:

Syntax:



 <Badge bg="*"> Your Text </Badge>

Note: Replace “*” with above mentioned variants

Example 1: This example explains Primary, Secondary, Success, Danger variants of Badge Contextual Variants.




// App.js
import React from "react";
import Badge from "react-bootstrap/Badge";
  
export default function App() {
    return (
        <div>
            <Badge bg="primary"> Blue </Badge>
            <Badge bg="secondary"> Gray </Badge>
            <Badge bg="success"> Green </Badge>
            <Badge bg="danger"> Red </Badge>
        </div>
)}

Output:



Example 2: This example explains Warning, Info, Light, Dark variants of Badge Contextual Variants.




// App.js
import React from "react";
import Badge from "react-bootstrap/Badge";
  
export default function App() {
    return (
        <div>
            <Badge bg="warning" text="dark">Yellow</Badge>
            <Badge bg="info">Sky Blue</Badge>
            <Badge bg="light" text="dark">White</Badge>
            <Badge bg="dark">Black</Badge>
        </div>
)}

Output:


Article Tags :