Skip to content

Custom element

Write your own element in HTML, CSS, and JavaScript, save it to your project, and reuse it in any funnel with settings in Properties.

A custom element is an element you write yourself in HTML, CSS, and JavaScript and save to your project. Use it when no built-in element matches what you need, for example, when you recreate a screen from a reference or a URL with AI Chat.

A custom element lets you build anything built-in elements can’t, such as animated buttons, charts, badges, or anything else. You write it once as an HTML fragment, then reuse it on any screen in any funnel of the project.

Each save creates a new version (v1, v2…). Funnels keep the version they use until you open them in the editor, save, and publish.

Custom elements are available in every project. Anyone who can edit funnels in the project can work with them.

Create custom elements with AI Chat, or write the code yourself. You can also have Claude write the code from this page.

  1. Open AI Chat

    Open AI Chat in Editor in the selector on the right. In the model menu, check that Engine is set to v2.

  2. Share reference

    Attach a reference image or paste a funnel link. When no built-in element matches part of it, the agent writes, saves, and places a custom element for you.

    Or describe the element, for example create a custom element that shows a score in a ring.

Prompt AI Chat in Editor to add a custom element by its name. When you rebuild a screen from a reference or a URL, AI Chat reuses your project’s custom elements, or creates new ones when no built-in element matches.

Or add them manually:

  1. Add element

    Open the Elements tab on the left, click Add element and go to Custom. You can also type the element’s name in the search. Click the element to add it to the current screen.

  2. Configure element

    Open Properties in the selector on the right and go to the Parameters tab. Below the common settings, such as ID and visibility, you see the props declared in the element’s code.

    The header of the props section shows:

    • Version: The version this element uses, for example v2.
    • Update to vN: Appears when the project has a newer version. Click it to move this element to the latest version.
    • Edit custom element: The gear icon opens the code editor.
  3. Style element

    Go to Properties > Styles to adjust the Container section and the style groups the element declares.

Open the code editor in one of these ways:

  • Right-click the element in the Elements tab and select Edit custom element.
  • Click Edit next to the element in Add element > Custom.

The code editor opens with the latest version. Its subtitle shows the version you’re about to create, for example v2 → v3. Change the code and click Save new version.

If the new version removes a prop or changes its type, elements lose that prop’s value. The editor shows Values at risk · this funnel first. Click Save anyway to save.

To keep the values, add a migration step to the code yourself or ask AI Chat to add it. A step moves values from version N to the version you’re saving:

Migration steps
<!-- Saved as v2: the "heading" prop is renamed to "title" -->
<script type="ff/migrate" data-from="1">
ctx.move('heading', 'title');
</script>
<!-- Saved as v3: the "ring" enum ("on"/"off") becomes the "showRing" boolean -->
<script type="ff/migrate" data-from="2">
config.showRing = config.ring !== 'off';
</script>
  • config holds the element’s props.
  • ctx.move() renames a prop and moves its translations.
  • Steps run only in the editor, when a funnel moves to the new version. They can’t use ff, the page, timers, or the network.

Saving a new version doesn’t change any funnel. For example, a published funnel uses v1 and you save v2:

  1. The live funnel stays on v1.
  2. You open the funnel in the editor: Its elements switch to v2 automatically, as an unsaved change. The live funnel is still on v1.
  3. You save and publish the funnel: The live funnel switches to v2.

When the elements switch versions, settings you changed keep their values. Settings you left at the default take the new default.

If an element doesn’t switch automatically, click Update to vN in Properties > Parameters.

Custom elements can’t be deleted. To hide one from your elements selector, open the code editor and click Hide from menu. The element disappears from the Add element menu, but funnels that already use it keep showing it. To offer it again, click Show in menu.

Custom elements you paste from another project, or that come with a template, are copied into your project. If you can’t access the original project, the element shows Custom element not found and the funnel can’t be published.

Text props of custom elements are translated together with the rest of the funnel. Learn about localizations.

  • text props: Translated like texts of built-in elements.
  • asset props: Can be changed per language, but aren’t translated automatically.
  • text props with the id or emoji format: Never translated.

Text typed directly into the markup isn’t translatable. The code itself is never sent for translation.

A custom element is one HTML fragment with up to four parts:

