If you've ever built a Webpack project and noticed the browser tab shows a generic globe or a blank square, you're not alone. Webpack doesn't handle favicons out of the box — you need to wire it up yourself. The good news: it's a few lines of config once you know where to put the file and how to inject the link tag.

This guide walks you through adding a favicon to a Webpack project, from placing the file to verifying it in the browser. We'll cover both the simple copy approach and the HtmlWebpackPlugin method, plus the pitfalls that trip up most developers.

Prerequisites

You should have a working Webpack project with webpack and webpack-cli installed. If you're using html-webpack-plugin to generate your HTML, that's even better — we'll use it in the recommended approach. A favicon file (ICO, PNG, or SVG) ready to go. If you need one, you can generate a multi-size ICO with our guide.

Step 1: Place the favicon in your project

Create a folder for static assets if you don't have one. A common convention is src/assets/ or public/. Put your favicon file there — let's call it favicon.ico for maximum browser compatibility. You can also use favicon.png or favicon.svg; SVG is supported in modern browsers but needs a fallback for older ones (see SVG with PNG fallback).

For this guide, we'll assume the file is at src/assets/favicon.ico.

Step 2: Configure Webpack to copy the favicon

Webpack needs to know about the file so it ends up in your build output. The simplest way is to use copy-webpack-plugin. Install it:

npm install --save-dev copy-webpack-plugin

Then add it to your webpack.config.js:

const CopyPlugin = require('copy-webpack-plugin');

module.exports = {
  // ... other config
  plugins: [
    new CopyPlugin({
      patterns: [
        { from: 'src/assets/favicon.ico', to: 'favicon.ico' }
      ]
    })
  ]
};

This copies the favicon to the root of your output directory (e.g., dist/favicon.ico). Browsers automatically request /favicon.ico if no link tag is present, so this alone can work — but explicit link tags are better for control and for non-ICO formats.

Step 3: Inject the link tag with HtmlWebpackPlugin

If you're using html-webpack-plugin, you can add the favicon link directly in your HTML template. In your index.html template (usually in src/), add this inside the <head>:

<link rel='icon' href='favicon.ico' type='image/x-icon'>

Because the file is copied to the output root, the relative path favicon.ico resolves correctly. If you're serving from a subdirectory, use an absolute path like /favicon.ico or configure publicPath in Webpack.

For SVG favicons, use:

<link rel='icon' href='favicon.svg' type='image/svg+xml'>

And for PNG:

<link rel='icon' href='favicon.png' type='image/png'>

The rel='icon' attribute is defined in the HTML standard as the way to specify a site icon. Browsers use it to pick the best icon for tabs, bookmarks, and history.

Step 4: Build and verify

Run your build command (e.g., npm run build). Check that favicon.ico appears in your output folder. Then serve the build locally (e.g., with npx serve dist) and open it in a browser. The tab should show your icon. If it doesn't, hard-refresh (Ctrl+Shift+R or Cmd+Shift+R) to bypass cache.

You can also inspect the page source to confirm the link tag is present and the path is correct.

Common pitfalls

Conclusion

Adding a favicon to a Webpack project is straightforward once you know the two key pieces: copying the file to the output and referencing it in your HTML. Use copy-webpack-plugin to move the asset, and add a link rel='icon' tag in your template. That's it — your tabs will look polished and professional.

If you need to generate a complete favicon set (ICO, PNG, Apple Touch, manifest icons), try Mzu favicondl to create all the files in one go.