Browser Support
Modern Browsers
Chrome 90+, Firefox 88+, Edge 90+, Safari 15+
WebAssembly Required
All browsers must support WebAssembly and WebGL
Getting Started
Project Setup
Create a browser-based Avalonia application:src/Browser/Avalonia.Browser/BrowserAppBuilder.cs:66
Browser Platform Options
Configure browser-specific options:src/Browser/Avalonia.Browser/BrowserAppBuilder.cs:19
Rendering Modes
WebGL Rendering
Hardware-accelerated rendering in the browser:- WebGL 2
- WebGL 1
- Software
src/Browser/Avalonia.Browser/BrowserAppBuilder.cs:12
Automatic Fallback
Avalonia automatically tries rendering modes in order:HTML Integration
Single View Mode
Embed Avalonia in a specific HTML element:src/Browser/Avalonia.Browser/BrowserAppBuilder.cs:74
Multiple Views
Create multiple Avalonia views on one page:src/Browser/Avalonia.Browser/BrowserAppBuilder.cs:130
Browser Features
Supported Features
- Touch Input: Full touch and pointer support
- Keyboard: Standard keyboard input with IME
- Mouse: Mouse events and cursor management
- Clipboard: Browser clipboard API integration
- File Dialogs: Native or polyfilled file pickers
- Drag & Drop: Drag and drop support
- Screen Info: Browser viewport information
- Dark Mode: System theme detection
- Storage: Local storage integration
src/Browser/Avalonia.Browser/BrowserPlatformSettings.cs:7
Limited Features
- No Native Menus: Browser doesn’t support native menus
- No System Tray: Not applicable in browsers
- No Window Management: Runs in a div, not a window
- Limited File System: Sandboxed file access only
File System Access
File Picker
Use the browser file picker:src/Browser/Avalonia.Browser/Storage/BrowserStorageProvider.cs:8
File Picker Polyfill
For browsers without native file system API:JavaScript Interop
Calling JavaScript from C#
Use JSImport attributes:Calling C# from JavaScript
Expose C# methods to JavaScript:Browser Application Lifetime
Browser apps use a single view lifetime:src/Browser/Avalonia.Browser/BrowserSingleViewLifetime.cs:11
Responsive Design
Adapt to different screen sizes:Input Handling
Touch and Mouse
Browser supports both touch and mouse:src/Browser/Avalonia.Browser/BrowserInputHandler.cs:18
Keyboard Input
Clipboard Access
Access browser clipboard:src/Browser/Avalonia.Browser/BrowserClipboardDataTransfer.cs:11
Performance Optimization
WebGL Optimization
Loading Performance
- Trim Unused Code: Enable IL trimming
- Use AOT Compilation: Faster startup
- Minimize Assembly Size: Remove unused dependencies
- Lazy Load Resources: Load images on demand
- Compress Assets: Use compressed image formats
Runtime Performance
- Virtualize Lists: Use virtualizing panels
- Minimize Redraws: Avoid unnecessary invalidations
- Use Hardware Acceleration: Prefer WebGL
- Optimize Images: Use appropriate resolutions
- Cache Data: Store frequently used data
Threading Support
Enable threading in WebAssembly:src/Browser/Avalonia.Browser/BrowserAppBuilder.cs:62
Deployment
Build for Production
Hosting Requirements
- HTTPS: Required for many browser APIs
- MIME Types: Properly configure
.wasmfile types - CORS: Configure Cross-Origin Resource Sharing if needed
- Compression: Enable gzip/brotli compression
Web Server Configuration
IIS (web.config)
nginx
Browser Compatibility
Feature Detection
src/Browser/Avalonia.Browser/BrowserRuntimePlatform.cs:13
Limitations
Browser Sandbox
- Limited file system access
- No native process launching
- No direct hardware access
- Network requests subject to CORS
- Storage limited to browser APIs
Performance
- Slower than native desktop
- Depends on browser JavaScript engine
- Initial load time for WASM
- Memory limitations
Workarounds
- Use web APIs for file access
- Implement server-side operations
- Optimize asset loading
- Use progressive loading
Next Steps
Desktop Platforms
Build native desktop applications
Platform-Specific APIs
Access platform-specific features