HTML ondblclick Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The ondblclick attribute is an event-handler attribute. It runs JavaScript when the dblclick event fires — the user double-clicks an element (two rapid presses of the pointing device’s primary button on the same target).

dblclick fires after two click events (and after two mousedown / mouseup pairs). Prefer real <button>s for actions, and avoid making critical features double-click-only.

Baseline · Widely available.

Not deprecated and not experimental. The dblclick event is stable across modern browsers since about July 2015.

Accessibility warning.

Double-click is difficult for many users (motor, keyboard, mobile). Offer the same action with a single click or a labeled button when the action matters.

HTML Syntax

syntax.html
<element ondblclick=" script">

script is JavaScript that runs when dblclick fires. Equivalent JS: el.ondblclick = handler or el.addEventListener("dblclick", handler).

Attribute Values

The attribute value is always a script. Common patterns:

Value / patternDescriptionTry it
scriptAny JavaScript run on a double-clickTry it
ondblclick="fn()"Call a named function from the attributeTry it
addEventListener("dblclick")Preferred modern listener; supports multiple handlersTry it
Toggle UICommon pattern: expand/collapse or show/hide on double-clickTry it
vs onclickTwo click events fire before dblclickTry it

Live Preview

Double-click the button. Status shows each dblclick. Single clicks are ignored here on purpose.

Action

Uses a real <button type="button">. Double-click quickly on the same target.

Button

Double-clicks: 0

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Inline ondblclick on a Button

Call a function when the button is double-clicked.

HTML
<button type="button" ondblclick="sayReady()">Double-click me</button>
<p id="msg">Waiting for a double-click…</p>

<script>
  function sayReady() {
    document.getElementById("msg").textContent = "dblclick fired!";
  }
</script>
Try It Yourself

How It Works

  1. Use <button type="button"> so activation does not submit a form.
  2. User double-clicks the primary pointer button quickly.
  3. dblclick fires and ondblclick runs sayReady().
  4. Update the page — here, set a message in a paragraph.

Example 2 — Toggle a Tip with addEventListener

Preferred script pattern: show or hide content on double-click.

HTML
<button type="button" id="card" aria-expanded="false" aria-controls="tip">
  Double-click to toggle tip
</button>
<p id="tip" hidden>Prefer a single-click button for important actions.</p>

<script>
  var btn = document.getElementById("card");
  var tip = document.getElementById("tip");
  btn.addEventListener("dblclick", function () {
    var open = tip.hidden;
    tip.hidden = !open;
    btn.setAttribute("aria-expanded", open ? "true" : "false");
  });
</script>
Try It Yourself

How It Works

  1. Register dblclick with addEventListener.
  2. Toggle hidden on the tip paragraph.
  3. Update aria-expanded for assistive tech.
  4. Still teach a11y: a normal single-click control is usually better for this UX.

Example 3 — click vs dblclick Order

Log both events so you can see two clicks before a double-click.

HTML
<button type="button" id="probe">Click or double-click</button>
<ul id="log"></ul>

<script>
  var btn = document.getElementById("probe");
  var log = document.getElementById("log");

  function add(line) {
    var li = document.createElement("li");
    li.textContent = line;
    log.appendChild(li);
  }

  btn.addEventListener("click", function () {
    add("click");
  });
  btn.addEventListener("dblclick", function () {
    add("dblclick");
  });
</script>
Try It Yourself

How It Works

  1. Single click logs one click.
  2. Double-click logs click, click, then dblclick.
  3. Design carefully — if both handlers do different jobs, a double-click also runs the click handler twice.
  4. Prefer one clear gesture for primary actions.

Edge Cases & Pitfalls

Most issues are accessibility, accidental double click side effects, or assuming touch has dblclick.

a11y

Do not hide critical actions behind double-click

Provide a single-click or keyboard-friendly control for anything important.

order

Two clicks come first

A double-click triggers two click handlers before dblclick. Avoid conflicting logic in both.

touch

Touch is unreliable for dblclick

Double-tap ≠ desktop double-click everywhere. Design mobile UX around single taps.

select

Text selection side effect

Double-clicking text often selects a word. On custom cards, consider user-select: none only when it does not hurt readability.

forms

Use type="button" in forms

A bare <button> inside a form defaults to submit. Set type="button" for non-submit actions.

Browser Support

ondblclick is an HTML event-handler attribute in the browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

ondblclick

Widely available since about July 2015. Desktop browsers support dblclick well; treat touch double-tap as a separate, less reliable gesture.

98% Global support (approx.)
Google Chrome 1+
Full support
Mozilla Firefox 1+
Full support
Apple Safari 1+
Full support
Microsoft Edge 12+
Full support
Opera All
Full support
Samsung Internet Modern · Full
Full support
Internet Explorer All
Supported
ondblclick Widely supported

Bottom line: Safe to use for optional desktop gestures. Prefer single-click primary actions, and use addEventListener in production.

Key Takeaways

  • Role: run script when the user double-clicks an element.
  • Order: two clicks, then dblclick.
  • A11y: do not require double-click for essential actions.
  • Apps: prefer addEventListener("dblclick", …).

One line: ondblclick is for a rapid second click — teach it, but keep primary actions on a single click.

Frequently Asked Questions

It is an event-handler attribute. When the user double-clicks an element with a pointing device (two rapid primary-button clicks), the dblclick event fires and the JavaScript in ondblclick runs.
onclick fires on each single activation. ondblclick fires after two clicks in a short time. A double-click also produces two click events before dblclick.
Double-tap is not the same as dblclick on all devices. Many touch UIs do not expose a reliable double-click. Prefer a clear single-tap control for important actions.
Often not ideal. Double-click is hard for many keyboard, motor, and mobile users. Offer the same action with a single click or an explicit button when the action matters.
Both work. For learning, ondblclick in HTML is fine. In production code, prefer element.addEventListener("dblclick", handler).
No. The dblclick event and ondblclick handler are standard and Baseline widely available since about July 2015.

Next: ondrag

Run JavaScript while an element is being dragged.

ondrag tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful