Screen shot 2011-01-06 at 2.32.34 PM.png

Code per Node makes it possible to add custom CSS and Javascript per node, per content type, per block, and globally. The code is stored in the database, but served from the file system. It also supports syntax highlighting with CodeMirror.

CPN was covered by a recent webinar by Mediacurrent: (this is also mentioned in DrupalEasy podcast 120)

It should be made clear that allowing non-developers to insert JS at will can be A Really Bad Idea; to quote Bob Kepford:

That sad moment when I consider just using Code per Node.


After the usual module installation, you should:

  1. Configure the global settings at admin/config/content/cpn (D7) or admin/settings/cpn (D6).
  2. Set appropriate permissions at admin/people/permissions (D7) or admin/user/permissions (D6).
  3. Enable per-content type settings at admin/structure/types/manage/[node-type] (D7) or admin/content/node-type/[node-type] (D6).


  • Install CodeMirror (tested with v3.20) to sites/all/libraries/codemirror.
  • Turn on syntax highlighting at admin/config/content/cpn (D7) or admin/settings/cpn (D6).

Additional Notes

Related Modules

This module provides functionality similar to other modules. I'll outline the differences, as I best understand them:

  • CSS Injector: doesn't support Javascript (though JS Injector does); doesn't provide fields for CSS per-node, though it may be possible in the admin settings via configurable rules (and may get implemented in #437006: Added CSS fieldset for node/edit); doesn't support CSS per-block.
  • CSS: doesn't serve the CSS from the file system; doesn't support Javascript; doesn't support CSS per-block.
  • Context Add Assets: doesn't support editing CSS or Javascript through the website; association of external assets happens in the backend Context module; doesn't support per-block assets.
  • Inline CSS Checker: use this to find any content that has inline CSS in text fields.


Originally build by joelstein, Rob Loach contributed on the D7 port. Currently maintained by Damien McKenna.

Continued development is sponsored by Mediacurrent.

Supporting organizations: 
Ongoing development sponsorship.

Project Information