Part How to write it Required What it does
Manifest <script type="application/json" data-ff-manifest> No Names the element and declares its settings (props) and capabilities
Style <style> No CSS that applies only to the element’s own markup
Markup Any HTML. Mark one element with data-ff-root Yes What the element shows
Script <script> without src No Behavior that markup and CSS can’t express

The starter code in the code editor declares one text prop, Label, and shows its value:

Starter code
<script type="application/json" data-ff-manifest>
{
"schema": 1,
"api": 1,
"name": "My element",
"category": "custom",
"engine": { "type": "html", "entry": "inline" },
"props": {
"label": { "type": "text", "label": "Label", "default": "Continue" }
},
"ssr": "static"
}
</script>
<div data-ff-root><span data-ff-prop="label"></span></div>
namestring

The element’s name in the Add element menu and the Elements tab.

propsobject

The element’s settings in Properties > Parameters. See Props.

stylesobject

Optional style settings in Properties > Styles. See Style groups.

capabilitiesobject

What the scripts may do beyond reading their own props, such as writing variables or navigating. See Capabilities.

previewobject

Sample values that scripts read on the editor canvas. vars holds variables, values holds the option values of Options answers:

"preview": { "vars": { "height": 175 }, "values": { "frequency": ["often"] } }

Keep schema, api, category, engine, and ssr as they are in the starter code.

Each prop is a key under props with a type, a label shown in Properties, and a default value:

Type Value Options
text Text format: plain (default), multiline, id, or emoji
number Number min, max, step, units (for example ["px"] or ["s"])
boolean Yes or no —
enum One value from a list values: a list of strings, numbers, or { "value": ..., "label": ... } objects
color Color default can be a hex color or a theme color, such as var(--app-color-primary)
asset Image, video, or Lottie animation kind: image, video, or lottie
ref A screen, an element, or a variable to: screen, element, or variable. For element, of lists the element types to offer, such as ["Plans"]
action An action actions: the action types to offer, such as ["navigate", "link", "scroll", "visibility"]
expression A condition kind: visibility. Set in a condition builder, like an element’s visibility
list A list of items of: the fields of each item, or item: a single field; min, max
group Several props shown together fields: the props in the group
variant One of several sets of props discriminator and variants

For an action prop, the only allowed default is "navigate", which goes to the next screen.

A ref prop with "to": "element" offers the elements of the same screen. A ref prop with "to": "variable" offers the funnel’s answers, grouped by screen, and email. You can also type a name, such as query.utm_source for a URL parameter.

Declare under capabilities what the scripts do beyond reading their own props. Each key unlocks part of the script API. Every key is optional:

Key Value Unlocks
reads Variable names Nothing. It lists the variables the scripts read
writes Variable declarations, such as { "name": "score", "type": "number", "default": 0 } ff.vars.set for these names
events Event names ff.track for these names
navigates "to", "next", "back", "external" The ff.actions.go methods you list
storage true ff.storage
writable { "value": "text" } or { "value": "number" } ff.field: the element holds an answer
formGate true ff.form

A writes variable has a type of text, number, or boolean. Its name starts with a lowercase letter and has only letters and digits. It starts at its default (else "", 0, or false) unless it already holds a value.

List in navigates only the methods the scripts call. The funnel diagnostic counts a listed next or external as a way forward and back as a way back. It doesn’t count to: give each target screen a ref prop instead.

These names are reserved and can’t be used in writes or as the ID of an element that holds an answer: user, query, inputs, source_subscription, singular, element, custom, countdown, _USERID_, email, checkout, _password_, firebase-password, phone, password, and zigzagid.

Event names can’t repeat FunnelFox tracking events, Meta standard events, or TikTok reserved events, in any letter case.

Bindings connect props to the markup and CSS. FunnelFox applies them before any script runs and again every time a prop changes. Every prop a binding names must be declared in the manifest.

Binding What it does
data-ff-prop="label" Sets the node’s text to the label prop
data-ff-attr="src:image alt:caption" Sets attributes from props, as attribute:prop pairs separated by spaces
data-ff-show="showRing" Hides the node unless the showRing prop is true
data-ff-action="action" Runs the action prop when the visitor clicks the node or presses Enter or Space
var(--p-label) CSS variable for every color, number, enum, and boolean prop. Numbers get their unit, and booleans become 1 or 0
var(--app-...) Your funnel’s theme values, such as var(--app-color-primary) or var(--app-border-radius-box)

