Embed URL's as base64 strings inside your stylesheets

npm install grunt-css-url-embed
2 downloads in the last day
83 downloads in the last week
381 downloads in the last month


Embed URL's as base64 data URI's inside your stylesheets

There are lots of base64 embedding Grunt plugins out there, but pretty much all of them are already outdated and/or abandoned. This plugin aims to change that.

Most of the codebase is donated from datauri plugin.

Getting Started

This plugin requires Grunt ~0.4.0

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-css-url-embed --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:


cssUrlEmbed task

Run this task with the grunt cssUrlEmbed command.

Task targets, files and options may be specified according to the grunt Configuring tasks guide.

Both image and font URL's are supported. Web URL's won't be supported.



Type: String

Default: . or the directory of Gruntfile.js

The base directory for URL's. Can be absolute or relative to the directory of your Gruntfile.js.

Usage Examples

Map input and output files directly

cssUrlEmbed: {
  encodeDirectly: {
    files: {
      'path/to/output.css': ['path/to/input.css']

Specify base directory if needed

cssUrlEmbed: {
  encodeWithBaseDir: {
    options: {
      baseDir: './app'
    files: {
      'path/to/output.css': ['path/to/input.css']

Process all CSS files in target directory

cssUrlEmbed: {
  encode: {
    expand: true,
    cwd: 'target/css',
    src: [ '**/*.css' ],
    dest: 'target/css'

Release History

  • 2014-01-29      v0.1.3      Fixed handling of URL's with parameters. Improved logging.
  • 2013-10-02      v0.1.2      Changed logging a bit.
  • 2013-09-17      v0.1.1      Removed dependency on datauri. Now pretty much all MIME types are supported.
  • 2013-09-09      v0.1.0      First version.
npm loves you