Custom Title Bar
Basic tutorial
Application windows have a default chrome applied by the OS. Not to be confused with the Google Chrome browser, window chrome refers to the parts of the window (e.g. title bar, toolbars, controls) that are not a part of the main web content. While the default title bar provided by the OS chrome is sufficient for simple use cases, many applications opt to remove it. Implementing a custom title bar can help your application feel more modern and consistent across platforms.
You can follow along with this tutorial by opening Fiddle with the following starter code.
Let’s start by configuring a window with native window controls and a hidden title bar.
To remove the default title bar, set the BaseWindowContructorOptions titleBarStyle
param in the BrowserWindow constructor to 'hidden'.
On macOS, setting titleBarStyle: 'hidden' removes the title bar while keeping the window’s
traffic light controls available in the upper left hand corner. However on Windows and Linux,
you’ll need to add window controls back into your BrowserWindow by setting the
BaseWindowContructorOptions titleBarOverlay param in the BrowserWindow constructor.
Create a custom title bar
Now, let’s implement a simple custom title bar in the webContents of our BrowserWindow.
There’s nothing fancy here, just HTML and CSS!
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<metahttp-equiv="Content-Security-Policy"content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'">
<linkhref="./styles.css"rel="stylesheet">
<title>Custom Titlebar App</title>
</head>
<body>
<!-- mount your title bar at the top of you application's body tag -->
<divclass="titlebar">Cool titlebar</div>
</body>
</html>
body{
margin:0;
}
.titlebar{
height:30px;
background:blue;
color:white;
display: flex;
justify-content: center;
align-items: center;
}
Currently our application window can’t be moved. Since we’ve removed the default title bar,
the application needs to tell Electron which regions are draggable. We’ll do this by adding
the CSS style app-region: drag to the custom title bar. Now we can drag the custom title
bar to reposition our app window!
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<metahttp-equiv="Content-Security-Policy"content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'">
<linkhref="./styles.css"rel="stylesheet">
<title>Custom Titlebar App</title>
</head>
<body>
<!-- mount your title bar at the top of you application's body tag -->
<divclass="titlebar">Cool titlebar</div>
</body>
</html>
body{
margin:0;
}
.titlebar{
height:30px;
background:blue;
color:white;
display: flex;
justify-content: center;
align-items: center;
app-region: drag;
}