Each <script> runs once after the markup appears. Scripts run on the published funnel, its preview link, and the editor canvas, but not in the preview of the code editor.

On the editor canvas, actions, navigation, and tracking do nothing. Variables take their values from preview.vars, and every element counts as visible. Test the behavior on the preview link.

When you change a prop or a style, a script that listens with ff.onChange keeps running, and the element updates in place. Without a listener, the element renders again and its scripts run again. The same happens when the element moves to a new version or the editor switches language.

rootobject

The element’s own root. Look up nodes with root.querySelector() instead of document.

ffobject

The object scripts call. See Script API.

FunnelFox clears the timers (setTimeout, setInterval, requestAnimationFrame) and the event listeners a script added to window, document, or root when the element renders again or leaves the screen.

Scripts work with the element and the funnel through the ff object.

  • Some calls need a capability. Without it, you can’t save the element.
  • On the editor canvas, actions, navigation, and tracking do nothing.
  • Methods that listen for changes, such as ff.vars.on, return a function that stops listening.
  • elementId is an element’s internal ID, from ff.page.elements() or a ref prop, not the ID set in Properties.
ff.elementobject

The element’s id, customId (the ID set in Properties), type, props, and styles. Text props are already translated.

ff.onChange(cb)function

Calls cb when a prop or style changes. The element updates without running its scripts again.

ff.vars.get(name)function

Reads a variable or an answer. Answers are text, so convert numbers with Number(). query.<name> reads a URL parameter.

ff.vars.values(name)function

The selected values of an Options answer, as an array, or undefined until it’s answered. Use them instead of labels, which change per language.

ff.vars.set(name, value)function

Writes a variable for {{name}} in funnel texts. Declare it in capabilities.writes. Conditions can’t read it; use an answer instead.

ff.vars.on(name, cb)function

Calls cb(value) when a variable or answer changes.

ff.vars.render(text)function

Fills the {{name}} placeholders in a text.

ff.vars.onRender(cb)function

Calls cb(render) now and after every variable change.

ff.actions.run(action)function

Runs an action prop, such as ff.element.props.next.

ff.actions.goobject

next(), back(), to(screenId), and external(url) navigate. List each one you use in capabilities.navigates.

ff.actions.visibility(elementId, value)function

Shows, hides, or toggles an element: 'visible', 'hidden', or 'toggle'. Hiding the custom element itself stops its scripts.

ff.actions.scroll(elementId)function

Scrolls to an element.

On the editor canvas, every element counts as visible.

ff.visibility.of(elementId)function

true if the element is visible.

ff.visibility.onOf(elementId, cb)function

Calls cb(visible) when the element shows or hides.

ff.visibility.rule(key, expr)function

Tracks a condition, such as an expression prop. Returns { visible(), on(cb), destroy() }.

ff.page.idstring

The current screen’s ID. index is its position from 0, and total is the number of screens.

ff.page.progress()function

{ position, total }, as the progress bar counts them.

ff.page.modalOpen()function

true while a popup is open. onModal(cb) reports changes.

ff.page.elements()function

The screen’s elements. find(elementId) returns one of them.

ff.modeobject
  • tier: live on the funnel and its preview link, editor on the canvas.
  • sandbox: false only on the published funnel.
ff.contextobject

locale, country, url.params, identity, experiment, browser, and paymentMethods().

ff.brand.tokensobject

Theme values by CSS variable name, such as ff.brand.tokens['--app-color-primary']. Use them where var() doesn’t work, such as on a canvas.

ff.lifecycle.onMount(fn)function

Runs fn after all of the element’s scripts run.

ff.lifecycle.onDestroy(fn)function

Runs fn when the element is removed or renders again.

ff.money.format(amount, currency)function

Formats a price for the funnel’s language, such as $9.99.

ff.logobject

debug(), warn(), and error() write to the browser console.

ff.track(name, payload?)function

Sends a custom event to your analytics integrations, not to FunnelFox analytics. List the name in capabilities.events.

ff.storage(scope, persistence)function

Saves values and returns get(key), set(key, value), and remove(key). Needs "storage": true.

  • scope: 'element' for this element, 'funnel' for all custom elements in the funnel.
  • persistence: 'memory' until the page reloads, 'local' after reloads too.

