Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ocornut/imgui/llms.txt

Use this file to discover all available pages before exploring further.

Buttons are fundamental interactive widgets that respond to user clicks. Dear ImGui provides several button types for different use cases.

Standard Button

Button()

Create a clickable button that returns true when pressed:
IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0, 0));
label
const char*
required
The text displayed on the button
size
ImVec2
default:"ImVec2(0, 0)"
Button size in pixels. Use (0,0) for auto-sizing to fit the label.
static int clicked = 0;
if (ImGui::Button("Click Me")) {
    clicked++;
}
if (clicked & 1) {
    ImGui::SameLine();
    ImGui::Text("Thanks for clicking me!");
}

Button Variants

SmallButton()

A button with reduced padding, useful for embedding in text:
IMGUI_API bool SmallButton(const char* label);
ImGui::Text("Inline button:"); 
ImGui::SameLine();
if (ImGui::SmallButton("small")) {
    // Button clicked
}

InvisibleButton()

A button without visual decoration, useful for custom rendering:
IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size, ImGuiButtonFlags flags = 0);
str_id
const char*
required
String identifier (not displayed)
size
ImVec2
required
Button size in pixels
flags
ImGuiButtonFlags
Optional button flags:
  • ImGuiButtonFlags_MouseButtonLeft (default)
  • ImGuiButtonFlags_MouseButtonRight
  • ImGuiButtonFlags_MouseButtonMiddle
if (ImGui::InvisibleButton("##invisible", ImVec2(100, 100))) {
    // Clicked
}

// Right-click button
if (ImGui::InvisibleButton("##context", ImVec2(50, 50), ImGuiButtonFlags_MouseButtonRight)) {
    ImGui::OpenPopup("context_menu");
}

ArrowButton()

A button displaying a directional arrow:
IMGUI_API bool ArrowButton(const char* str_id, ImGuiDir dir);
dir
ImGuiDir
required
Arrow direction:
  • ImGuiDir_Left
  • ImGuiDir_Right
  • ImGuiDir_Up
  • ImGuiDir_Down
static int counter = 0;
float spacing = ImGui::GetStyle().ItemInnerSpacing.x;

if (ImGui::ArrowButton("##left", ImGuiDir_Left)) { counter--; }
ImGui::SameLine(0.0f, spacing);
if (ImGui::ArrowButton("##right", ImGuiDir_Right)) { counter++; }
ImGui::SameLine();
ImGui::Text("%d", counter);

Button Modifiers

Repeating Buttons

Make buttons fire continuously while held down:
static int counter = 0;
float spacing = ImGui::GetStyle().ItemInnerSpacing.x;

ImGui::PushItemFlag(ImGuiItemFlags_ButtonRepeat, true);
if (ImGui::ArrowButton("##left", ImGuiDir_Left)) { counter--; }
ImGui::SameLine(0.0f, spacing);
if (ImGui::ArrowButton("##right", ImGuiDir_Right)) { counter++; }
ImGui::PopItemFlag();

ImGui::SameLine();
ImGui::Text("%d", counter);
With ImGuiItemFlags_ButtonRepeat enabled, the button returns true multiple times while held, not just on initial press.

Colored Buttons

Customize button colors using style modifiers:
// Single colored button
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.0f, 0.2f, 0.2f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.8f, 0.0f, 0.0f, 1.0f));
if (ImGui::Button("Red Button")) {
    // Clicked
}
ImGui::PopStyleColor(3);

// Multiple colored buttons with HSV
for (int i = 0; i < 7; i++) {
    if (i > 0) ImGui::SameLine();
    ImGui::PushID(i);
    ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::HSV(i / 7.0f, 0.6f, 0.6f));
    ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::HSV(i / 7.0f, 0.7f, 0.7f));
    ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::HSV(i / 7.0f, 0.8f, 0.8f));
    ImGui::Button("Click");
    ImGui::PopStyleColor(3);
    ImGui::PopID();
}

Checkbox and Radio Buttons

Checkbox()

Toggle boolean values:
IMGUI_API bool Checkbox(const char* label, bool* v);
IMGUI_API bool CheckboxFlags(const char* label, int* flags, int flags_value);
IMGUI_API bool CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value);
static bool check = true;
ImGui::Checkbox("Enable Feature", &check);

