Add Docs Embed to any website with a simple script tag
The quickest way to add Docs Embed to your website or app is by adding it through a "standalone" script tag. Every docs site in GitBook includes a ready-to-use script for embedding your docs as a widget.
Steps
1
Get your embed script URL
Navigate to your docs site's Settings → AI & MCP tab and copy the script URL, or use the script at https://docs.company.com/~gitbook/embed/script.js (replace docs.company.com with your actual docs site URL).
2
Add the script tag to your HTML
Place this code in your HTML <head> or before the closing </body> tag:
Update docs.company.com with your actual docs site URL.
4
Test the widget
Load your page. The embed widget should appear in the bottom-right corner.
5
Optionally configure the embed
Add customization options before calling show():
<scriptsrc="https://docs.company.com/~gitbook/embed/script.js"></script><script>window.GitBook('init', { siteURL: 'https://docs.company.com' });window.GitBook('configure', {button: {label: 'Ask',icon: 'assistant'// 'assistant' | 'sparkle' | 'help' | 'book' },tabs: ['assistant', 'docs'],actions: [ {icon: 'circle-question',label: 'Contact Support',onClick: () =>window.open('https://support.example.com', '_blank') } ],greeting: { title: 'Welcome!', subtitle: 'How can I help?' },suggestions: ['What is GitBook?', 'How do I get started?'] });window.GitBook('show');</script>
6
Control widget visibility
Use the API to show, hide, open, or close the embed:
<script> // Show the widgetwindow.GitBook("show"); // Hide the widgetwindow.GitBook("hide"); // Open the embed windowwindow.GitBook("open"); // Close the embed windowwindow.GitBook("close"); // Toggle the embed windowwindow.GitBook("toggle");</script>
7
Navigate and interact programmatically
Use the API to navigate to pages, switch tabs, or post messages:
<script> // Navigate to a specific page in the docs tabwindow.GitBook('navigateToPage', '/getting-started'); // Switch to the assistant tabwindow.GitBook('navigateToAssistant'); // Post a message to the chatwindow.GitBook('postUserMessage', 'How do I get started?'); // Clear chat historywindow.GitBook('clearChat');</script>
8
Load dynamically (optional)
For authenticated docs or conditional loading, inject the script at runtime:
Configure the widget button that launches the embed (standalone script only). This allows you to customize the label and icon of the button that appears in the bottom-right corner of your page.
icon: 'assistant' | 'sparkle' | 'help' | 'book' - The icon displayed on the button
assistant - Assistant icon
sparkle - Sparkle icon
help - Help/question icon
book - Book icon
Example:
Note: This option is only available when using the standalone script tag implementation. For React or Node.js implementations, you'll need to create your own button to trigger the embed.
unsignedClaims: Record<string, unknown> (optional) - Unsigned claims for dynamic expressions
Common pitfalls
Script URL is incorrect – Ensure you're using your actual docs URL, not the example docs.company.com.
Calling GitBook before script loads – Wrap API calls in script.onload or place them after the script tag.
Authenticated docs not accessible – If your docs require sign-in, you must provide the visitor.token when initializing. See Using with authenticated docs.
CORS or CSP errors – Ensure your site's Content Security Policy allows loading scripts and iframes from your GitBook domain.
Widget not visible – Check z-index conflicts with other elements on your page. The widget uses a high z-index by default.
Forgetting to initialize – Make sure to call GitBook('init', { siteURL: '...' }) before using other methods.