ff.field.register(spec) makes the element store an answer, like a Text input. Needs capabilities.writable.

  • The answer is named by the element’s ID in Properties.
  • Conditions can use it, as Text or Number.
  • In webhooks and the API, its element type is prj_<projectId>/<slug>.
specobject
  • kind: 'text' or 'number', as in capabilities.writable.
  • required: While the answer is empty, a Button on the same screen can’t navigate.
  • validate(value): Returns an error message, or undefined if the value is valid. A text answer arrives as { value }.
  • initial: The starting value.
handleobject

What register returns:

  • set(value), get(): Write a string or number, read { value } for text.
  • onValue(cb), onError(cb): Report a new value or error message.
  • validate(): Returns true if the answer is valid.
  • destroy(): Removes the field and keeps the answer.

Checks the screen’s fields before a custom button navigates. Needs "formGate": true.

Submit button
root.querySelector('button').addEventListener('click', async () => {
if (await ff.form.submit()) ff.actions.run(ff.element.props.next);
});
ff.form.submit()function

Checks every field on the screen. Resolves true if all pass.

ff.form.canSubmit()function

false while a required answer is empty.

The Styles tab shows the Container section for every custom element. To add your own style settings, declare a style group under styles in the manifest:

"styles": {
"card": {
"kind": "group",
"label": "Card",
"fields": {
"radius": { "type": "number", "label": "Radius", "default": 16, "units": ["px"] }
}
}
}

Style fields can be number, enum, color, or boolean. Each field becomes a CSS variable named --s-<group>-<field>, so the example above gives var(--s-card-radius).

These block the save with an error:

  • Load scripts with <script src> or <script type="module">.
  • Make network requests with fetch, XMLHttpRequest, sendBeacon, WebSocket, or EventSource.
  • Use import(), eval, or new Function.
  • Use javascript: URLs or CSS @import.
  • Use inline event handlers, such as onclick. Add listeners in a script.
  • Put content outside the data-ff-root element.
  • Use an ff part that doesn’t exist, such as ff.http.
  • Use a host API feature without its capability, or call ff.vars.set or ff.track with a name the manifest doesn’t declare.
  • Use a reserved name in capabilities.
  • Pass an action written in code to ff.actions.run.
  • Exceed 64 KB of source code.

<link>, <meta>, <title>, and <base> tags are removed from the saved element, with a warning.

These trigger a warning:

  • Calls to fox (the Fox API). Use ff instead.
  • localStorage and sessionStorage. Use ff.storage instead.
  • {{variable}} in a script, where nothing fills it. Use a text prop or ff.vars.render.

The code editor checks only what the code spells out, such as ff.vars.set('score', ...). FunnelFox checks every call again when the script runs.

Rich text and HTML text props, external libraries, and elements that hold other elements aren’t supported. The code editor names the unsupported part when you use one.

Only the markup is required, so you can paste an existing HTML widget that follows the restrictions. FunnelFox adds a manifest automatically and replaces {{variable}} placeholders in the markup, as Raw HTML does. A snippet without a manifest has no settings in Properties and no translatable texts.

A full-width button with a two-color gradient and twinkling stars. It has six props: a label, two gradient colors, the number of stars, the twinkle speed, and the action to run on press.

