The Selector Manager in Silex allows you to efficiently manage and apply complex CSS selectors within your project. It enhances the style management capabilities of the editor, making it easier to work with classes, IDs, tag names, and advanced CSS relationships like pseudo-classes and attribute selectors.
Technicly, this is a grapesjs plugin, pre-installed in silex, here is the source code of this plugin
To open the Advanced Selector Manager, select any element in your project and navigate to the Styles panel. You will find an enhanced interface that provides better control over CSS selectors.
<div>
, <section>
, <article>
, etc.) to another.[data-*]
and other custom attributes for styling.div > .button
).:hover
, :focus
, :nth-child(n)
) to style interactions.:not()
, :has()
, etc.).@media
rules) to define styles at different screen sizes.Click on an element in the canvas to open the Advanced Selector Manager.
:hover
, :focus
, and :first-child
.parent > child
relationships).This row shows the parts of the selector that directly identify the element.
Tag name (e.g. div
, button
)
ID (e.g. #main-button-2-2
)
Class (e.g. .btn
, .primary
)
This control lets you style the element in a particular state, e.g.
➡ Changing or removing the pseudo-class here does not change the CSS. It only tells the editor which variant of the selector you are currently styling.
You can extend the selector with:
>
, +
, ~
, space):not()
:has()
:is()
:where()
➡ Adding/removing parts here never changes your DOM or CSS classes.
It only lets you target different situations (e.g. .parent > .child
, .btn:not(.disabled)
).
The Current Selector Display is the control panel at the bottom of the Selector Manager.
It shows which CSS selector you are currently editing and gives you a list of all the existing selectors for the current selection.
.btn
.btn.primary
button:hover
Icon | Action | Description |
---|---|---|
✏️ | Edit Selector | Opens an input where you can directly rename or refine the selector (.item → .item.active , etc.) |
📋 | Copy Styles | Copies all CSS properties defined in this selector to the clipboard |
📥 | Paste Styles | Applies the last copied styles to the current selector |
🧹 | Clear Styles | Removes all styles from the selector but keeps the selector itself |
❓ | Help | Opens documentation about the selector manager |
✔ Use classes instead of IDs for styling whenever possible to keep your design flexible.
✔ Use :not()
and :has()
carefully to avoid performance issues with complex selectors.
This document explains what CSS selectors are valid and suggested by the GrapesJS Advanced Selector plugin.
The Advanced Selector plugin supports standard CSS selectors with intelligent validation and suggestions. It only allows valid CSS selector patterns and provides contextual suggestions based on your component structure.
Format: tagname
Examples: div
, p
, span
, button
my-component
)Format: .classname
Examples: .my-class
, .btn-primary
, .navigation
Format: #idname
Examples: #header
, #main-content
, #user-123
Format: [attribute]
or [attribute="value"]
The following HTML attributes are always accepted:
[id]
, [class]
, [style]
[name]
, [type]
, [value]
, [placeholder]
[href]
, [src]
, [alt]
, [title]
[width]
, [height]
, [disabled]
, [checked]
[selected]
, [hidden]
, [readonly]
, [multiple]
[required]
, [min]
, [max]
, [step]
, [pattern]
[autocomplete]
, [autofocus]
, [spellcheck]
[contenteditable]
, [dir]
, [lang]
, [tabindex]
[accesskey]
, [role]
Format: [data-*]
Examples: [data-test]
, [data-user-id]
, [data-toggle]
data-
followed by at least one characterYou can use CSS attribute operators:
[attr="value"]
- Exact match[attr~="value"]
- Word match (space-separated)[attr|="value"]
- Language code match (hyphen-separated)[attr^="value"]
- Starts with[attr$="value"]
- Ends with[attr*="value"]
- Contains substringFormat: *
Description: Matches all elements
The following patterns are NOT accepted:
[customattr]
- ❌ Not allowed[my-attribute]
- ❌ Not allowed[testprop]
- ❌ Not allowedWhy: Custom attributes should use the data-*
prefix for valid HTML.
1class
, #2id
.my class
, #my id
The plugin provides intelligent suggestions based on:
id
- use #id
instead)#id
syntax instead of [id="..."]
div p
(space)div > p
div + p
div ~ p
:hover
, :focus
, :active
:first-child
, :last-child
, :nth-child()
:not()
, :is()
, :where()
::before
, ::after
::first-line
, ::first-letter
/* Simple selectors */
div
.my-class
#header
[data-toggle]
[type="button"]
*
/* Complex selectors */
div.container
#header .navigation
.btn[disabled]
[data-role="button"]:hover
.parent > .child
div + p
.container [data-test="value"]
/* Pseudo-classes and elements */
.button:hover
.input:focus
.list-item:first-child
.content::before
/* These will be rejected */
[customattr] /* Use [data-customattr] instead */
[testprop="value"] /* Use [data-testprop="value"] instead */
.2invalid /* Cannot start with number */
#my id /* No spaces allowed */
[data-] /* Incomplete data attribute */
[data-component="header"]
.navigation
over .nav1
#header
not [id="header"]
.button[data-variant="primary"]
⚠ Current selector does not match the selected components
?This warning means that the selector you are editing does not currently apply to the element you have selected on the canvas. The editor tries to check if the selected component matches the rule you are styling. If it doesn’t, the warning is displayed.
This does not mean your selector is invalid or that the styles won’t work. It only indicates that, in the current context, the selected element is not matched by the selector. When the selector applies to elements in your final page (for example, because of different attributes, states, or structure), the styles will be applied normally.
Tip: You can usually ignore this message if you know your selector is valid for your intended use. It’s primarily a reminder that the currently selected component is not affected by it inside the editor preview.