JavaScript Document queryCommandSupported() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

document.queryCommandSupported(command) returns a boolean: whether the browser supports a named editor command at all. It belongs to the legacy execCommand family and does not run the command itself.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call document.queryCommandSupported. Start with this line.

JavaScript
document.queryCommandSupported(command)
CallWhat it does
document.queryCommandSupported(command)Primary signature.
document.queryCommandSupported(...)Call with the arguments your case needs.

Built into the browser. Call queryCommandSupported(...) on document — no import required.

Library declarations
JavaScript
document.queryCommandSupported(command)

Parameters

ParameterDescription
commandRequired. Editor command name to probe

Return Value

Return ValueDescription
*true if supported, else false

JavaScript Examples

Example 1 — Check SelectAll Support

MDN pattern: only continue when the command is supported.

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

if (flg) {
  console.log("Safe to consider SelectAll in this browser");
}
Try It Yourself

How It Works

  1. Ask about support. queryCommandSupported("SelectAll") returns a boolean.
  2. Log the result. Useful when comparing browsers or debugging a toolbar.
  3. Gate the feature. Only treat SelectAll as available when flg is true.
  4. Remember status. This is legacy — prefer modern APIs for new products.

Example 2 — Feature-Detect Before Calling

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

  1. Test the method. typeof … === "function" avoids a crash if the API is gone.
  2. Probe a command. When present, check something common like "bold".
  3. Plan a fallback. If missing, point code at modern editor / clipboard APIs.
  4. Why it matters. Deprecated APIs can shrink — detect before you depend on them.

Example 3 — Supported vs Enabled

A command can be supported yet not enabled in the current context.

JavaScript
const names = ["bold", "SelectAll", "copy", "paste"];

names.forEach((name) => {
  const supported =
    typeof document.queryCommandSupported === "function"
      ? document.queryCommandSupported(name)
      : false;
  const enabled =
    typeof document.queryCommandEnabled === "function"
      ? document.queryCommandEnabled(name)
      : false;
  console.log(name + " → supported=" + supported + ", enabled=" + enabled);
});
Try It Yourself

How It Works

  1. List commands. Mix formatting and clipboard names for a clear contrast.
  2. Ask “supported?” Does the browser know this command at all?
  3. Ask “enabled?” Can it run now? Clipboard answers often differ.
  4. Rule of thumb. Hide unknown commands with supported; grey out with enabled.

Browser Support

Document.queryCommandSupported() is a legacy browser DOM API. MDN marks it Deprecated and Non-standard (not part of any current specification).

✓ Deprecated · Non-standard

Document.queryCommandSupported()

Legacy capability probe for editor commands — still present in many engines; avoid for new apps.

Legacy Not for new apps
Google Chrome Legacy editing probe
Legacy
Microsoft Edge Legacy editing probe
Legacy
Mozilla Firefox Legacy editing probe
Legacy
Apple Safari Legacy editing probe
Legacy
Opera Follow Chromium legacy path
Legacy
Internet Explorer Historic rich-text path
Legacy
queryCommandSupported() Avoid for new code

Bottom line: Widely present for legacy editing, but do not build new products on it. Prefer modern editors and the Clipboard API. See the MDN Document.queryCommandSupported() reference.

Frequently Asked Questions

It reports whether a named editor command is supported by the browser. It returns true if supported and false if not. It does not run the command.
Yes. MDN marks it Deprecated and Non-standard. It is not part of any current specification and is no longer on track to become a standard.
Only when maintaining legacy execCommand() UIs. MDN says if you still call execCommand for a rare reason, consider checking with queryCommandSupported() first. Prefer modern APIs for new work.
queryCommandSupported() asks whether the browser knows the command at all. queryCommandEnabled() asks whether that command can run right now (focus, selection, and user-gesture rules matter).
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: paste returns false not only when the feature is unavailable, but also when the calling script lacks privileges to perform the action.

Next: querySelector()

Learn how to find the first element that matches a CSS selector.

querySelector() 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.

11 people found this page helpful