7

Is it possible to get autocomplete or suggestions or intellisense or something for CSS when developing in React?

example

For example, when I write something like this I want to be able to see all the possibilities for that CSS property. I know that I can get this if I use .css files but sometimes I want to use inline CSS for something and it's really annoying that I have to google every time to see what I can use.

6 Answers 6

4

Maybe you can use this. (Similiar to StyleSheet.create() in React Native): https://github.com/sutanlab/react-styles-hook

Sign up to request clarification or add additional context in comments.

Comments

1

I don't think there is some extension that will help you because CSS keeps getting better day by day. So, the maximum you can achieve is create a cheatsheet and use that for every project.

You can install IntelliSense for CSS class names in HTML by Zignd. It is VS Code extension that loads your CSS on program launch and provides autocomplete for that.

3 Comments

This is not what I am looking for, this only works for class names, I need something that works for CSS properties
It scans the whole project and maintain cache. So, it means if you used a margin class regularly it will be shown by autocomplete.
This isn't exactly true. VScode has great intellisense when editing a .css file or .html file within <style> tags.
1

If you are using Styled-Components then try using this Extension:

Extension Name: vscode-styled-components by Julien Poissonnier

https://marketplace.visualstudio.com/items?itemName=styled-components.vscode-styled-components

Comments

1

Open VSCode Settings and search for "css: enabled languages". Click in the "Edit in settings.json" link and add the following text to the json file:

...
"window.zoomLevel": 2,
"css.enabledLanguages": ["html", "jsx"]

}

After doing this, press Shift+Ctrl+P and find the command "Cache CSS class definitions". This worked for me. Now I can see Bootstrap classes, for example, inside my jsx code.

2 Comments

settings not available in vscode 1.77.3. vscode doesn't recognize this settings. is it extension specific settings?
Yes, it is. I forgot to mention... You must install the following extensions: "IntelliSense for CSS class names in HTML" and "HTML and CSS Support" . Hope it helps!
0

I do not think it is necessary since most of the time, if you are using too many CSS, you are going to have modularity and have external css file. But for you, how about temporarily changing "Language Mode" to css. This may need extra clicks, but it will give you CSS auto-completions or suggestions in Visual Studio Code.

Comments

0

You can simply use JSDoc for this purpose. Take for example the following snippet:

 /**
 * @type {import("react").CSSProperties}
 */
const padStyle = {
  bottom: '20vh',
  right: '20vw'
}

export default padStyle

Vs code understands the JSDoc annotation and voila:

VSCode CSS intellisense

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.