React Favicon Helper

2.0.7 · active · verified Sun Apr 19

react-favicon is a React component that enables dynamic control over a web application's favicon. It allows developers to easily update the favicon image using a URL or a base64 encoded string, integrate animated sequences from a list of URLs, toggle these animations on and off, and display alert bubbles with customizable text and background colors directly on the favicon. Additionally, it supports custom icon overlays through a render function and offers a mechanism to preserve existing favicon links on the page, which can be beneficial for specific browser behaviors like desktop Safari. The package is currently at version 2.0.7 and appears to have an active release cadence, with recent updates ensuring compatibility with React 19 and addressing various internal component optimizations. Its key differentiator lies in providing a declarative, React-idiomatic way to manage complex favicon behaviors, moving beyond simple static <link> tags, making it suitable for applications requiring dynamic visual feedback in the browser tab.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic `Favicon` usage with a static URL and an animated sequence, updating the browser tab's icon dynamically. Includes basic error handling for root element.

import React from "react";
import ReactDOM from "react-dom";
import Favicon from "react-favicon";

function App() {
  const githubFaviconUrl = "http://oflisback.github.io/react-favicon/img/github.ico";
  const animatedFavicons = [
    "http://oflisback.github.io/react-favicon/img/github.ico",
    "https://www.google.com/favicon.ico",
    "https://www.npmjs.com/favicon.ico"
  ];

  return (
    <div>
      <Favicon url={githubFaviconUrl} />
      <h1>Hello, Favicon!</h1>
      <p>This component dynamically sets the favicon for your page.</p>
      <p>
        You can also animate it or show alerts. Here's an animated example:
      </p>
      <Favicon url={animatedFavicons} animated={true} animationDelay={1000} />
      <p>Check your browser tab to see the favicon change every second!</p>
    </div>
  );
}

// Assumes an HTML element with id="root" exists.
const rootElement = document.getElementById("root");
if (rootElement) {
  ReactDOM.render(
    <App />,
    rootElement
  );
} else {
  console.error("Root element not found. Please ensure an element with id='root' exists in your HTML.");
}

view raw JSON →