Skip to Content
WidgetReferenceAttributes

Attributes

This page lists every script-tag attribute the CDN widget reads and the matching npm option where one exists.

Only data-project-id is required. Invalid enum, language, and hex color values are ignored with a console warning.

Identity

Script attributenpm optionTypeDefault
data-project-idprojectIdUUIDRequired

Behavior

Script attributenpm optionTypeDefault
data-themethemeauto, light, darkauto
data-languagelanguageen, tr, de, es, fr, it, pt, nl, ja, ko, zh, ru, csBrowser-detected, then en
data-layoutlayoutmodal, overlay, pushmodal
data-open-selectoropenSelectorCSS selectorNone
data-modemodechat, deflectorchat
data-form-selectorformSelectorCSS selectorRequired for deflector mode
data-subject-selectorsubjectSelectorCSS selectorNone
data-body-selectorbodySelectorCSS selectorNone

data-open-selector binds clicks on matching elements. It also watches the DOM, so triggers rendered later by React, Vue, Docusaurus, VitePress, or another client router still work.

data-mode="deflector" turns the widget into a support form deflector. It requires Business or above and data-form-selector. See Support form deflector.

Launcher

Script attributenpm optionTypeDefault
data-launcher-alignlauncherAlignbottom-right, bottom-leftbottom-right
data-launcher-hiddenlauncherHiddentrue, falsefalse
data-launcher-textlauncherTextTextAsk Docs
data-launcher-subtitlelauncherSubtitleTextEmpty
data-launcher-iconlauncherIconBuilt-in icon namebook-open
data-launcher-stylelauncherStylepill, cardpill
data-launcher-icon-positionlauncherIconPositionleft, rightright
data-launcher-show-iconlauncherShowIcontrue, falsetrue

The default launcher is the compact pill style with Ask Docs and the book-open icon.

The legacy card style displays two lines. If you switch to card without overriding copy, the visual fallback is Need help? and Ask AI; explicit data-launcher-text and data-launcher-subtitle always win.

Copy

Script attributenpm optionTypeDefault
data-greetinggreetingTextEmpty
data-suggested-questionssuggestedQuestionsComma-separated text, optional `icon-name. Escape ,,

Example:

data-suggested-questions="Get started|rocket,API reference|code,Pricing|card"

Questions containing commas or | in the script tag must escape them (\,, \|). The dashboard snippet does this automatically. Or use the npm object form:

suggestedQuestions: [ { text: 'Install, configure, and verify the widget', icon: 'rocket' }, 'How does pricing work?', ]

Colors

Script attributenpm optionTypeDefault
data-primary-colorprimaryColor#RRGGBBSets light and dark together
data-primary-color-lightprimaryColorLight#RRGGBB#171717
data-primary-color-darkprimaryColorDark#RRGGBB#d4d4d4

Primary colors affect the launcher, submit button, and focus states. For per-slot styling, use Component styles.

Script attributenpm optionTypeDefault
data-consent-requiredconsent.requiredtrue, falsefalse
data-consent-titleconsent.titleTextLanguage default
data-consent-disclaimerconsent.disclaimerTextLanguage default
data-consent-accept-textconsent.acceptTextTextLanguage default
data-consent-reject-textconsent.rejectTextTextLanguage default

When consent is required, Knoku.ask(question) opens the consent screen first and submits the held question after the visitor accepts.

Component styles

Per-slot style overrides use this pattern:

data-{slot}-{property} data-{slot}-{state}-{property} data-{slot}-{property}-dark data-{slot}-{state}-{property}-dark

See Component styles for all slots and allowed CSS properties.

npm-only options

These options exist on initKnokuWidget() but are not parsed from the CDN script tag:

npm optionPurpose
apiUrlOverride the API origin, usually for local development
hostIdOverride the generated widget host element ID
primaryDomainOverride the source-link base used by citations
preview / previewSurfaceDashboard preview mode

Example

import { initKnokuWidget } from '@knoku/widget' await initKnokuWidget({ projectId: 'YOUR_PROJECT_ID', theme: 'auto', language: 'en', layout: 'modal', greeting: 'How can I help?', launcherText: 'Ask Docs', launcherStyle: 'pill', launcherIcon: 'book-open', openSelector: '#ask-ai', suggestedQuestions: [ { text: 'Get started', icon: 'rocket' }, { text: 'API reference', icon: 'code' }, ], consent: { required: true, title: 'Use the AI assistant?', }, componentStyles: { 'panel-header': { 'background-color': '#ffffff' }, 'panel-header:dark': { 'background-color': '#020617' }, }, })
Last updated on