Tour Steps
At the core of every Cue.js tour is an array of step objects. Each object in this array defines a single point in your guided experience: what element to highlight, what message to show, and how it behaves.
Understanding these step properties is crucial for building effective and dynamic tours.
The Anatomy of a Tour Step
A basic tour step is a JavaScript object that you pass within an array to the cue.setSteps() method.
const myTour = new Cue();
myTour.setSteps([
{
// Properties of the first step object
target: '#my-element-id',
title: 'Step 1 Title',
content: 'This is the description for step 1.',
position: 'bottom'
},
{
// Properties of the second step object
target: '.another-element-class',
title: 'Step 2 Title',
content: 'More details here.',
position: 'right'
}
]);1. target (Required)
target (Required)The most fundamental property. This tells Cue.js what element on your page this step is about.
Type:
string(CSS Selector) orHTMLElementDescription:
If a
string, it must be a valid CSS selector (e.g.,"#myId",".myClass","div[data-attribute='value']"). Cue.js will usedocument.querySelector()to find this element.If an
HTMLElement, you can pass a direct reference to a DOM element you've already obtained (e.g.,document.getElementById('myId')).
Technical Consideration: When using a string selector, Cue.js re-queries the DOM for the
targetelement before displaying each step. This is powerful for dynamic content, as the element doesn't need to exist when you initially callsetSteps(), but it must be present in the DOM by the time its step is about to be shown.
Tip: For reliable targeting, especially when elements might load asynchronously or appear later, use unique IDs. If IDs aren't feasible, ensure your CSS selectors are robust and don't match unintended elements.
2. title (Optional)
title (Optional)Type:
stringDescription: A concise heading that appears at the top of the tour step's tooltip. Use it to quickly summarize the purpose of the step.
3. content (Optional)
content (Optional)Type:
stringDescription: The main body text of the tour step's tooltip. Use this to provide detailed instructions, explanations, or context. Basic HTML (like
<strong>,<em>,<br>) can be included to format your text.
4. position (Optional)
position (Optional)Controls where the tooltip appears relative to its target element.
Type:
stringDefault:
'auto'(or the globaltooltipPositionoption)Values:
'top': Tooltip appears above the target.'bottom': Tooltip appears below the target.'left': Tooltip appears to the left of the target.'right': Tooltip appears to the right of the target.'center': Tooltip appears in the center of the viewport (useful for general announcements, not tied to a specific element).'auto': Cue.js will intelligently try to find the best available position (prioritizingbottom, thentop, thenright, thenleft) to ensure the tooltip is fully visible within the current viewport.
5. padding (Optional)
padding (Optional)Adjusts the space around the highlighted target element.
Type:
numberDefault:
10(pixels) (or the globalpaddingoption)Description: Controls the padding between the
targetelement and the highlight border. A larger number increases the space.
6. scrollToElement (Optional)
scrollToElement (Optional)Determines if the page should automatically scroll to make the target visible.
Type:
booleanDefault:
true(or the globalscrollToElementoption)Description: If
true, Cue.js will smoothly scroll the page to ensure thetargetelement is in the viewport and properly centered (vertically). Set tofalseif you want to manage scrolling yourself or if the element is always visible.
7. disableInteraction (Optional)
disableInteraction (Optional)Prevents user interaction with the highlighted element during the step.
Type:
booleanDefault:
falseDescription: If
true, thetargetelement will become non-interactive (clicks, hovers, inputs will be disabled). This is useful for "read-only" steps where you want the user to absorb information without accidentally activating the element. The overlay click-to-exit functionality remains active unless disabled globally.
8. showButtons (Optional)
showButtons (Optional)Overrides the global setting for displaying navigation buttons on a specific step.
Type:
booleanDefault:
true(or the globalshowButtonsoption)Description: If
false, the "Next", "Back", "Skip", and "Done" buttons will not appear in the tooltip for this step. You would typically use this if you want to implement custom navigation logic or require a specific user action on thetargetto proceed.
9. preStep (Optional)
preStep (Optional)A callback function executed before a step is displayed.
Type:
Function(asyncfunction supported)Description: This function runs just before the highlight and tooltip for the step appear. It's incredibly powerful for:
Showing/Hiding elements: Making a hidden element visible.
Opening/Closing menus: Navigating to a different state of your UI.
Fetching data: Waiting for asynchronous operations to complete.
Animations: Starting an animation that prepares the target.
Arguments: Receives the
stepobject as an argument.Asynchronous Support: You can define
preStepas anasyncfunction. Cue.js will wait for thePromiseto resolve before displaying the step.
10. postStep (Optional)
postStep (Optional)A callback function executed after a step is hidden.
Type:
Function(asyncfunction supported)Description: This function runs after the user has left the current step (either by navigating to the next/previous step, skipping the tour, or completing it). It's useful for:
Cleaning up UI: Hiding elements revealed by
preStep.Resetting state: Closing open menus or modals.
Tracking: Logging that a user passed this specific step.
Arguments: Receives the
stepobject as an argument.Asynchronous Support: Can also be an
asyncfunction.
11. onTargetNotFound (Optional)
onTargetNotFound (Optional)A callback function for handling cases where a step's target element is missing.
Type:
FunctionDescription: If Cue.js cannot find the element specified by
targetfor a step, this function will be called. This prevents the tour from abruptly stopping if an element is missing (e.g., due to dynamic content not loading, or a user permission preventing its display).Arguments: Receives the
stepobject as an argument.Return Value:
Return
'skip'to automatically skip the current step and proceed to the next one.Return
'stop'to stop the tour gracefully at this point.If nothing is returned, the tour will stop by default (equivalent to
'stop').
Putting It All Together: A Comprehensive Step Example
Here's an example combining several properties for a more complex tour step:
Next Steps
Now that you're familiar with defining individual tour steps, let's explore how to customize the visual appearance of your tours.
Last updated