Guide · Open source
How to use webview: build a small C/C++ desktop GUI with HTML
Updated · written with AI from the project's own documentation and checked against our catalogue data
webview is a small C/C++ library that opens a native window containing a web view, so you can build a graphical app with HTML for the interface. This guide walks through the prerequisites, the official build commands and the basic C++ and C examples from the project README. By the end you will know how to build the example and what each platform needs.
Quick start
- 1Check prerequisites. Confirm your compiler supports C++11 (C++14 on Windows) and install CMake and Ninja if you want the recommended build flow.
- 2Install platform libraries. On Linux install GTK and WebKitGTK development packages; on Windows install the WebView2 runtime if you target versions before Windows 11.
- 3Clone the repository. Run git clone https://github.com/webview/webview to get the source.
- 4Configure the build. Run cmake -G Ninja -B build -S . -D CMAKE_BUILD_TYPE=Release from the project directory.
- 5Build the example. Run cmake --build build, then find the executable in the build/bin directory.
- 6Run and modify. Start the executable, then edit main.cc to change the title, window size or HTML content.
What webview is and who it suits
webview is a tiny cross-platform library for C and C++. It uses WebKit (through GTK and WebKitGTK) on Linux, Cocoa and WebKit on macOS, and the Windows API with Microsoft's WebView2 on Windows. The project's goal is a common HTML5 UI abstraction layer for the most widely used platforms.
It supports two-way JavaScript bindings, so C/C++ code can call JavaScript and JavaScript can call C/C++.
- Good fit: C or C++ developers who want an HTML-based GUI without bundling a full browser framework.
- Good fit: small desktop tools that need a simple window and web content.
- Not a fit: people who want a ready-made app rather than a library to compile into their own program.
- Not a fit: projects needing one identical rendering engine on every platform, since it relies on each system's web engine.
Check the prerequisites for your platform
Your compiler must support at least C++11. On Windows the README requires C++14, and recommends an up-to-date Windows 10 SDK with Visual Studio 2022 or later for Visual C++.
CMake and Ninja are recommended for convenience but are not required to use the library. On Linux and BSD you need the GTK and WebKitGTK development packages; check your distribution's package repositories for the exact names.
- Linux: GTK and WebKitGTK libraries, plus the dl library.
- macOS: the WebKit framework and the dl library.
- Windows: the WebView2 runtime must be installed on any Windows version before Windows 11, for both developers and end users.
- Windows libraries listed: advapi32, ole32, shell32, shlwapi, user32, version.
apt install libgtk-4-dev libwebkitgtk-6.0-devClone the repository and build the example
Clone the project from GitHub, then configure and build the example with CMake. The README uses Ninja as the generator and a Release build type.
When the build finishes, look for the executable in the build/bin directory.
git clone https://github.com/webview/webview
cmake -G Ninja -B build -S . -D CMAKE_BUILD_TYPE=Release
cmake --build buildWrite your first app with the C++ example
The README's getting-started example creates a new directory with a CMakeLists.txt, a main.cc file and a .gitignore that ignores the /build folder. The CMake file fetches webview with FetchContent at a pinned tag and links the webview::core target.
The C++ program creates a webview window, sets a title and size, loads a short HTML string, and runs the event loop. Errors are caught as webview::exception.
- CMakeLists.txt uses FetchContent_Declare and FetchContent_MakeAvailable to pull in webview.
- main.cc includes webview/webview.h and calls set_title, set_size and set_html.
- On Windows the example uses WinMain; other platforms use main.
webview::webview w(false, nullptr);
w.set_title("Basic Example");
w.set_size(480, 320, WEBVIEW_HINT_NONE);
w.set_html("Thanks for using webview!");
w.run();Use the C API or an amalgamated library
If you work in C, the README's C example links webview::core_static and uses functions such as webview_create, webview_set_title, webview_set_html, webview_run and webview_destroy. The project also offers an amalgamated single-header build, created with the amalgamate.py script or as part of the CMake build.
For projects without CMake, the README shows direct compiler commands for macOS, Linux and Windows. You place the amalgamated webview.h or the individual files in libs/webview, and WebView2.h in libs on Windows.
- CMake targets: webview::core (C++ headers), webview::core_shared and webview::core_static (C libraries).
- Amalgamation script: scripts/amalgamate/amalgamate.py, with --help for options.
python3 scripts/amalgamate/amalgamate.py --base core --search include --output webview_amalgamation.h srcKnow the limits before you start
Because webview relies on each system's web engine, the same page can render slightly differently on Linux, macOS and Windows. The README also notes that on some BSD systems you may need the wxallowed fstab option, and suggests trying without disabling W^X protection first.
The project's most up-to-date documentation is the source code itself, according to the README.
What people use it for
- Building a small desktop tool with a simple window and an HTML interface.
- Creating a C or C++ app whose UI is written in HTML and JavaScript.
- Dropping a single amalgamated header into an existing C or C++ project.
- Providing a C API that other languages can bind to.
Frequently asked questions
Is webview free to use?
webview is released under the MIT licence. The README does not describe any paid tier, so the library itself is open source under that licence.
What do I need to install to use webview?
You need a C++11 compiler (C++14 on Windows), and CMake and Ninja are recommended but optional. On Linux you need GTK and WebKitGTK development packages, and on Windows the WebView2 runtime is required before Windows 11.
Does webview work on Windows 10?
The README says developers and end users must have the WebView2 runtime installed on any Windows version before Windows 11. Install that runtime if you target Windows 10.
What is the difference between webview and Electron?
webview is a library you compile into your own C or C++ program, and it uses each system's native web engine. Electron is a framework for building JavaScript desktop apps; the comparison list for this item includes Electron, Tauri, Neutralinojs and Sciter as related projects.
Why does the build fail on Linux?
The README says GTK and WebKitGTK libraries are required, and that you should check your package repositories for the right packages. Make sure you installed the development packages, such as libgtk-4-dev and libwebkitgtk-6.0-dev on Debian, or the matching ones for your distribution.
Can I use webview from languages other than C and C++?
The project's design includes a C API that other languages can bind to. The README notes that the Go binding has moved to another repository, and versions up to 0.1.1 remain in this one.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
webview suits C and C++ developers who want a small HTML-based window without bundling a full browser framework. If you want a ready-made app or one identical rendering engine across platforms, or you have no C or C++ experience, pick a different tool.
Install options & downloads