14

In my CSS file I'm using custom CSS as can be seen from the photo. WebStorm gives errors. How can I fix it?

When hovered on it full error is here

Cannot resolve '--color-gray-1' custom property
This inspection warns about CSS custom property variable references which cannot be resolved to any valid target

enter image description here

LazyOne
  • 158,824
  • 45
  • 388
  • 391
demiculus
  • 1,243
  • 1
  • 12
  • 32
  • 3
    works fine for me using similar syntax. Please try invalidating caches (*File | Invalidate caches, Invalidate and restart*). If it doesn't help, please create a support ticket, providing your `.css` file – lena Dec 26 '18 at 14:05
  • Seems like it happens only on non-project files. There is a [youtrack issue](https://youtrack.jetbrains.com/issue/WEB-53346) filed for it (unless it was you) – AaA Aug 15 '23 at 15:22

3 Answers3

4

Adding the property to custom CSS properties suppresses the 'Unknown CSS property' inspection; But in your screenshot I am guessing the warning comes from W3C validator. W3C Validator Inspection is based on external tool provided by W3C (online version available at http://jigsaw.w3.org/css-validator/#validate_by_input), so we can do nothing to fix such warnings. Plus w3C validator is not always up-to-date and reports errors for valid CSS, but some users still like to have it enabled.

You can only disable this inspection if you don't like these errors being displayed: hit Alt+Enter and choose 'Disable W3C CSS validation'.

Arman sheikh
  • 176
  • 2
  • 7
  • This is not the case, my phpstorm was working fine until few days ago (not showing error as soon as I add them). No updates were downloaded or installed ( I have been offline for past few weeks) which means there should be some settings accidentally triggered or files corrupted, causing this to appear. – AaA Aug 15 '23 at 11:29
2

Make sure directory css file resides in is not excluded: right click on directory > Mark Directory As > Not Excluded

normonds
  • 73
  • 4
1

two ways you can try:

1. :root {
     --color-gray-1: #666666;
   }

2. html, body {
     --color-gray-1: #666666;
     color: var(--color-gray-1)
   }
Leonardo Buscemi
  • 1,111
  • 1
  • 15
  • 22
videring
  • 19
  • 2