Skip to main content
Version: Next

Styling overview

React Query Builder has a flexible structure with specific classes assigned to each element in the component hierarchy, enabling a wide range of styling possibilities.

tip

Check out the customization showcase for a variety of styling tips.

The default stylesheet comes in CSS and SCSS flavors. Either will allow you to override the default values and tweak styles without having to replicate the entire rule set.

To load only the default layout/structural values (flex-direction, gap, alignment, etc.—without background-color, border-style, or other decorative styles), import query-builder-layout.css (or .scss) instead.

@import 'react-querybuilder/dist/query-builder.css';
/* OR, for layout only: */
@import 'react-querybuilder/dist/query-builder-layout.css';

CSS variables

Customize the default stylesheet by overriding the CSS (or SCSS) variables.

info

CSS variables were introduced to React Query Builder in v8.3.0 and SCSS variables have been available since v4.0.0. Both methods will be supported going forward.

The default variables include:

:root {
--rqb-spacing: 0.5rem;
--rqb-border-width: 1px;
--rqb-background-color: #004bb733;
--rqb-border-color: #8081a2;
--rqb-border-style: solid;
--rqb-border-radius: 0.25rem;
}

Example:

@import 'react-querybuilder/dist/query-builder.css';

:root {
--rqb-spacing: 0.8rem; /* a little roomier than the default 0.5rem */
--rqb-background-color: #ccc3; /* gray, semi-transparent background */
}

SCSS variables

SCSS variables begin with $ instead of --, but otherwise have the same name as their CSS counterpart (e.g., $rqb-spacing corresponds to --rqb-spacing).

Using SCSS has the advantage of allowing you to customize the CSS variable prefix (rqb- by default) by setting $rqb-var-prefix.

@use 'react-querybuilder/dist/query-builder' with (
$rqb-var-prefix: myprefix-,
$rqb-spacing: 0.8rem
);

:root {
--myprefix-background-color: #ccc3;
}

Branch lines

To add branch lines to the left side of rule groups, add the queryBuilder-branches class to the query builder using the controlClassnames prop, or to any ancestor element.

<QueryBuilder
controlClassnames={{ queryBuilder: 'queryBuilder-branches' }}
/>
https://example.com

The branch lines are colored red in the example above to stand out, but by default, branch lines use the same color, width, and style as the group borders. The following variables can be overridden to customize the branch lines.

:root {
--rqb-branch-indent: var(--rqb-spacing);
--rqb-branch-width: var(--rqb-border-width);
--rqb-branch-color: var(--rqb-border-color);
--rqb-branch-radius: var(--rqb-border-radius);
--rqb-branch-style: var(--rqb-border-style);
}

Drag-and-drop

When drag-and-drop is enabled, the following variables control styles for the dragged and hovered elements.

:root {
--rqb-dnd-drop-indicator-color: rebeccapurple;
--rqb-dnd-drop-indicator-copy-color: #669933;
--rqb-dnd-drop-indicator-style: dashed;
--rqb-dnd-drop-indicator-width: 2px;
}

You can also assign styles to the following classes.

  • dndDragging: Assigned to the clone of the dragged element (the "ghost" that follows the mouse cursor)
  • dndOver: Assigned to a drop target when the cursor hovers over it
  • dndCopy: Assigned to a drop target when the cursor hovers over it while the modifier key is pressed (Alt on Windows/Linux, Option/ on Mac)