API Documentation
Complete reference for the <browser-window> component
Attributes
Configure the component behavior using these HTML attributes.
| Attribute | Type | Default | Description |
|---|---|---|---|
url |
string | '' |
URL to display in the address bar. The hostname is extracted and shown as the title if no title attribute is set. |
title |
string | hostname from url | Title shown in the URL bar. Overrides the automatically extracted hostname. |
src |
string | '' |
Path to an HTML file to load in an iframe. When set, enables source viewing, sharing, and CodePen export features. |
mode |
'light' | 'dark' |
auto | Color scheme for the component. When omitted, automatically follows system preference via prefers-color-scheme. |
shadow |
boolean | false |
When present, adds a drop shadow around the browser window frame. |
Attribute Examples
Slots
Use slots to provide custom content inside the browser window.
| Slot | Description |
|---|---|
(default) |
The default slot accepts any content to display inside the browser window. Used when the src attribute is not set. Content automatically fills the available space. |
Slot Examples
CSS Custom Properties
Customize the appearance using CSS custom properties. Set these on the browser-window element or a parent container.
| Property | Default | Description |
|---|---|---|
--browser-window-bg |
#ffffff |
Background color of the entire component |
--browser-window-header-bg |
#f6f8fa |
Background color of the header/toolbar area |
--browser-window-border-color |
#d1d5da |
Border color for the window frame |
--browser-window-border-radius |
8px |
Border radius of the window corners |
--browser-window-text-color |
#24292e |
Primary text color |
--browser-window-text-muted |
#586069 |
Muted/secondary text color |
--browser-window-url-bg |
#ffffff |
Background color of the URL bar |
--browser-window-shadow |
0 4px 12px rgba(0,0,0,0.15) |
Box shadow when shadow attribute is set |
--browser-window-close-color |
#ff5f57 |
Color of the close (red) button |
--browser-window-minimize-color |
#febc2e |
Color of the minimize (yellow) button |
--browser-window-maximize-color |
#28c840 |
Color of the maximize (green) button |
--browser-window-accent-color |
#2563eb |
Accent color for interactive elements |
--browser-window-hover-bg |
#f3f4f6 |
Background color on hover for buttons |
--browser-window-content-bg |
#ffffff |
Background color of the content area |
--browser-window-font-family |
System fonts | Font family for text content |
--browser-window-mono-font |
Monospace fonts | Font family for code/monospace content |
Theming Example
CSS Parts
Style internal elements using the ::part() selector.
| Part | Description |
|---|---|
header |
The browser header/toolbar containing controls and URL bar |
content |
The content area containing the iframe or slotted content |
CSS Parts Example
Keyboard Shortcuts
The component supports keyboard navigation for accessibility.
| Key | Action |
|---|---|
Escape |
Close maximized view or close open menus |
Tab |
Navigate between interactive elements |
Enter / Space |
Activate focused button |
Features Reference
Source Code Viewing
When the src attribute is set, a code icon (</>) appears in the URL bar. Clicking it toggles between the rendered content and syntax-highlighted source code. The source view includes a "Copy" button to copy the code to clipboard.
Maximize Mode
Enter maximize mode by:
- Double-clicking the title bar
- Clicking the green maximize button
Exit maximize mode by:
- Pressing
Escape - Clicking the backdrop overlay
- Clicking the green button again
When maximized, the component displays as a centered modal with a backdrop and proper ARIA attributes (role="dialog", aria-modal="true").
Share Menu
When src is set, a share button provides:
- Share... - Uses the native Web Share API (on supported devices)
- Open in CodePen - Exports the demo to CodePen with HTML, CSS, and JS properly separated
Download
A download button appears when src is set, allowing direct download of the source HTML file.
Resizable
The component can be resized by dragging the bottom-right corner. Set initial dimensions using CSS:
Browser Support
Works in all modern browsers that support Web Components:
- Chrome/Edge 67+
- Firefox 63+
- Safari 10.1+
Accessibility
The component is built with accessibility in mind:
- Full keyboard navigation with visible focus indicators
- ARIA labels on all interactive elements
role="dialog"andaria-modalwhen maximized- Respects
prefers-reduced-motionfor animations - Touch targets meet WCAG 2.1 minimum size requirements (44px)