Elements

The Custom code element

Add your own HTML, CSS and JavaScript to one spot on a page, for embeds, widgets and anything the other elements can't do. Only administrators can add or change it.

Custom code is in the Content group of the Elements panel. It's only shown to administrators (users who may post unfiltered HTML), and it's part of Builder Pro or Kufi ONE (activate a Pro key). Without Pro, code elements placed earlier keep working but can't be changed. Code snippets and site-wide code under Kufi → Custom code are free (a few snippet options are Pro).

Fields

Field What it does
Name in the builder Only shown in the builder, to tell code blocks apart in Layers.
HTML Any HTML, including <script> and <style> tags.
CSS Plain CSS. Write selector to target this block, for example selector .card { color: red; }.
JavaScript Runs once the page is ready. The variable el is this block.
Run scripts in the builder too Off by default, so a broken script can't get in the way while you edit.

Example

HTML:

<button type="button" class="tip">Show a tip</button>
<p class="tip-text" hidden>Press Ctrl+D to duplicate an element.</p>

JavaScript:

el.querySelector('.tip').addEventListener('click', function () {
  el.querySelector('.tip-text').hidden = false;
});

CSS:

selector .tip-text { color: var(--accent); }

Security and the Content Security Policy

Kufi blocks scripts that weren't added by the site, to protect visitors from injected code. Scripts and styles in this element get the page's security nonce automatically, so they run normally.

Scripts loaded from another domain (for example <script src="https://widget.example.com/x.js">) also get the nonce. But many widgets then load more scripts, images, frames or data from their own servers, and those are blocked for visitors until you allow the widget's domains. If a widget works while you are logged in but not for visitors, see Something is blocked by the Content Security Policy.

Good to know: The Content Security Policy only applies to visitors who aren't logged in. Always test embeds in a private browser window.

Who can edit it

  • Only administrators see the element and can change its code.
  • When an editor without that right saves a page that has a Custom code element, the code stays exactly as it was, and they can't add new code. The builder tells them: "This block holds custom code. Only administrators can change it."

Code for the whole site

For CSS on every page, analytics, tag managers or chat widgets, use Kufi → Custom code instead.

More in Elements

Still need help?

Tell us what you are trying to do and what you see. We read every message.