DevTools Tip: Sync your CSS Edits from the browser to VS Code
Tags: tooling, webdev, tutorial, css
Published: 2022-11-23 18:20:00

In the Myspace and Livejournal days of the web, you could find me altering themes with CSS. I honestly can't remember exactly what led to poking around in CSS but it was most likely seeing custom layouts or styles in Livejournal and then figuring it out from there. 

My degree is in web design and I've spent many an hour in the Styles pane in the browser DevTools' Elements tool. When I'm styling a project, my workflow is typically to write the HTML, add some classes I suspect I'll want to use and then start the CSS boilerplate. 

Once I've done that, I open the Microsoft Edge Developer Tools and use the Elements tool with the Styles pane to style my elements and design in the browser. 

This is the way it's always been for me. As is the unavoidable loss of styles I applied when I accidentally refreshed by browser pane. 


![The Developer Tools Elements tool with Styles pane open](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6rekhn0vqrwh0gd5dqkr.png)

Big headache...what styles did I try to add? 

The timeless question I asked...until the ability to sync your changes to VS Code was added. 

VS Code is my IDE of choice. I have tried atom and another one I've forgotten the name of...and Dreamweaver, ages ago. Maybe working at Microsoft, it was inevitable I use VS Code. I do enjoy using it though. 

What I love about it is that I can sync my CSS changes back to my file when I'm adding and removing styles in the browser. 

1. To set this up, go to the DevTools Settings pane > Experiments > Then find "Open source files in Visual Studio Code" in the list. Then re-start DevTools. 
2. When you open a local server or a local project file, you'll be prompted to select the root folder you're working from for your project. 
3. When you go back to the Elements tool and the styles pane, and the file you're working on is located within that root folder you set, you should be able to make edits to your CSS and it will immediately reflect back in your CSS file in VS Code. 

![The DevTools UI showing a prompt to select a root folder](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t8w6i9nifuvf5g0wk6cz.png)

![The Workflows tab in the browser DevTools Settings pane](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mhhb7zl4hwr4udunoxm4.png)

If you uncheck styles you've applied in the browser, that also syncs back to VS Code, but instead of removing the style, it just comments it out. So if you don't reapply it, you'll have to do a little code cleanup, but I find this a minimal task. 

As someone who designs in the browser, this is one of my core workflows and such a handy feature in the DevTools for CSS. 

You can read more about this feature and how to manage a Workspace in the DevTools in the [Edge DevTools documentation](https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/sources/opening-sources-in-vscode).

---

Follow me on [Twitter](https://twitter.com/seaotta) for tech, travel and musings. I blog over on my website at [blog.stephaniestimac.com](https://blog.stephaniestimac.com) and run [The Web We Want](https://webwewant.fyi), a place for web developers and designers to submit the things they need from browsers and the web platform to make their jobs easier. Author of [Design for Developers](https://www.manning.com/books/design-for-developers?utm_source=stimac&utm_medium=affiliate&utm_campaign=book_stimac_design_4_19_22&a_aid=stimac&a_bid=5f6ba095).