---
title: "Embed the query builder"
description: "Embed Metabase’s visual query builder or SQL editor in your app, so people can build and save their own questions."
url: "https://www.metabase.com/docs/latest/embedding/query-builder"
version: "65"
---

> For the complete documentation index, see [llms.txt](https://www.metabase.com/docs/llms.txt).

# Embed the query builder

> Embedding the query builder is only available on [Pro](https://store.metabase.com/checkout/embedding) and [Enterprise](https://www.metabase.com/product/enterprise) plans (both self-hosted and on Metabase Cloud).

You can embed one of Metabase's query editors so people can build questions from scratch.

- [Visual query builder](#embed-the-visual-query-builder)
- [SQL editor](#embed-the-sql-editor)

Both query editors need a logged-in Metabase account: to run a new query, Metabase has to know who's asking, so it can work out which data they're allowed to see. In an embed, [SSO](https://www.metabase.com/docs/latest/embedding/introduction.md#components-with-sso-authentication) is how you provide that account, so neither editor works in a [guest embed](https://www.metabase.com/docs/latest/embedding/introduction.md#components-with-guest-authentication). Check out [SSO or guest embeds](https://www.metabase.com/docs/latest/embedding/introduction.md#comparison-between-sso-and-guest-authentication).

And because everyone queries through their own Metabase account, people can only build questions on databases their groups have permission to query. See [data permissions](https://www.metabase.com/docs/latest/permissions/data.md).

Both query editors use the same `<metabase-question>` element as an embedded chart, so they take the same attributes and props. See the [Question component reference](https://www.metabase.com/docs/latest/embedding/question-reference.md).

To embed an existing chart instead, check out [Embed a chart](https://www.metabase.com/docs/latest/embedding/chart.md).

## Embed the visual query builder

To let people build new questions with the visual query builder, use `new` as the question ID.

![Query builder](https://www.metabase.com/docs/latest/embedding/images/embedded-query-builder.png)

As a web component:

```html
<metabase-question question-id="new"></metabase-question>
```

With the SDK:

```tsx
import React from "react";
import {
  InteractiveQuestion,
  MetabaseProvider,
  defineMetabaseAuthConfig,
} from "@metabase/embedding-sdk-react";

const authConfig = defineMetabaseAuthConfig({
  metabaseInstanceUrl: "https://your-metabase.example.com",
});

export default function App() {
  return (
    <MetabaseProvider authConfig={authConfig}>
      <InteractiveQuestion questionId="new" />
    </MetabaseProvider>
  );
}
```

To narrow down what people can start from, list the entity types you want in the data picker with the `entity-types` attribute (web component) or the `entityTypes` prop (SDK). For example, `entity-types="['table']"` limits the picker to raw tables. The attribute takes `"table"`, `"model"`, or both.

## Embed the SQL editor

![Embedded SQL editor](https://www.metabase.com/docs/latest/embedding/images/embedded-sql-editor.png)

To let people write native SQL, use `new-native` as the question ID.

As a web component:

```html
<metabase-question question-id="new-native"></metabase-question>
```

With the SDK:

```tsx
import React from "react";
import {
  InteractiveQuestion,
  MetabaseProvider,
  defineMetabaseAuthConfig,
} from "@metabase/embedding-sdk-react";

const authConfig = defineMetabaseAuthConfig({
  metabaseInstanceUrl: "https://your-metabase.example.com",
});

export default function App() {
  return (
    <MetabaseProvider authConfig={authConfig}>
      <InteractiveQuestion questionId="new-native" />
    </MetabaseProvider>
  );
}
```

## Let people save questions

### Saving with web components

With a web component, turn saving on with `is-save-enabled="true"`. `target-collection` is optional, but it's worth setting: it picks the collection that new questions land in, so people's work doesn't scatter across your Metabase.

```html
<metabase-question
  question-id="new"
  is-save-enabled="true"
  target-collection="5"
></metabase-question>
```

These examples use sequential IDs — the number in the item's URL. On Pro and Enterprise plans, you can use [entity IDs](https://www.metabase.com/docs/latest/installation-and-operation/serialization.md#entity-ids-work-with-embedding) instead; they stay the same when you [serialize](https://www.metabase.com/docs/latest/installation-and-operation/serialization.md) content from one Metabase to another, like from staging to production.

### Saving with the React SDK

With the SDK, saving is already on, so `targetCollection` is all you need. Setting `targetCollection` also hides the collection picker, so nobody has to decide where their question goes.

For the `isSaveEnabled`, `onBeforeSave`, and `onSave` props, check out [Let people save their changes](https://www.metabase.com/docs/latest/embedding/chart.md#let-people-save-their-changes).

## Customize the query builder's layout

With the SDK, you can build your own layout out of the namespaced components inside `InteractiveQuestion`, like `<InteractiveQuestion.Editor />`. See [InteractiveQuestion components](https://www.metabase.com/docs/latest/embedding/question-reference.md#react-sdk-interactivequestion-components).

## Further reading

- [Embed a chart](https://www.metabase.com/docs/latest/embedding/chart.md)
- [Question component reference](https://www.metabase.com/docs/latest/embedding/question-reference.md)
- [Embed a dashboard](https://www.metabase.com/docs/latest/embedding/dashboard.md)
- [Dashboard component reference](https://www.metabase.com/docs/latest/embedding/dashboard-reference.md)
- [Modular embedding](https://www.metabase.com/docs/latest/embedding/modular-embedding.md)
- [Modular embedding SDK](https://www.metabase.com/docs/latest/embedding/sdk/introduction.md)
- [Modular embedding components](https://www.metabase.com/docs/latest/embedding/components.md)
- [Appearance](https://www.metabase.com/docs/latest/embedding/appearance.md)