if (check) {
    ImGui::Text("Feature is enabled");
}

RadioButton()

Select one option from a group:
IMGUI_API bool RadioButton(const char* label, bool active);
IMGUI_API bool RadioButton(const char* label, int* v, int v_button);
static int selected = 0;
if (ImGui::RadioButton("Option A", selected == 0)) selected = 0;
if (ImGui::RadioButton("Option B", selected == 1)) selected = 1;
if (ImGui::RadioButton("Option C", selected == 2)) selected = 2;

Image Buttons

ImageButton()

Create a button with an image:
IMGUI_API bool ImageButton(const char* str_id, ImTextureRef tex_ref, const ImVec2& image_size,
                           const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1, 1),
                           const ImVec4& bg_col = ImVec4(0, 0, 0, 0), 
                           const ImVec4& tint_col = ImVec4(1, 1, 1, 1));
str_id
const char*
required
String identifier for the button
tex_ref
ImTextureRef
required
Texture reference (your texture ID cast to ImTextureRef)
image_size
ImVec2
required
Size of the image to display
uv0, uv1
ImVec2
default:"(0,0), (1,1)"
UV coordinates for the image texture
ImTextureRef my_texture = /* your texture */;
ImVec2 button_size = ImVec2(32.0f, 32.0f);

for (int i = 0; i < 8; i++) {
    ImGui::PushID(i);
    if (i > 0) ImGui::SameLine();
    
    ImVec4 bg_col = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
    ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
    
    if (ImGui::ImageButton("", my_texture, button_size, 
                           ImVec2(0, 0), ImVec2(1, 1), bg_col, tint_col)) {
        // Button clicked
    }
    ImGui::PopID();
}

Button with Tooltip

Add tooltips to buttons for additional information:
ImGui::Button("Hover Me");
ImGui::SetItemTooltip("This is a tooltip");

// Or using BeginItemTooltip for complex tooltips
ImGui::Button("Advanced");
if (ImGui::BeginItemTooltip()) {
    ImGui::Text("This is a more complex tooltip");
    ImGui::BulletText("Feature 1");
    ImGui::BulletText("Feature 2");
    ImGui::EndTooltip();
}

Complete Example

void ShowButtonDemo() {
    ImGui::Begin("Button Demo");
    
    // Standard button
    static int click_count = 0;
    if (ImGui::Button("Standard Button")) {
        click_count++;
    }
    ImGui::Text("Clicked %d times", click_count);
    
    ImGui::Spacing();
    
    // Small button
    ImGui::Text("Inline:"); ImGui::SameLine();
    if (ImGui::SmallButton("small")) {
        // Clicked
    }
    
    ImGui::Spacing();
    
    // Arrow buttons with repeat
    static int counter = 0;
    ImGui::PushItemFlag(ImGuiItemFlags_ButtonRepeat, true);
    if (ImGui::ArrowButton("##left", ImGuiDir_Left)) counter--;
    ImGui::SameLine();
    if (ImGui::ArrowButton("##right", ImGuiDir_Right)) counter++;
    ImGui::PopItemFlag();
    ImGui::SameLine();
    ImGui::Text("%d", counter);
    
    ImGui::Spacing();
    
    // Checkbox
    static bool enabled = true;
    ImGui::Checkbox("Enable Feature", &enabled);
    
    ImGui::Spacing();
    
    // Radio buttons
    static int selection = 0;
    ImGui::RadioButton("Option A", &selection, 0); ImGui::SameLine();
    ImGui::RadioButton("Option B", &selection, 1); ImGui::SameLine();
    ImGui::RadioButton("Option C", &selection, 2);
    
    ImGui::Spacing();
    
    // Colored button
    ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 1.0f));
    ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.9f, 0.3f, 0.3f, 1.0f));
    ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.7f, 0.1f, 0.1f, 1.0f));
    if (ImGui::Button("Danger Button")) {
        // Perform dangerous action
    }
    ImGui::PopStyleColor(3);
    
    ImGui::End();
}

Best Practices

Use PushID() / PopID() or the ## label syntax when you need multiple buttons with the same label.
Button size (0,0) means auto-size. Use (-FLT_MIN, 0) for full-width buttons.

Build docs developers (and LLMs) love