CLion recognizes and processes most common style selectors: universal selector
*, type selectors
.a, descendant selectors
.a.b, child selectors
.a .b, ID selectors
#b, pseudo-classes and class selectors
Working with style declarations
CLion lets you create new rulesets from existing declarations and even move entire rulsets from other files using CSS-aware intention actions and refactoring.
To extract a ruleset
Select the declarations to extract. If you need only one declaration, just place the cursor inside it.
Press Alt+Enter and select Extract ruleset from the list.
CLion creates a new ruleset with the same selector and moves the selected declarations to it. If the selection contains comments, nested selectors, and so on, they are also moved to the new ruleset.
To move a ruleset to another file
Place the cursor anywhere in the ruleset and press F6.
In the dialog that opens, specify the file to move the ruleset to. If the specified file does not exist, CLion will suggest creating it.
By default, CLion automatically opens the file where the ruleset is moved. To change this behavior, clear the Open in editor checkbox.
CLion first suggests classes and ids from the style tag and linked files. But if no matching results are found, CLion also suggests symbols defined in all stylesheet files in the project. To see all classes and ids defined in the project straight away, before you start typing, press Ctrl+Space twice.
With CLion, you can easily introduce variables using the
var(--var-name) syntax in your .css files.
In the editor, place the cursor at the expression to convert into a variable and press Ctrl+Alt+V or selectfrom the context menu or from the main menu.
If more than one occurrence of the selected expression is found, select Replace this occurrence only or Replace all occurrences from the Multiple occurrences found list.
In the field with red borders, accept the suggested variable name or specify a custom name. Press Enter when ready.
For CSS properties and pseudo-elements, CLion can show you a summary from the corresponding MDN article. This summary is displayed in the Documentation popup which shows a brief description of the property and its values, as well as information about its compatibility with various browsers.
To view documentation for a property at caret
Press Ctrl+Q or select Documentation popup with a brief description of the property.from the main menu. CLion opens a
If the property is available in all versions of browsers, CLion does not show any information about its compatibility.
Otherwise, the Documentation popup also lists the browsers and their versions that support the property.
To open the MDN documentation in the browser
In the Documentation popup (Ctrl+Q), click the link at the bottom.
Press Shift+F1 or selectfrom the main menu.
Checking compatibility with browsers
Besides looking up in the documentation popup, you can check CSS properties for compatibility with specific browsers on the fly. This inspection is based on the MDN Browser Compatibility Data and shows you a warning every time a property is not supported in one of the targeted browsers.
In the Settings/Preferences dialog (Ctrl+Alt+S), go to .
Expand the CSS node and select the Browser compatibility checkbox. In the Options area, select the browsers you want to target and the minimum versions for them.
Formatting Style Sheets
Every time CLion generates, refactors, or reformats your Style Sheet code, it automatically applies the language-specific code style settings.
Alternatively, you can use the Prettier formatter.
To format a Style Sheet with Prettier
Select the code fragment to reformat in the editor or select a file or a folder in the Project tool window and press N/A.
Changing Color Values in Style Sheets
With CLion, you can easily change color values in Style Sheets without typing hexadecimal codes.
To choose a color
Open the desired Style Sheet for editing.
color:, and then press Ctrl+Space.
Select the desired color value from the suggestion list or choose color... to pick a custom one.
To change a color
Open the desired Style Sheet for editing, and locate the color property that you want to change.
Click the color icon in the gutter.
Alternatively, if the icons are not shown, press Alt+Enter and select Change color from the list.
In the Choose color dialog that opens, pick the desired new color and click Choose.
To preview the code of a color
CLion marks each
colorproperty with a gutter icon of the corresponding color. When you hover over a color icon, CLion displays a popup that shows the color preview and its hexadecimal code.
To show color icons in the gutter
By default, CLion displays color icons in the gutter. If they are for some reason hidden, you can return them at any time.
In the Settings/Preferences dialog (Ctrl+Alt+S), go to . The Gutter Icons page opens.
In the Common area, select the Color preview checkbox.
Viewing the Styles Applied to a Tag
For HTML, XHTML files, CLion suggests a way to explore all styles applied to an arbitrary tag.
The results for each tag are displayed in the dedicated tabs of the CSS Styles tool window. Using this tool window, you can view the list of styles applied to a tag, and the definition of these styles. Besides that, you can navigate from style to the corresponding tag in the source code.
Open the desired file in the editor, and right-click the tag you want to explore for applied styles.
From the context menu, choose.
View results in a dedicated tab in the CSS Styles tool window:
Configuring syntax highlighting
You can configure CSS-aware syntax highlighting according to your preferences and habits.
In the Settings/Preferences dialog (Ctrl+Alt+S), go to .
Select the color scheme, accept the highlighting settings inherited from defaults or customize them as described in Configuring Colors and Fonts.