JavaScript Document queryCommandSupported() Method

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Deprecated
Non-standard
Instance method

What You’ll Learn

document.queryCommandSupported() is a deprecated, non-standard instance method that reports whether a named editor command exists in the browser (see MDN Document: queryCommandSupported()). Learn the boolean return value, the MDN SelectAll pattern, paste privilege notes, how it differs from queryCommandEnabled() and queryCommandState(), and five try-it labs.

01

Kind

Instance method

02

Args

command string

03

Returns

boolean

04

Pairs with

execCommand

05

Status

Deprecated

06

Also

Non-standard

Introduction

Before a legacy toolbar offers bold or SelectAll, it often asks: “Does this browser even know that command?” document.queryCommandSupported() answers that question.

MDN: the method reports whether or not the specified editor command is supported by the browser. If you still use deprecated execCommand(), MDN suggests checking with queryCommandSupported() for compatibility.

💡
Think: “Does this browser know the command?”

1) Pick a command name (e.g. "SelectAll")
2) Call document.queryCommandSupported(command)
3) If true, optionally run execCommand / further checks
4) Remember paste can be false for privilege reasons (MDN)

Related tutorials: execCommand(), queryCommandEnabled(), queryCommandState(), designMode.

Understanding document.queryCommandSupported()

An instance method on the page’s document object that probes whether a named editing/clipboard command is supported (MDN).

  • command — string naming the command to check (MDN).
  • Return valuetrue if supported, false otherwise (MDN).
  • Pairs with — deprecated document.execCommand() (MDN note).
  • paste — MDN: false when unavailable or when privileges are insufficient.
  • vs enabled — supported = browser knows it; enabled = usable right now.
  • vs state — state = already applied to the selection.

📝 Syntax

General form of Document.queryCommandSupported (MDN):

JavaScript
queryCommandSupported(command)

Parameters

  • command — the command for which to determine support (MDN). Examples: "SelectAll", "bold", "insertText", "copy", "paste".

Return value

A boolean that is true if the command is supported and false if it is not (MDN).

MDN Notes (paste)

  • The "paste" command returns false not only if unavailable, but also if the calling script has insufficient privileges (MDN).

MDN-style support check

JavaScript
const flg = document.queryCommandSupported("SelectAll");

if (flg) {
  // Do something… e.g. document.execCommand("SelectAll", false, null)
}

⚡ Quick Reference

GoalCode
Check SelectAlldocument.queryCommandSupported("SelectAll")
Gate a commandif (document.queryCommandSupported("bold")) { … }
Can I run it now?document.queryCommandEnabled("bold")
Is it applied?document.queryCommandState("bold")
Feature-detect methodtypeof document.queryCommandSupported === "function"
MDN statusDeprecated & Non-standard

🔍 At a Glance

Four facts about document.queryCommandSupported().

Returns
boolean

supported?

Arg
command

string

paste
privileges

MDN note

Status
Deprecated

+ Non-standard

📋 Supported vs Enabled

queryCommandSupportedqueryCommandEnabled
MeaningExists in this browser?Can run now?
Clipboard nuancepaste may be false for privileges (MDN)cut/copy need user thread (MDN)
Typical useHide unsupported toolbar actionsDisable buttons that cannot run yet
StatusDeprecated & Non-standardSame legacy family

Examples Gallery

Examples follow MDN Document: queryCommandSupported() and practical beginner patterns. Always treat this API as legacy.

📚 Getting Started

MDN’s core pattern: check support, then act.

Example 1 — MDN: check SelectAll

Only proceed when the browser reports the command as supported.

JavaScript
const flg = document.queryCommandSupported("SelectAll");
console.log("SelectAll supported:", flg);

if (flg) {
  console.log("Safe to call execCommand(\"SelectAll\") in legacy UI");
}
Try It Yourself

How It Works

This is MDN’s documented example. Pair it with execCommand() only when you must maintain legacy editing code.

Example 2 — Feature-detect the method itself

Guard against engines that remove legacy editing APIs.

JavaScript
const hasApi = typeof document.queryCommandSupported === "function";
console.log("queryCommandSupported available:", hasApi);

if (hasApi) {
  console.log("bold supported:", document.queryCommandSupported("bold"));
} else {
  console.log("Use a modern editor / Clipboard API instead");
}
Try It Yourself

How It Works

Deprecated APIs can disappear. Always feature-detect before calling, then prefer modern alternatives for new work.

📈 Practical Patterns

Capability reports, paste caveats, and the full queryCommand trio.

Example 3 — Report several commands

Build a quick support matrix for common toolbar actions.

JavaScript
const commands = ["bold", "insertText", "SelectAll", "copy", "paste"];
const report = commands.map((name) => {
  const supported =
    typeof document.queryCommandSupported === "function"
      ? document.queryCommandSupported(name)
      : false;
  return name + ": " + (supported ? "yes" : "no");
});
console.log(report.join("\n"));
Try It Yourself

How It Works

Support is uneven — especially for clipboard commands. Hide unsupported buttons instead of offering dead UI.

Example 4 — MDN note for paste

false may mean missing support or insufficient privileges.

JavaScript
const pasteSupported =
  typeof document.queryCommandSupported === "function"
    ? document.queryCommandSupported("paste")
    : false;

console.log("paste supported:", pasteSupported);
if (!pasteSupported) {
  console.log(
    "MDN: false can mean unavailable OR insufficient privileges"
  );
  console.log("Prefer navigator.clipboard.readText() for new apps");
}
Try It Yourself

How It Works

For new clipboard UX, skip legacy paste commands and use the Clipboard API instead.

