70

https://code.visualstudio.com/docs/languages/css

None of the current plugin able to do so. I am really surprised. even intellij has this support!

Also the reply from vscode itself is a bit not helpful either. https://github.com/Microsoft/vscode/issues/36485

Any hint on how to build such plugin, seems shouldn't be really hard since its really just porting the feature from one file extension to another?

Anyone able to resolve this?

ey dee ey em
  • 7,991
  • 14
  • 65
  • 121

8 Answers8

81

I found colorize which can highlight JavaScript and TypeScript (among others) GitHub

In your settings.json in VSCode just add languages you'd like to target:

"colorize.languages": ["typescript", "javascript", "css", "scss"]

enter image description here

Boris Yakubchik
  • 3,861
  • 3
  • 34
  • 41
  • 5
    got it working with `"colorize.include": ["**/*.coffee"]` – Nitsan Baleli Dec 08 '19 at 08:47
  • 9
    Does this extension have a color picker? Or does it just highlight colors? I installed it but there is no color picker in jsx – Ali Mert Çakar Jul 17 '20 at 07:34
  • 1
    @AliMertCakar unfortunately "Colorize" doesn't include a colour _picker_, it only highlights known colour strings.. I've just switched from that to "JSON Color Token". if you haven't already done so in the almost-2-years since you posted this comment, I'd highly recommend you check it out... :) – Andre Greeff Apr 23 '22 at 09:58
  • @AndreGreeff I've checked and I am using "Color Highlight". Works in .tsx files for me. I don't even remember myself commenting on this :) – Ali Mert Çakar Apr 24 '22 at 00:19
  • 4
    This doesn't answer the question which is referring to the color ``picker`` and not just a color ``highlight`` – Monstar Jun 14 '22 at 17:53
31

Updating for this question. Seems like:

https://marketplace.visualstudio.com/items?itemName=AntiAntiSepticeye.vscode-color-picker

adds color picker brings functionality into other languages.

Personally tested and works in typescript. It's relatively new so it doesn't have a lot of downloads or installs but it works as advertised.

cpakken
  • 311
  • 4
  • 3
30

To anyone who uses Colorize and wants it to work on their React project (CSS in JS and such) use:

"colorize.languages": ["javascriptreact", "javascript", "css", "scss"]

as apparently "javascriptreact" is needed and not "javascript"

For TypeScript in React use "typescriptreact".

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Amit
  • 2,142
  • 1
  • 11
  • 12
11

VS extension JSON color token is capable of bringing up the native color picker in any language.

To make this work with JS and React, add this in VS Code's settings.json:

"jsonColorToken.languages": [
    "json",
    "jsonc",
    "javascript",
    "javascriptreact"
  ]

Source: https://github.com/YECHUNAN/json-color-token/issues/2#issuecomment-977261832

kracas
  • 111
  • 2
  • 3
  • 1
    I've been using Colorize (as per many other answers) for ages now, but thanks to your answer here now, I've just switched over to JSON Color Token instead... this is so much nicer to use, thank you! :) – Andre Greeff Apr 23 '22 at 09:55
  • 1
    Thanks - after installing the extension, updating settings.json, and _restarting_ VSCode, it's looking good! – Peter Jun 01 '22 at 17:51
  • It works but only with Hex codes, not RGB. – Loïc Joachim Jun 13 '22 at 23:40
5

The ability to see a color decorator in front of css-stle color formats or invoke a standalone color picker anywhere is currently in vscode Insiders v1.78.

Demo in ts and jsx files:

setting toggle and color decorators

Setting: Editor: Default Color Decorators

Command: Show or Focus Standalone Color Picker

See more at https://stackoverflow.com/a/76066924/836330

Mark
  • 143,421
  • 24
  • 428
  • 436
  • Here is the answer! Why to install extensions. But i observed, it works in tsx only when there is StyleSheet object imported, either blank or with styles. const styles = StyleSheet.create({}); – Rohit Parte Jun 19 '23 at 11:58
  • I have a weird behaviour, not sure whether this is bc of some other extension I have. But activating this and then reloading the window I do see the previews in my tailwind.config.js for a couple of seconds, then they disappear so I'm on the hunt on why that happens – lakardion Jun 26 '23 at 12:57
  • update: found out it is the Talwind CSS Intellisense extension so I'll probably open an issue – lakardion Jun 26 '23 at 13:10
1

There is one possible implementation with vscode-color-info from wayncheng

Adding the following code to colorInfo.languages in settings.json should do the trick. Make sure to include all the default languages as well so they aren't disabled.

{
    "selector": "javascript",
    "colors": "css"
}

So your settings.json should look something like this:

"colorInfo.languages": [
    {
        "selector": "css",
        "colors": "css"
    },
    {
        "selector": "sass",
        "colors": "css"
    },
    {
        "selector": "scss",
        "colors": "css"
    },
    {
        "selector": "less",
        "colors": "css"
    },
    {
        "selector": "html",
        "colors": "css"
    },
    {
        "selector": "javascript",
        "colors": "css"
    }
]
ey dee ey em
  • 7,991
  • 14
  • 65
  • 121
1

It works to use "colorize.include": ["**/*.js"] in my create-react-app project

翁于宸
  • 11
  • 1
0

I had the problem that TSX (TypeScript files with XML) wouldn't properly highlight the color. The solution was to add "typescriptreact" to the array as described in the post by @rouan.

PS @Ali Mert Cakar it adds no color picker and only highlights the color in the respective color.