Styling SDL Titles

Is it possible to style the window title (e.g., bold text)?

Unfortunately, SDL does not support styling window titles. The title displayed in a window's border is entirely controlled by the operating system's window manager. This means you cannot apply styles like bold, italic, or color changes.

Workarounds for Styled Titles

If you need styled text, consider displaying it inside the window itself, rather than relying on the title bar. Use SDL rendering or a library like SDL_ttf for custom text rendering.

#include <SDL.h>
#include <SDL_ttf.h>
#include <string>

int main() {
  SDL_Init(SDL_INIT_VIDEO);
  TTF_Init();

  SDL_Window* window = SDL_CreateWindow(
    "Styled Title Example",
    SDL_WINDOWPOS_CENTERED,
    SDL_WINDOWPOS_CENTERED,
    800,
    600,
    SDL_WINDOW_SHOWN
  );

  SDL_Renderer* renderer = SDL_CreateRenderer(
    window, -1, SDL_RENDERER_ACCELERATED);
  TTF_Font* font =
    TTF_OpenFont("Arial.ttf", 24);
    
  // White text
  SDL_Color color = {255, 255, 255, 255};
  
  SDL_Surface* surface = TTF_RenderText_Blended(
    font, "Bold Title Inside Window", color);
    
  SDL_Texture* texture =
    SDL_CreateTextureFromSurface(
      renderer, surface);

  SDL_Rect dst = {
    200, 250, surface->w, surface->h};
  SDL_FreeSurface(surface);

  SDL_RenderClear(renderer);
  SDL_RenderCopy(renderer, texture, nullptr,
                 &dst);
  SDL_RenderPresent(renderer);

  SDL_Delay(3000);
  SDL_DestroyTexture(texture);
  TTF_CloseFont(font);
  SDL_DestroyRenderer(renderer);
  SDL_DestroyWindow(window);

  TTF_Quit();
  SDL_Quit();
}
Displays "Bold Title Inside Window" rendered in the window.

For styling, always work within your window's content area.

Window Titles

Learn how to set, get, and update window titles dynamically

Questions & Answers

Answers are generated by AI models and may not have been reviewed. Be mindful when running any code on your device.

Use Cases for SDL_SetWindowTitle()
What practical use cases are there for changing the window title during runtime?
Using Unicode in SDL Titles
Can I use Unicode characters in a window title?
Localizing SDL Titles
How do I localize window titles for different languages?
Dynamic Titles in SDL
Can I make the title reflect real-time data, like a countdown timer?
Using SDL_GetWindowFromID()
Why should I use SDL_GetWindowFromID() instead of passing the SDL_Window*?
Or Ask your Own Question
Get an immediate answer to your specific question using our AI assistant