Chromium's Transition from GTK2 to GTK3 and GTK4 on Linux

This article provides an overview of how the Chromium web browser evolved its Linux desktop integration from GTK2 to GTK3, and eventually to GTK4. Over the years, Chromium shifted away from using native GTK widgets to build its interface, opting instead for its own custom graphics engine. Consequently, the transitions to GTK3 and GTK4 focused on updating how Chromium extracts system colors, fonts, and metrics from the host operating system to paint a simulated native look, alongside maintaining native file dialogs and input methods.

The GTK2 Era and the Shift to Aura

In its early days on Linux, Chromium used GTK2 directly to render the browser's user interface, such as the tab strip, address bar, and menus. In 2014, with the release of version 35, Chromium replaced this native GTK2 interface with "Aura," its own hardware-accelerated UI toolkit.

Even after adopting Aura, Chromium retained a dependency on GTK2 for native theme integration. Rather than using GTK2 to build the interface, Chromium created invisible, off-screen GTK2 widgets in memory. It queried these widgets using the GtkStyle API to determine the user's system colors, borders, and font settings, and then applied those values to its own Aura-based interface.

The Transition to GTK3

By 2017, most major Linux distributions had migrated to GTK3, leaving Chromium's GTK2 theme engine looking outdated and unable to match modern desktop themes. In Chromium 59, the browser officially switched its default Linux backend from GTK2 to GTK3.

This transition required a complete overhaul of the theme extraction code because GTK3 deprecated the old GtkStyle system in favor of a CSS-based styling engine called GtkStyleContext. To integrate with GTK3, Chromium developers programmed the browser to construct a virtual hierarchy of GTK3 style contexts. Chromium would query the CSS properties of these contexts—such as background colors, text colors, and state flags (like hover or active states)—and translate them into instructions for its internal rendering engine. Moving to GTK3 also allowed Chromium to support modern Linux features like per-monitor HiDPI scaling and updated native file picker dialogs.

The Transition to GTK4

As the GNOME project and Linux distributions began adopting GTK4, Chromium faced a new challenge. GTK4 introduced significant architectural changes, completely removing the ability to render foreign widget styles in the exact way Chromium had done with GTK3.

Starting around Chromium 106 in late 2022, developers introduced support for GTK4. To accomplish this, the Chromium team had to adapt to GTK4's scene-graph-based rendering model, known as GSK (GTK Scene Kit). Instead of relying on legacy drawing functions to sample widget pixels, Chromium was updated to parse GTK4 rendering nodes and CSS values directly to extract theme colors for the tab strip, toolbar, and context menus.

Dynamic Loading and Coexistence

A major hurdle in the GTK4 transition was that GTK3 and GTK4 symbols cannot exist in the same process simultaneously, and third-party browser plugins or system libraries might still require GTK3.

To solve this without maintaining two separate browser builds, Chromium developers changed how the browser links to GTK. Instead of linking to a specific GTK version at compile time, Chromium now loads the GTK library dynamically at runtime. By generating custom C++ wrappers around the GTK APIs, Chromium can detect the user's desktop environment at launch—or read a command-line flag like --gtk-version=4—and load the appropriate GTK3 or GTK4 shared library into memory to handle native theming, printing dialogs, and Wayland window management.