Gradient stars button code
Gradient stars button
<script type="application/json" data-ff-manifest>
{
"schema": 1, "api": 1,
"name": "Gradient stars button",
"description": "CTA button with a two-color gradient and floating stars",
"category": "custom",
"engine": { "type": "html", "entry": "inline" },
"props": {
"label": { "type": "text", "label": "Label", "default": "Continue" },
"from": { "type": "color", "label": "Gradient start", "default": "var(--app-color-primary)" },
"to": { "type": "color", "label": "Gradient end", "default": "var(--app-color-secondary)" },
"stars": { "type": "number", "label": "Stars", "default": 12, "min": 0, "max": 40, "step": 1 },
"speed": { "type": "number", "label": "Twinkle speed", "default": 2, "min": 0.5, "max": 10, "step": 0.5, "units": ["s"] },
"action": { "type": "action", "label": "On press", "actions": ["navigate", "link", "scroll", "visibility"], "default": "navigate" }
},
"ssr": "static"
}
</script>
<style>.btn { position: relative; overflow: hidden; width: 100%; padding: 16px 24px; border: 0; cursor: pointer; border-radius: var(--app-border-radius-box); background: linear-gradient(90deg, var(--p-from), var(--p-to)); color: var(--app-color-text-on-primary); font: inherit; font-weight: 600; }
.star { position: absolute; width: 6px; height: 6px; border-radius: 50%; background: #fff; opacity: 0; animation: twinkle var(--p-speed) ease-in-out infinite; }
@keyframes twinkle { 50% { opacity: .9; transform: scale(1.4); } }</style>
<button class="btn" data-ff-root data-ff-action="action"><span data-ff-prop="label"></span><span class="stars" aria-hidden="true"></span></button>
<script>
const layer = root.querySelector('.stars');
const { stars } = ff.element.props;
layer.replaceChildren(...Array.from({ length: stars }, (_, i) => {
const s = document.createElement('i');
s.className = 'star';
s.style.left = `${(i * 37) % 100}%`;
s.style.top = `${(i * 53) % 100}%`;
s.style.animationDelay = `${(i % 7) * 0.3}s`;
return s;
}));
</script>

A card that adds up the answers of two elements with the IDs q_sleep and q_stress and shows the sum in a ring. It writes the sum to the score variable, so later screens can show {{score}}, and sends the score_shown event. It updates when either answer or a prop changes.

Score card code
Score card
<script type="application/json" data-ff-manifest>
{
"schema": 1, "api": 1,
"name": "Score card",
"description": "Sums two quiz answers into a score with a ring gauge and a continue button",
"category": "custom",
"engine": { "type": "html", "entry": "inline" },
"props": {
"title": { "type": "text", "label": "Title", "default": "Your score" },
"caption": { "type": "text", "label": "Caption", "default": "out of 20" },
"cta": { "type": "text", "label": "Button", "default": "Continue" },
"accent": { "type": "color", "label": "Ring color", "default": "var(--app-color-primary)" },
"showRing": { "type": "boolean", "label": "Show ring", "default": true },
"next": { "type": "action", "label": "On continue", "actions": ["navigate"], "default": "navigate" }
},
"capabilities": {
"reads": ["q_sleep", "q_stress"],
"writes": [{ "name": "score", "type": "number" }],
"events": ["score_shown"]
},
"ssr": "static"
}
</script>
<style>
.card { display: grid; gap: 8px; justify-items: center; padding: 24px;
border-radius: var(--app-border-radius-box); background: rgba(var(--app-color-primary-rgb), .06); }
.ring circle { fill: none; stroke: var(--p-accent); stroke-width: 4; stroke-linecap: round;
transform: rotate(-90deg); transform-origin: center; transition: stroke-dasharray .6s ease-out; }
.value { font-size: 40px; font-weight: 700; color: var(--app-color-text); }
.cta { padding: 12px 20px; border: 0; border-radius: var(--app-border-radius-box);
background: var(--app-color-primary); color: var(--app-color-text-on-primary); font: inherit; }
</style>
<div class="card" data-ff-root>
<h2 data-ff-prop="title"></h2>
<svg class="ring" viewBox="0 0 36 36" width="120" height="120" data-ff-show="showRing"><circle r="16" cx="18" cy="18"></circle></svg>
<strong class="value">0</strong>
<small data-ff-prop="caption"></small>
<button class="cta" data-ff-action="next" data-ff-prop="cta"></button>
</div>
<script>
const value = root.querySelector('.value');
const ring = root.querySelector('.ring circle');
const compute = () => Number(ff.vars.get('q_sleep') ?? 0) + Number(ff.vars.get('q_stress') ?? 0);
function paint() {
const score = compute();
ff.vars.set('score', score); // shown by {{score}} on later screens
value.textContent = String(score);
ring.style.strokeDasharray = `${Math.min(1, score / 20) * 100} 100`;
}
paint();
const offs = [ff.vars.on('q_sleep', paint), ff.vars.on('q_stress', paint), ff.onChange(paint)];
ff.lifecycle.onMount(() => { if (ff.mode.tier === 'live') ff.track('score_shown', { score: compute() }); });
ff.lifecycle.onDestroy(() => offs.forEach((off) => off()));
</script>

">

To test it on the editor canvas, add sample answers to the manifest: "preview": { "vars": { "q_sleep": 8, "q_stress": 6 } }.