How to Open Your Chatbot From Your Own Button (and Keep It Keyboard-Friendly)
A "Chat with us" button in your nav or on your contact page gets more people talking. Here's the one-line snippet, and how to make sure keyboard users can use it too.
By Umar Mirza, founder of ChatBento
Published Updated 7 min read
To open a website chatbot from your own button, add a real <button> element to your page and have it call the chat widget's open function. With ChatBento that's one line: <button type="button" onclick="window.ChatBento && window.ChatBento.open()">Chat with us</button>. Give the button visible text, test it with the Tab key, and keep the chat bubble in the corner as a second way in.
I build ChatBento, and this is one of the most common setup questions I get. Most of the work is in the details: the element you use, its label, and what happens to keyboard focus. A recent support case showed how easily those details go wrong, so I'll cover that too.
Why add your own button?
The chat bubble in the corner works, but people don't always notice it, and it doesn't say what it's for. A button in the page can:
- Sit where the question comes up. "Questions about plans? Ask us" next to your pricing table, or "Chat with us" on your contact page.
- Say what it does. "Ask about delivery" is clearer than an icon.
- Live in your navigation, so it's always one click away on every page.
- Match your design, because it's your button, styled with your site's CSS.
The bubble still matters. Some visitors look for it in the corner out of habit, and it's there on pages where you haven't added a button. ChatBento doesn't have a setting to hide the bubble, and I'd keep it anyway: two ways in are better than one.
The snippet
First, install the chatbot as usual: one script tag before </body>, from your chatbot's Install tab. (The install guides show where it goes on each builder.) Once the widget has loaded, it creates window.ChatBento with three functions:
ChatBento.open()opens the chat.ChatBento.close()closes it.ChatBento.toggle()opens it if it's closed and closes it if it's open.
Then add your button anywhere on the page:
<button type="button" onclick="window.ChatBento && window.ChatBento.open()">
Chat with us
</button>
The window.ChatBento && part matters. The widget loads after your page, so for a moment after the page appears, window.ChatBento doesn't exist yet. The check stops an early click from throwing an error. If you'd rather tell the visitor something when the chat isn't ready, call a small function of your own that shows a message in that case.
Make it a real button
This is where most custom launchers go wrong. Use a <button> element, not a <div> or a <span> with an onclick.
A <button>:
- Is reachable with the Tab key.
- Works with Enter and Space.
- Is announced as a button by screen readers.
A <div onclick="..."> does none of that out of the box. It works with a mouse and silently fails for everyone using a keyboard or a screen reader.
Avoid <a href="#"> for the same reason: it's a link that pretends to be a button, it can jump the page to the top, and it's announced as a link. If it opens something on the page, it's a button.
Give it a clear name
The button's text is its accessible name, so make it say what happens:
- Good: "Chat with us", "Ask a question", "Questions about delivery? Ask us".
- Unclear: "Help", "Click here", or an icon with no text.
If your design calls for an icon-only button, add a label for screen readers:
<button type="button" aria-label="Open chat" onclick="window.ChatBento && window.ChatBento.open()">
<svg aria-hidden="true">…</svg>
</button>
If the button shows an image as well as text, give the image an empty alt="" so screen readers don't read it twice.
Keep it easy to see and hit
A few things from WCAG 2.2 that apply directly:
- Visible focus. Don't remove the focus outline in your CSS. Keyboard users need to see when the button is selected. If your theme's outline is hard to see, style
:focus-visiblewith a clear ring. - Target size. Make it at least 24 by 24 pixels (WCAG 2.2's minimum). On a phone, bigger is kinder.
- Contrast. The text needs 4.5:1 against the button's background, and the button's edge 3:1 against the page.
What happens to focus when the chat opens and closes
You don't have to manage focus yourself.
- When the chat opens, ChatBento moves focus into the message box on devices with a mouse or trackpad, so a keyboard user can start typing straight away. On phones it doesn't, so the on-screen keyboard doesn't jump up uninvited.
- When the chat closes, with Escape or the close button, focus goes back to whatever opened it. If that was your button, the visitor lands back on your button and can carry on through the page.
That second point is newer than it sounds. Until November 6, 2026, closing the chat sent focus back to ChatBento's own bubble. On a site where the bubble wasn't visible, focus had nowhere useful to go, and a keyboard user lost their place. We found it while testing a real site, which brings me to the case.
A real case: the button that wasn't there
A disability-led nonprofit was evaluating ChatBento, and a member of their team tested it with the keyboard only. They'd added their own "Ask" button that called ChatBento.open(), with good styling and a clear label.
On their public pages, it worked: Tab reached the button, Enter opened the chat, and the cursor landed in the message box.
On the pages members see after logging in, the tester couldn't reach the chat at all. The custom button wasn't on those pages. Their site also hid the chat bubble, so there was no way in from the keyboard.
What I took from it:
- Put your button wherever the chatbot loads. If the snippet runs on a page, your way of opening it should be there too. Check templates that work differently, such as member areas, checkout steps and landing-page builders.
- Test logged-in pages, not just the homepage. Log in as a customer or member and repeat the keyboard test.
- Don't take away the bubble. It's the fallback when a custom button is missing from a page.
I covered the wider checklist in Is Your Chat Widget Accessible?.
Adding the button in your site builder
The button is HTML, so you need a place in your builder that accepts custom HTML with an onclick:
- Plain HTML or a framework: put it anywhere in your template. In React-based frameworks, call
window.ChatBento?.open()from anonClickhandler instead of an inline attribute. - Webflow: a Code Embed element. Webflow says it needs a paid site plan or a paid Workspace.
- Squarespace: a Code Block. Squarespace's entry plan doesn't run scripts, so check your plan if the button does nothing.
- WordPress: a Custom HTML block. WordPress removes scripts and onclick attributes when the person saving the page doesn't have the right permission, which can catch editors and some multisite admins. If your button vanishes or stops working after saving, that's the likely cause.
- Framer: an Embed component set to HTML.
Whatever the builder, test on the published site. Some builders don't run custom code in their editor preview. And if a builder places HTML embeds inside an iframe, a button in there can't reach the chat on the main page.
A 2-minute keyboard test
After publishing, on a real page:
- Click in the browser's address bar, then press Tab repeatedly. Does focus reach your button, with a visible outline?
- Press Enter. Does the chat open, with the cursor in the message box?
- Type a question and press Enter to send.
- Press Escape. Does the chat close, with focus back on your button?
- Do the same on one logged-in page and one page that uses a different template.
If any step fails, check the element type first (is it really a <button>?), then whether your builder kept the onclick.
Quick checklist
- Chatbot snippet installed site-wide
- Your button is a
<button type="button"> - It has visible text, or an
aria-labelif it's icon-only - It checks
window.ChatBentoexists before callingopen() - Focus outline visible, target at least 24 by 24 pixels, text contrast 4.5:1
- Present on every template where the chatbot loads, logged-in pages included
- Chat bubble left in place as a second way in
- Tested with the Tab key: open, type, send, Escape
The install guides cover where the snippet goes on each platform, and the Squarespace guide has the Code Injection steps for the snippet itself.