Example 5 — Supported vs enabled vs state

Compare all three probes for the same command names.

JavaScript
const names = ["bold", "SelectAll", "copy", "paste"];
const lines = names.map((name) => {
  const supported =
    typeof document.queryCommandSupported === "function"
      ? document.queryCommandSupported(name)
      : false;
  const enabled =
    typeof document.queryCommandEnabled === "function"
      ? document.queryCommandEnabled(name)
      : false;
  const state =
    typeof document.queryCommandState === "function"
      ? document.queryCommandState(name)
      : null;
  return (
    name +
    " → supported=" + supported +
    ", enabled=" + enabled +
    ", state=" + state
  );
});
console.log(lines.join("\n"));
Try It Yourself

How It Works

A command can be supported yet not enabled, or enabled yet not applied (state=false). See queryCommandEnabled() and queryCommandState().

🚀 Common Use Cases

  • Legacy toolbar capability checks — hide unsupported commands (MDN).
  • Safe execCommand gate — MDN: check support before running a deprecated command.
  • Maintaining old editors — explain why paste / clipboard actions disappear.
  • Interview / history knowledge — supported vs enabled vs state.
  • Not new clipboard UX — use the Clipboard API instead.
  • Not a modern editor foundation — prefer dedicated libraries for new products.

🧠 How queryCommandSupported() Works

1

Choose a command name

Pass a string such as "SelectAll", "bold", or "paste" (MDN).

command
2

Browser answers support

Engines report whether they implement that editor command (MDN).

Capability
3

Return a boolean

true means supported; false means not (MDN). Paste may also fail on privileges.

boolean
4

Optionally call execCommand

MDN suggests this check when you still use deprecated execCommand. Prefer modern APIs when possible.

📝 Notes

  • MDN: Deprecated and Non-standard; not part of any current specification.
  • MDN: if you still use execCommand(), consider queryCommandSupported() for compatibility checks.
  • MDN: paste can return false for privilege reasons, not only missing support.
  • Do not confuse “supported” with “enabled” or “state”.
  • Support matrices still vary by engine — always verify in your target browsers.
  • Related: execCommand(), queryCommandEnabled(), queryCommandState(), designMode.

Legacy Browser Support

Document.queryCommandSupported() is Deprecated and Non-standard on MDN (not part of any current specification). Logos use the shared browser-image-sprite.png sprite from this project. Still present in many engines for legacy editing, but do not build new products on it.

Deprecated · Non-standard

Document.queryCommandSupported()

Legacy support probe for editor commands — still seen with old toolbars; prefer modern editors and the Clipboard API.

Legacy Not for new apps
Google Chrome Legacy editing probe still present — avoid for new apps
Legacy
Mozilla Firefox Legacy path; paste often restricted — avoid for new apps
Legacy
Apple Safari Legacy editing support; verify each command
Legacy
Microsoft Edge Chromium legacy path — avoid for new code
Legacy
Opera Follow Chromium legacy behavior
Legacy
Internet Explorer Historic rich-text path only
Legacy
queryCommandSupported() Avoid

Bottom line: Learn it for legacy execCommand toolbars and interviews. For new clipboard and rich-text UX, prefer modern APIs and editor libraries.

Conclusion

document.queryCommandSupported(command) returns a boolean telling you whether a legacy editor command exists in the browser. MDN marks it deprecated and non-standard. Use it only when maintaining execCommand-based UIs; for new apps, choose modern editors and the Clipboard API.

Continue with querySelector(), exitFullscreen(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect typeof document.queryCommandSupported === "function"
  • Check support before calling legacy execCommand (MDN)
  • Treat paste false as possibly a privilege issue (MDN)
  • Prefer the Clipboard API for new copy / paste UX
  • Compare with enabled and state when debugging toolbars

❌ Don’t

  • Build a new rich-text product on queryCommand* + execCommand
  • Assume supported means enabled or already applied
  • Treat paste: false as “unsupported only”
  • Skip browser testing — command matrices differ
  • Ignore that the whole editing command family is non-standard

Key Takeaways

Knowledge Unlocked

Five things to remember about queryCommandSupported()

Legacy support probe for editor commands — know it, rarely ship it.

5
Core concepts
⚠️02

Status

Deprecated

MDN
🛡03

Also

Non-standard

MDN
📋04

Pairs with

execCommand

legacy
📋05

paste

privileges

MDN note

❓ Frequently Asked Questions

MDN: Document.queryCommandSupported() reports whether or not the specified editor command is supported by the browser. It returns true if supported and false if not.
Yes. MDN marks Document.queryCommandSupported() as Deprecated and Non-standard. It is not part of any current specification and is no longer on track to become a standard.
MDN: if you still use deprecated execCommand() for a rare reason, consider checking the command with queryCommandSupported() to ensure compatibility. Prefer modern APIs for new products.
queryCommandSupported() asks whether the browser knows the command at all. queryCommandEnabled() asks whether that command is currently enabled (for example, cut/copy often need a user-initiated thread).
queryCommandState() asks whether the command’s formatting is already applied to the current selection (true, false, or null). queryCommandSupported() only asks about browser support.
MDN: the paste command returns false not only if the feature is unavailable, but also if the script calling it has insufficient privileges to perform the action.
Did you know?

MDN pairs this method with deprecated execCommand() the same way it pairs queryCommandEnabled(): if you still call execCommand, check support first. Supported asks “does it exist?”; enabled asks “can I run it now?”

Next: querySelector()

Learn how Document.querySelector() finds the first Element matching a CSS selector.

querySelector() →

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.

6 people found this page helpful