How to fix a div used as a button (accessibility)
A div that is styled and wired up to act like a button usually cannot be reached with the Tab key or used with Enter and Space, and screen readers do not call it a button. The fix is almost always to replace it with a real <button> element.
Sometimes a button on a web page is not really a button. A developer or a page builder has made a plain box (a div) look like a button and attached a click action to it. Mouse users never notice. People who use a keyboard or a screen reader often cannot use it at all.
What the problem looks like
On screen everything seems fine: a styled box that says 'Add to cart', 'Open menu' or 'Send'. In the page code it looks like this:
<div class='btn' onclick='addToCart()'>Add to cart</div>
The browser treats this as a generic box that happens to react to mouse clicks. In practice that means:
- The Tab key skips it, so keyboard users cannot reach it.
- Even if something focuses it, Enter and Space do nothing.
- A screen reader reads it as plain text, not as a button, so the person does not know it can be pressed.
- Voice control tools may not list it as something you can click.
Why it matters
This problem breaks two WCAG 2.2 success criteria: 2.1.1 Keyboard (everything must work without a mouse) and 4.1.2 Name, Role, Value (controls must tell assistive technology what they are). WCAG is the standard that most accessibility laws and customer requirements point to.
The business effect is simple. If the broken control is Add to cart, Checkout, a menu toggle or the Send button on your contact form, some visitors cannot buy from you or reach you. Keyboard use is common among people with motor disabilities, people with a temporary injury, and people who just prefer it.
There is a search angle too when the div is meant to go to another page. Search engines follow real links (an <a> tag with an href), not click handlers on boxes, so those pages may be harder for them to discover.
How to check your own site (free)
- Keyboard test. Put the mouse aside and press Tab from the top of the page. Can you reach every button-like item? Can you see which one is selected (an outline or highlight)? Press Enter and Space on each. If something you can click with a mouse cannot be reached or does nothing, you have found it.
- Inspect the element. Right click the button, choose Inspect, and look at the tag. If it is a
divorspanwith a click action and norole='button', that is the problem. In Chrome DevTools, the Accessibility tab shows the role as generic instead of button. - Automated tools. Lighthouse (built into Chrome DevTools), the axe DevTools browser extension and WAVE are all free. They catch many issues, but they often miss click-only divs because they cannot always see what the page scripts are listening for. A clean report does not prove the keyboard test would pass.
- Screen reader. VoiceOver is built into Mac and iPhone, TalkBack into Android, and NVDA is a free download for Windows. A real button is announced as 'button' along with its name.
How to fix it in general
The best fix is to use the element made for the job:
<button type='button' class='btn' onclick='addToCart()'>Add to cart</button>
A real button gets keyboard focus, responds to Enter and Space, and is announced as a button, all without extra code. Two practical notes:
- Buttons come with default browser styling. To keep your design, reset it in your CSS with
background: none,border: 0,font: inheritandcolor: inherit, then apply your own styles. - Add
type='button'unless it is meant to submit a form. Inside a form, a button without a type acts as a submit button.
If the thing takes people to another page, use a link instead: <a href='/pricing'>Pricing</a>. Buttons do actions, links go places.
If you truly cannot change the element (for example a third-party widget or a builder limitation), the backup plan is to add what the browser would have given you:
role='button'so it is announced correctly.tabindex='0'so the Tab key can reach it.- A keyboard handler that runs the same action on Enter and Space (and stops Space from scrolling the page).
- A visible focus style, for example with
:focus-visible. aria-disabled='true'(plus blocking the action) if it should look and act disabled.
This works but it is more code and easier to get wrong, so treat it as second best. Also make sure the button has a name: visible text is best. If it only shows an icon, see icon buttons with no label.
Fixing it on common platforms
Where you make the change depends on how the site is built, and menu names vary by version and theme.
- React and Next.js: replace
<div onClick={...}>with<button type='button' onClick={...}>. For navigation, use a link (in Next.js, theLinkcomponent renders a real anchor). See the React guide. - WordPress: the culprit is usually the theme, a plugin or a Custom HTML block. Fix Custom HTML in the block editor, theme code in a child theme (so updates do not overwrite it), and report plugin problems to the plugin author. See the WordPress guide.
- Shopify: buttons live in theme files, usually under
sectionsorsnippets(Online Store, Themes, Edit code). Duplicate the theme first and test on the copy. - Webflow: a Div Block with a click interaction is the usual cause. Use a Button or Link Block element instead. Custom attributes can add
roleandtabindexif you must keep the div. - Elementor: a container or column made clickable can cause it. Use the Button widget where you can. Some versions also offer a link setting on containers, which is better than a click script.
- Wix: use the Button element from the Add panel instead of a clickable box or strip. Options vary by editor, so check what your version offers.
How to confirm the fix worked
- Repeat the keyboard test: Tab reaches the button, a visible outline shows, and both Enter and Space trigger it.
- Inspect it again. The tag should be
button(or a link), and the Accessibility tab should say button. - Listen with a screen reader. It should say the name followed by 'button'.
- Run Lighthouse or axe again, and test on a phone too, because mobile menus are a frequent source.
How to stop it coming back
- Put one line in your build or review checklist: no click actions on
divorspanelements. - If your developers use React, the
eslint-plugin-jsx-a11ylinting plugin has rules such asclick-events-have-key-eventsandno-static-element-interactionsthat flag this automatically. - Do a quick Tab-key pass before publishing any new page or template.
- Tell whoever edits pages in your builder to use the Button widget or element, not a clickable box.
- Re-check after theme, plugin or app updates, since they can change markup you did not write.
SiteMonday's week 7 accessibility audit (WCAG 2.2) looks for this pattern on your site and ends with a written report and a ranked fix list. Making the change is up to you or your developer.
Step by step for your platform
- Clickable div acting as button without role on React
- Clickable div acting as button without role on Next.js
- Clickable div acting as button without role on WordPress
- Clickable div acting as button without role on Shopify
- Clickable div acting as button without role on Webflow
- Clickable div acting as button without role on Elementor
- Clickable div acting as button without role on Wix
Questions
Why can't I just add an onclick to a div?
You can, but only mouse and touch users benefit. A div cannot be reached with Tab, does not respond to Enter or Space, and is not announced as a button, so you would have to rebuild all of that yourself.
Is role='button' on a div enough?
No. It only changes how screen readers describe the element. You also need `tabindex='0'`, Enter and Space handling and a visible focus style, which is why a real `<button>` is better.
Will a button element ruin my design?
No. Buttons accept any CSS. Reset the default background, border and font, then style it the way your div was styled.
When should I use a link instead of a button?
Use a link (`<a href>`) when the action takes the visitor to another page or place. Use a button when it does something on the current page, like adding to cart, opening a menu or submitting a form.
Do accessibility checkers always find this problem?
Not always. Many tools cannot see click handlers added by scripts, so they may report nothing. The keyboard test is the most reliable quick check.
Does this affect SEO?
Not directly as a ranking factor, but if a clickable div is the only way to reach a page, search engines may not follow it. A real link with an `href` avoids that.