WebStorm 2019.1 Help

Style Sheets

With WebStorm, you can write style definitions both in CSS and in various languages that compile into it, such as, Sass, Less, SCSS, or Stylus.

WebStorm 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 DIV.warning.

WebStorm provides code completion for selectors, properties and their values and navigation from the use of a selector in HTML or JavaScript to its definition in a style sheet file. You can also use code completion and navigation to the definition for variables and mixins.

Working with style declarations

WebStorm 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

  1. Select the declarations to extract. If you need only one declaration, just place the cursor inside it.

  2. Press Alt+Enter and select Extract ruleset from the list.

WebStorm 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

  1. Place the cursor anywhere in the ruleset and press F6.

  2. In the dialog that opens, specify the file to move the ruleset to. If the specified file does not exist, WebStorm will suggest creating it.

  3. By default, WebStorm automatically opens the file where the ruleset is moved. To change this behavior, clear the Open in editor checkbox.

Completing classes

WebStorm first suggests classes and ids from the style tag and linked files. But if no matching results are found, WebStorm also suggests symbols defined in all stylesheet files in the project.

Project-wide completion for CSS symbols in HTML
To see all classes and ids defined in the project straight away, before you start typing, press Ctrl+Space twice.

Extracting variables

With WebStorm, you can easily introduce variables using the var(--var-name) syntax in your .css files.

  1. In the editor, place the cursor at the expression to convert into a variable and press Ctrl+Alt+V or select Refactor | Extract | Variable from the context menu or from the main menu.

  2. 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.

  3. In the field with red borders, accept the suggested variable name or specify a custom name. Press Enter when ready.

Documentation look-up

For CSS properties and pseudo-elements, WebStorm 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 View | Quick Documentation Lookup from the main menu. WebStorm opens a Documentation popup with a brief description of the property.

    • If the property is available in all versions of browsers, WebStorm does not show any information about its compatibility.

      CSS quick documentation: property is available in all versions of browsers
    • Otherwise, the Documentation popup also lists the browsers and their versions that support the property.

      CSS quick documentation: compatible browsers are listed

To open the MDN documentation in the browser

  • In the Documentation popup (Ctrl+Q), click the link at the bottom.

  • Press Shift+F1 or select View | External Documentation from 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.

CSS compatibility inspection popup
  1. In the Settings/Preferences dialog (Ctrl+Alt+S), go to Editor | Inspections.

  2. 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.

    CSS compatibility inspection settings

Formatting Style Sheets

Every time WebStorm 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 Ctrl+Shift+Alt+P.

  • Alternatively, press Ctrl+Shift+A and select Reformat with Prettier from the Find Action list.

    ws_reformat_with_prettier_css.png

Changing Color Values in Style Sheets

With WebStorm, you can easily change color values in Style Sheets without typing hexadecimal codes.

To choose a color

  1. Open the desired Style Sheet for editing.

  2. Type color:, and then press Ctrl+Space.

  3. Select the desired color value from the suggestion list or choose color... to pick a custom one.

To change a color

  1. Open the desired Style Sheet for editing, and locate the color property that you want to change.

  2. Click the color icon in the gutter.

    Alternatively, if the icons are not shown, press Alt+Enter and select Change color from the list.

  3. In the Choose color dialog that opens, pick the desired new color and click Choose.

To preview the code of a color

  • WebStorm marks each color property with a gutter icon of the corresponding color. When you hover over a color icon, WebStorm displays a popup that shows the color preview and its hexadecimal code.

    Color preview on hovering over a color icon in the gutter

    To use a code instead of a human-readable color name, press Alt+Enter and select Convert color to <color code system> from the list, where <color code system> is HEX, HSL, HWB, or RGB

To show color icons in the gutter

By default, WebStorm displays color icons in the gutter. If they are for some reason hidden, you can return them at any time.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), go to Editor | General | Gutter Icons. The Gutter Icons page opens.

  2. In the Common area, select the Color preview checkbox.

Viewing the Styles Applied to a Tag

For HTML, XHTML files, WebStorm 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.

  1. Open the desired file in the editor, and right-click the tag you want to explore for applied styles.

  2. From the context menu, choose Show Applied Styles for Tag.

  3. View results in a dedicated tab in the CSS Styles tool window:

    Viewing the styles applied to the tag <body>

Configuring syntax highlighting

You can configure CSS-aware syntax highlighting according to your preferences and habits.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), go to Editor | Color Scheme | CSS.

  2. Select the color scheme, accept the highlighting settings inherited from defaults or customize them as described in Configuring Colors and Fonts.

Last modified: 25 March 2019