| I wanted to change the code block theme in Confluence Cloud for better visibility based on a black background and white text color. And found the below approach. Before reading the whole post, I want to let you know that you cannot directly change the global code block theme in Confluence Cloud using native Confluence settings or custom CSS. Actually, the Confluence standard provides that feature. As an alternative solution, Confluence Cloud offers a built-in "Dark" theme for its code block macro, which provides a black background with white or light-colored text, perfect for better visibility, especially if you're working with a dark desktop theme or prefer high contrast. Here's a guide on how to change the code block theme in Confluence Cloud: Method 1: Using Confluence's Built-in "Dark" Theme (Recommended)This is the easiest and most direct way to get a black background and white text for your code blocks. 1. Edit Your Confluence Page: - Navigate to the Confluence page where you want to change the code block theme.
- Click the "Edit" button (pencil icon) in the top right corner of the page.
2. Locate or Insert a Code Block Macro: - If you already have a code block: Click on the existing code block macro to select it.
- If you need to insert a new one: Type
/code and select "Code snippet" from the suggestion list, or click the "+" (Insert more content) icon in the editor toolbar and search for "Code snippet."
3. Access Macro Settings: - Once the code block macro is selected, a small toolbar will appear directly above or below it.
- Look for the "Theme" dropdown menu within this toolbar. By default, it's often set to "Confluence" or "Default."
(Example of what the toolbar might look like)
[ Language: Java ▼ ] [ Theme: Confluence ▼ ] [ Show line numbers ] [ Copy ] 4. Select the "Dark" Theme: - Click the "Theme" dropdown.
- From the list of available themes, select "Dark."
You should immediately see the code block's background change to black and the text to a lighter color. 5. Adjust Language (Optional but Recommended): - Next to the "Theme" dropdown, there's usually a "Language" dropdown.
- Select the correct programming language (e.g.,
Java, Python, HTML, JavaScript, Plain Text) for proper syntax highlighting. This will ensure keywords, strings, and comments are colored appropriately against the dark background.
6. Save or Publish Your Page: - Once you're happy with the changes, click "Publish" (if it's a new page or a major edit) or "Update" (if it's an existing page) in the top right corner of the editor.
Method 2: Using a Third-Party App (For More Customization) If Confluence's built-in "Dark" theme isn't exactly what you're looking for, or you need more control over colors and styles, you might consider a third-party app from the Atlassian Marketplace. These apps often provide a wider range of themes, including more dark options, and sometimes custom CSS capabilities. Examples of Apps: - Advanced Code Macro: Offers more syntax highlighting options and themes.
- Code Block Pro for Confluence: Provides additional themes, line highlighting, and other features.
Steps: 1. Consult Your Confluence Administrator: Installing new apps requires administrator privileges. Discuss your needs with your Confluence admin. 2. Browse the Atlassian Marketplace: Your administrator can go to Settings (gear icon) > Apps > Find new apps and search for "code block" or "syntax highlighting." 3. Install the App: Your administrator will install the chosen app. 4. Use the App's Specific Macro: Once installed, the app will likely provide its own code block macro (e.g., /advanced code, /code block pro). 5. Configure Theme within the App's Macro: When you insert or edit the app's macro, it will have its own set of theme options, which might include more dark themes or even allow custom color schemes. Follow the app's specific documentation for configuration. Important Considerations: - Consistency: For the best reader experience, try to maintain a consistent code block theme across your Confluence space or within related documentation.
- Accessibility: While a dark theme can be great for many, ensure it doesn't negatively impact users with certain visual impairments. High contrast is generally good, but extreme color combinations can sometimes be problematic.
- Confluence Cloud Limitations: Unlike Confluence Server/Data Center, Confluence Cloud does not allow end-users to directly inject custom CSS to override styles. Your options are limited to the built-in themes or themes provided by marketplace apps.
By following Method 1, you should easily achieve the desired black background and white text for your code blocks in Confluence Cloud, significantly improving visibility. |