Overview
Dear ImGui provides comprehensive styling capabilities to customize the visual appearance of your UI. You can modify colors, spacing, rounding, and many other visual properties either globally or temporarily for specific UI elements.
Style Structure
The ImGuiStyle structure contains all styling properties. Access it via:
ImGuiStyle & style = ImGui :: GetStyle ();
Key Style Properties
FontSizeBase - Current base font size before external global factors are applied
FontScaleMain - Main global scale factor
FontScaleDpi - Additional global scale factor from viewport/monitor contents scale
ImGuiStyle & style = ImGui :: GetStyle ();
style . FontSizeBase = 20.0 f ;
style . FontScaleMain = 1.5 f ;
Alpha - Global alpha applies to everything in Dear ImGui
DisabledAlpha - Additional alpha multiplier applied by BeginDisabled()
style . Alpha = 0.95 f ; // Slightly transparent UI
style . DisabledAlpha = 0.6 f ; // Disabled widgets are 60% of normal alpha
WindowPadding - Padding within a window
WindowRounding - Radius of window corners rounding
WindowBorderSize - Thickness of border around windows (generally 0.0f or 1.0f)
WindowMinSize - Minimum window size
WindowTitleAlign - Alignment for title bar text
style . WindowPadding = ImVec2 ( 15 , 15 );
style . WindowRounding = 5.0 f ;
style . WindowBorderSize = 1.0 f ;
FramePadding - Padding within a framed rectangle (used by most widgets)
FrameRounding - Radius of frame corners rounding
FrameBorderSize - Thickness of border around frames
style . FramePadding = ImVec2 ( 8 , 4 );
style . FrameRounding = 4.0 f ;
style . FrameBorderSize = 1.0 f ;
ItemSpacing - Horizontal and vertical spacing between widgets/lines
ItemInnerSpacing - Spacing within elements of a composed widget
IndentSpacing - Horizontal indentation when entering a tree node
CellPadding - Padding within a table cell
style . ItemSpacing = ImVec2 ( 8 , 4 );
style . ItemInnerSpacing = ImVec2 ( 4 , 4 );
style . IndentSpacing = 21.0 f ;
TabRounding - Radius of upper corners of a tab
TabBorderSize - Thickness of border around tabs
TabBarBorderSize - Thickness of tab-bar separator
TabBarOverlineSize - Thickness of tab-bar overline
style . TabRounding = 4.0 f ;
style . TabBarBorderSize = 1.0 f ;
style . TabBarOverlineSize = 2.0 f ;
Color Scheme
Dear ImGui uses an enum ImGuiCol_ to identify 58 different color elements:
Text Colors
ImGuiCol_Text // Regular text
ImGuiCol_TextDisabled // Disabled/grayed out text
ImGuiCol_TextLink // Hyperlink color
ImGuiCol_TextSelectedBg // Selected text inside an InputText
Window Colors
ImGuiCol_WindowBg // Background of normal windows
ImGuiCol_ChildBg // Background of child windows
ImGuiCol_PopupBg // Background of popups, menus, tooltips
ImGuiCol_Border // Border color
ImGuiCol_BorderShadow // Border shadow
Frame Colors
ImGuiCol_FrameBg // Background of checkbox, radio button, plot, slider, text input
ImGuiCol_FrameBgHovered // Frame background when hovered
ImGuiCol_FrameBgActive // Frame background when active
Title Bar Colors
ImGuiCol_TitleBg // Title bar
ImGuiCol_TitleBgActive // Title bar when focused
ImGuiCol_TitleBgCollapsed // Title bar when collapsed
ImGuiCol_Button // Button background
ImGuiCol_ButtonHovered // Button background when hovered
ImGuiCol_ButtonActive // Button background when active/clicked
ImGuiCol_CheckMark // Checkbox tick and RadioButton circle
ImGuiCol_SliderGrab // Slider grab
ImGuiCol_SliderGrabActive // Slider grab when active
Tab Colors
ImGuiCol_Tab // Tab background when unselected
ImGuiCol_TabSelected // Tab background when selected
ImGuiCol_TabSelectedOverline // Tab horizontal overline when selected
ImGuiCol_TabHovered // Tab background when hovered
ImGuiCol_TabDimmed // Tab background when unfocused & unselected
ImGuiCol_TabDimmedSelected // Tab background when unfocused & selected
Table Colors
ImGuiCol_TableHeaderBg // Table header background
ImGuiCol_TableBorderStrong // Table outer and header borders
ImGuiCol_TableBorderLight // Table inner borders
ImGuiCol_TableRowBg // Table row background (even rows)
ImGuiCol_TableRowBgAlt // Table row background (odd rows)
Modifying Colors
Direct Modification
ImGuiStyle & style = ImGui :: GetStyle ();
style . Colors [ImGuiCol_Text] = ImVec4 ( 1.0 f , 1.0 f , 1.0 f , 1.0 f ); // White
style . Colors [ImGuiCol_WindowBg] = ImVec4 ( 0.06 f , 0.06 f , 0.06 f , 0.94 f ); // Dark gray
style . Colors [ImGuiCol_Button] = ImVec4 ( 0.26 f , 0.59 f , 0.98 f , 0.40 f ); // Blue
Temporary Color Changes
Use PushStyleColor() and PopStyleColor() to temporarily change colors:
// Push color changes
ImGui :: PushStyleColor (ImGuiCol_Button, ImVec4 ( 1.0 f , 0.0 f , 0.0 f , 1.0 f )); // Red button
ImGui :: PushStyleColor (ImGuiCol_ButtonHovered, ImVec4 ( 1.0 f , 0.3 f , 0.3 f , 1.0 f )); // Light red when hovered
ImGui :: PushStyleColor (ImGuiCol_ButtonActive, ImVec4 ( 0.8 f , 0.0 f , 0.0 f , 1.0 f )); // Dark red when clicked
if ( ImGui :: Button ( "Delete" )) {
// Danger action
}
ImGui :: PopStyleColor ( 3 ); // Pop all 3 color changes
Always match your PushStyleColor() calls with PopStyleColor()! Mismatched push/pop will cause visual glitches.
Using ImU32 Colors
// Using packed 32-bit color
ImGui :: PushStyleColor (ImGuiCol_Text, IM_COL32 ( 255 , 255 , 0 , 255 )); // Yellow text
ImGui :: Text ( "This text is yellow" );
ImGui :: PopStyleColor ();
Modifying Style Variables
Use PushStyleVar() and PopStyleVar() for temporary style changes:
// Make windows more rounded temporarily
ImGui :: PushStyleVar (ImGuiStyleVar_WindowRounding, 10.0 f );
ImGui :: Begin ( "Rounded Window" );
ImGui :: Text ( "This window has rounded corners" );
ImGui :: End ();
ImGui :: PopStyleVar ();
Common Style Variables
// Modify padding
ImGui :: PushStyleVar (ImGuiStyleVar_WindowPadding, ImVec2 ( 20 , 20 ));
ImGui :: PushStyleVar (ImGuiStyleVar_FramePadding, ImVec2 ( 10 , 5 ));
// Modify spacing
ImGui :: PushStyleVar (ImGuiStyleVar_ItemSpacing, ImVec2 ( 10 , 5 ));
// Modify rounding
ImGui :: PushStyleVar (ImGuiStyleVar_FrameRounding, 5.0 f );
ImGui :: PushStyleVar (ImGuiStyleVar_GrabRounding, 3.0 f );
// Your UI code here
ImGui :: PopStyleVar ( 5 ); // Pop all 5 changes
Built-in Themes
Dear ImGui provides three built-in color themes:
Dark Theme (Default)
ImGui :: StyleColorsDark ();
A dark theme suitable for most applications. This is the recommended default style.
Light Theme
ImGui :: StyleColorsLight ();
A light theme best used with borders and a custom, thicker font.
Classic Theme
ImGui :: StyleColorsClassic ();
The classic ImGui style from earlier versions.
Style Editor
Dear ImGui includes a built-in style editor for live customization:
ImGui :: Begin ( "Style Editor" );
ImGui :: ShowStyleEditor ();
ImGui :: End ();
You can also compare against a reference style:
ImGuiStyle ref = ImGuiStyle (); // Default style
ImGui :: ShowStyleEditor ( & ref);
Complete Styling Example
void SetupCustomStyle ()
{
ImGuiStyle & style = ImGui :: GetStyle ();
// Rounding
style . WindowRounding = 5.0 f ;
style . FrameRounding = 3.0 f ;
style . ScrollbarRounding = 2.0 f ;
style . GrabRounding = 2.0 f ;
style . TabRounding = 4.0 f ;
// Spacing
style . WindowPadding = ImVec2 ( 10 , 10 );
style . FramePadding = ImVec2 ( 8 , 4 );
style . ItemSpacing = ImVec2 ( 8 , 4 );
style . ItemInnerSpacing = ImVec2 ( 4 , 4 );
// Borders
style . WindowBorderSize = 1.0 f ;
style . FrameBorderSize = 0.0 f ;
// Colors
ImVec4 * colors = style . Colors ;
colors [ImGuiCol_Text] = ImVec4 ( 1.00 f , 1.00 f , 1.00 f , 1.00 f );
colors [ImGuiCol_TextDisabled] = ImVec4 ( 0.50 f , 0.50 f , 0.50 f , 1.00 f );
colors [ImGuiCol_WindowBg] = ImVec4 ( 0.10 f , 0.10 f , 0.10 f , 1.00 f );
colors [ImGuiCol_ChildBg] = ImVec4 ( 0.00 f , 0.00 f , 0.00 f , 0.00 f );
colors [ImGuiCol_PopupBg] = ImVec4 ( 0.08 f , 0.08 f , 0.08 f , 0.94 f );
colors [ImGuiCol_Border] = ImVec4 ( 0.43 f , 0.43 f , 0.50 f , 0.50 f );
colors [ImGuiCol_FrameBg] = ImVec4 ( 0.16 f , 0.29 f , 0.48 f , 0.54 f );
colors [ImGuiCol_FrameBgHovered] = ImVec4 ( 0.26 f , 0.59 f , 0.98 f , 0.40 f );
colors [ImGuiCol_FrameBgActive] = ImVec4 ( 0.26 f , 0.59 f , 0.98 f , 0.67 f );
colors [ImGuiCol_TitleBg] = ImVec4 ( 0.04 f , 0.04 f , 0.04 f , 1.00 f );
colors [ImGuiCol_TitleBgActive] = ImVec4 ( 0.16 f , 0.29 f , 0.48 f , 1.00 f );
colors [ImGuiCol_Button] = ImVec4 ( 0.26 f , 0.59 f , 0.98 f , 0.40 f );
colors [ImGuiCol_ButtonHovered] = ImVec4 ( 0.26 f , 0.59 f , 0.98 f , 1.00 f );
colors [ImGuiCol_ButtonActive] = ImVec4 ( 0.06 f , 0.53 f , 0.98 f , 1.00 f );
}
Tips and Best Practices
Always use PushStyleColor()/PushStyleVar() to modify styles mid-frame
Direct modification of ImGuiStyle should be done at initialization or between frames
Use the built-in style editor during development to experiment with values
Keep track of push/pop pairs to avoid style stack errors
See Also