@{}

Razor Formatter

NewCtrl+N
Open file(s)Ctrl+O
PasteCtrl+V
DownloadCtrl+S
Download all
Compare two files
Copy link with settings
Export settings
Import settings
Import .editorconfig
Undo formatCtrl+Z
Copy formattedCtrl+Shift+C
Copy with highlighting
Format selectionCtrl+Shift+S
Find in outputCtrl+F
Go to lineCtrl+G
FormatCtrl+Enter
Collapse @() expressions
Sort directives
Normalise blank lines
Blank lines around tags
Auto-copy on format
Format on paste
Error checking
Collapse after format
Indent guides
Format on type
Accessibility checker
Indent: Tab
Indent: 4 spaces
Indent: 2 spaces
Custom components...
Reset all to defaults
Diff viewCtrl+D
Word-level diff
Word wrap
Component report
Collapse input
Collapse output
Restore panels
Toggle horizontal/vertical
Minimal mode
Larger fontCtrl+=
Smaller fontCtrl+−
Font: Fira Code
Font: JetBrains Mono
Font: Source Code Pro
Toggle themeCtrl+T
How it works
Features
Take the tour
Keyboard shortcuts
Load sample
My stats
💜 Say thanks
Version
0 lines
0 changed
0 @()
0 errors
0 chars
You have unsaved work from a previous session.
Compare mode: drop or open two files
Input
Output
INPUT ▸
◂ OUTPUT
How It Works

1. Pre-processing

Multi-line @() expressions are collapsed. Directives sorted by convention. Blank lines normalised.

2. Formatting

Each line classified as tag, brace, Razor block, or content. A state machine tracks quoted attributes and @() depth across multi-line tags. Indent adjusted per line type.

3. Blazor awareness

20+ built-in components registered. Self-closing vs container detected across multi-line spans. Custom components via Format menu.

4. Razor C#

Allman braces: @if/@foreach don't indent (the { handles it). else/catch stay level with preceding }.

5. Post-processing

Error detection (unclosed tags, braces), accessibility checks, fold map, and LCS diff all run in a Web Worker off the main thread.

Keyboard Shortcuts
FormatCtrl+Enter
Format selectionCtrl+Shift+S
Copy formattedCtrl+Shift+C
Open filesCtrl+O
DownloadCtrl+S
ClearCtrl+N
Diff viewCtrl+D
Find in outputCtrl+F
Go to lineCtrl+G
ThemeCtrl+T
Font largerCtrl+=
Font smallerCtrl+−
IndentTab
OutdentShift+Tab
CloseEsc
Features
Formatting
Razor + HTML + C# — Allman braces, multi-line tags, Razor expression tracking
Directive sorting — @page, @using, @inject ordered by convention
Expression collapsing — multi-line @() collapsed to single lines
20+ Blazor components — InputText, EditForm, AuthorizeView and more
Custom components — add your own, persisted across sessions
Format on type — live preview as you writeFormat menu
Format on paste — paste messy code, get clean code
Format selection — format only highlighted textCtrl+Shift+S
🔍Output & Navigation
Virtual scrolling — 30k lines, ~100 DOM nodes
Syntax highlighting — 10 token types, cached per line
Code folding — collapse blocks, tags, Razor regions
Indent guides — vertical nesting depth indicators
Find — search and navigate matchesCtrl+F
Go to line — jump to any line numberCtrl+G
Bracket matching — click { or <tag> to highlight its pair
🔄Diff & Analysis
LCS diff — real algorithm, not positionalCtrl+D
Word-level diff — highlights exact words that changed
Compare two files — raw side-by-side diffFile menu
Error detection — unclosed tags, unmatched braces
Accessibility checker — missing alt, aria-label, empty linksFormat menu
Component report — usage count per Blazor componentView menu
📁Files & Settings
Multi-file batch — open many files, tabs, batch download
Drag & drop — .razor, .cshtml, .html
Auto-save — drafts saved every 5s, restored on next visit
Copy with highlighting — for docs and presentations
.editorconfig — import indent style from your project
Theme — light/dark, 3 fonts, adjustable sizeCtrl+T
Export & share — save settings or share as URL
🚀Performance & Privacy
Web Worker — formatting never freezes the UI
Smart caching — skips re-format if nothing changed
100% client-side — your code never leaves your browser
EU made & hosted — no tracking on code content
Custom Components

Add your Blazor component names (one per line). These will be treated as self-closing and won't trigger "unclosed" errors.

Component Report

Format code first to generate a report.

FormatCtrl+Enter
Format selectionCtrl+Shift+S
Copy formatted
Undo format
Collapse all
Expand all

The only formatter built for Razor

Every other formatter breaks your Blazor code. This one understands it.

Why Razor files are hard to format

Razor files mix three languages in one file: HTML markup, C# logic, and Blazor component syntax. Generic formatters like Prettier treat @if blocks as broken HTML. Visual Studio's built-in formatter doesn't handle multi-line tag attributes with Razor expressions like @(condition ? "value-a" : "value-b"). Razor Formatter was built from scratch to handle exactly these cases.

What it does

Paste any .razor or .cshtml file and get properly indented code in milliseconds. The formatter applies Allman-style braces for C# blocks, correctly indents nested Blazor components like EditForm, AuthorizeView, and InputSelect, sorts your @using and @inject directives by convention, and collapses multi-line Razor expressions. It knows the difference between self-closing components like InputText and container components like CascadingValue.

Built for real Blazor projects

Register your project's custom components so they're formatted correctly. Import your .editorconfig to match your team's indent style. Open multiple files at once with batch formatting. Compare two files with a proper LCS diff algorithm. Run an accessibility check to catch missing alt attributes and unlabelled inputs before they reach code review.

Private by design

Your code is processed entirely in your browser. Nothing is sent to any server, ever. The formatting engine runs in a Web Worker for performance, but it's still local JavaScript. No telemetry, no analytics on code content, no accounts required. Made and hosted in the EU by Tahleel Consultancy.

Fast enough for large files

Virtual scrolling renders only the visible lines, keeping the DOM under 100 nodes even for 30,000-line files. Syntax highlighting is cached per line with pre-compiled regex patterns. The diff engine caps at 8,000 trace steps to prevent memory issues. Smart dirty tracking means the formatter won't re-run if nothing has changed.

Free and open

Razor Formatter is free to use with no limits. No sign-up, no paywall, no ads. Format as many files as you need. Works on any device with a modern browser.

Razor Formatter supports .razor and .cshtml files for ASP.NET Core, Blazor Server, Blazor WebAssembly, and Blazor United (.NET 8+). Compatible with all modern browsers. Made by Tahleel Consultancy.