Ora

How Do You Change the Font Color in Visual Studio Code?

Published in VS Code Customization 5 mins read

Changing font colors in Visual Studio Code is primarily done through themes or by customizing your settings.json file, offering extensive control over both the editor's UI and syntax highlighting.

Using Built-in and Marketplace Themes

The quickest way to alter font colors and the overall look of Visual Studio Code is by applying a theme. Themes package a complete set of color definitions for the editor's UI and syntax highlighting.

Steps to Change Your Theme:

  1. Open the Command Palette: Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS).
  2. Type "theme": Select Preferences: Color Theme.
  3. Browse Themes: Use the up/down arrow keys to preview different themes installed on your system. Visual Studio Code comes with several default themes (e.g., Light+, Dark+, Monokai).
  4. Install More Themes: If you don't find a theme you like, you can explore thousands of additional themes on the VS Code Marketplace directly from the Extensions view:
    • Click on the Extensions icon in the Activity Bar on the side (or press Ctrl+Shift+X / Cmd+Shift+X).
    • Search for "theme" and filter by "Themes".
    • Click "Install" on any theme you wish to try. Once installed, it will appear in your Preferences: Color Theme selection list.

Advanced Customization with settings.json

For more granular control, you can override specific color settings of your current theme using the settings.json file. This allows you to fine-tune individual elements without creating an entirely new theme.

Steps to Edit settings.json:

  1. Open Settings: Press Ctrl+, (Windows/Linux) or Cmd+, (macOS).
  2. Open settings.json: In the Settings editor, click the "Open Settings (JSON)" icon in the top right corner. This will open your user settings.json file, where you can add or modify color customizations.

Customizing UI Element Colors (workbench.colorCustomizations)

The workbench.colorCustomizations property in settings.json allows you to change the colors of various UI elements outside of the code editor itself, such as the sidebar, activity bar, status bar, and integrated terminal.

Common UI Customizations:

Property Description Example Color
editor.foreground Default font color in the editor. #F8F8F2
editor.background Background color of the editor. #282A36
sideBar.background Background color of the sidebar. #3C3C3C
statusBar.background Background color of the status bar. #007ACC
terminal.foreground Default foreground color of the terminal. #ABB2BF
input.background Background of input fields. #3D3D3D
list.activeSelectionForeground Foreground color of the active item in lists/trees. #FFFFFF

Example settings.json for UI Colors:

{
    "workbench.colorCustomizations": {
        "editor.foreground": "#E0E0E0",             // Editor text color
        "sideBar.background": "#252526",            // Sidebar background
        "statusBar.background": "#005a99",          // Status bar background
        "terminal.foreground": "#D4D4D4",           // Integrated terminal text color
        "tab.activeForeground": "#FFFFFF",          // Active tab text color
        "tab.inactiveForeground": "#BBBBBB"         // Inactive tab text color
    }
}

You can find a comprehensive list of customizable UI colors in the VS Code Theme Color Reference.

Customizing Syntax Highlighting (editor.tokenColorCustomizations)

To change the color of specific language elements (like keywords, strings, comments, or variable names) in your code, use editor.tokenColorCustomizations. This property allows you to target different "scopes" that define parts of your code.

How to Find Token Scopes:

  1. Open Command Palette: Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS).
  2. Run "Developer: Inspect Editor Tokens and Scopes": This command opens a hover window showing detailed information about the token under your cursor, including its scope.
  3. Identify the Scope: Look for the "scopes" array. For example, a string might have scopes like string.quoted.double.js. You can use a specific scope or a broader one (e.g., string to affect all strings).

Example settings.json for Syntax Highlighting:

{
    "editor.tokenColorCustomizations": {
        // Customize a specific token scope
        "textMateRules": [
            {
                "scope": "comment",               // Target comments
                "settings": {
                    "foreground": "#6A9955",      // Change comment color to green
                    "fontStyle": "italic"         // Make comments italic
                }
            },
            {
                "scope": "keyword.control",       // Target control flow keywords (if, for, while)
                "settings": {
                    "foreground": "#C586C0"       // Change keyword color to purple
                }
            },
            {
                "scope": [
                    "variable.other.property",    // Target object properties
                    "entity.name.function"        // Target function names
                ],
                "settings": {
                    "foreground": "#56B6C2"       // Change these to a teal color
                }
            }
        ],
        // Alternatively, use semantic token rules for languages supporting semantic highlighting
        // "semanticHighlighting": true, // Ensure semantic highlighting is enabled
        // "rules": {
        //     "variable.readonly:java": {
        //         "foreground": "#FF0000" // Example for a specific semantic token
        //     }
        // }
    }
}

For more advanced syntax highlighting, especially with languages that support it, explore Semantic Highlighting.

Customizing Font Colors in Specialized Tool Windows

While Visual Studio Code primarily uses themes and settings.json for font customization, it's also worth noting that in broader development environments, including certain specialized text-based tool windows like command line interfaces or output panes, specific font and color settings might be accessed via a dedicated menu path. For instance, in some integrated development environments, options for text-based tool windows such as the Command window, Immediate window, and Output window can often be adjusted through a sequence like Tools > Options > Environment > Fonts and Colors.

Essential Tips for Font Color Customization

  • Backup Your Settings: Before making extensive changes, consider backing up your settings.json file.
  • Use Color Pickers: Many online tools and VS Code extensions can help you pick hex color codes (#RRGGBB or #RRGGBBAA).
  • Consider Accessibility: Ensure your custom color scheme provides sufficient contrast for readability and is accessible to all users.
  • Restart VS Code: Sometimes, a full restart of Visual Studio Code is needed for all custom settings to take effect, especially after installing new themes or making significant changes.