Skip to content
insert a string of css into the <head>
JavaScript CSS
Find file
Latest commit acc7f46 @substack upgrade tape
Failed to load latest commit information.
example working example!
test Add prepend option
LICENSE package.json etc
index.js Add prepend option
package.json upgrade tape
readme.markdown Add prepend option



insert a string of css into the <head>

browser support


suppose we've got some css:

body {
    background-color: purple;
    color: yellow;

and we want to bundle that css into a js file so that we can write an entirely self-contained module:

var fs = require('fs');
var insertCss = require('insert-css');
var css = fs.readFileSync(__dirname + '/style.css');
document.body.appendChild(document.createTextNode('HELLO CRUEL WORLD'));

optionally prepend the css to the head with the prepend option:

insertCss(css, { prepend: true });

compile with browserify using brfs to inline the fs.readFile() call:

$ browserify -t brfs insert.js > bundle.js

Now plop that bundle.js into a script tag and you'll have a self-contained js blob with inline css!

    <script src="bundle.js"></script>
Something went wrong with that request. Please try again.