Dev · Formatter
TypeScript & TSX formatter using Prettier.
Paste TypeScript or TSX, pick indent, semicolons, quote style and print width, and get Prettier’s output. Formatting runs in your browser; your code is never uploaded. Syntax errors are reported with a line and column instead of being guessed at.
Inputs
Result
Loading Prettier…
Worked example
The default input above is three lines of compressed TSX. With 2-space indent, semicolons, double quotes and print width 80, Prettier 3.9.9 returns:
interface User {
id: number;
name: string;
}
const greet = (u: User): string => {
return "Hi, " + u.name;
};
export function App({ user }: { user: User }) {
return <div className="x">{greet(user)}</div>;
}
Change to 4 spaces, no semicolons, single quotes and print width 40 and the same code reflows: the App parameter list and the JSX element each break onto their own lines because they no longer fit in 40 columns, and every statement loses its trailing semicolon.
What each option does
These map one-to-one to Prettier’s documented options (Prettier options): indent sets tabWidth (2 or 4) or useTabs; semicolons sets semi (default true); quotes sets singleQuote (default false); print width sets printWidth (default 80). Print width is a target, not a hard limit: Prettier breaks lines that would exceed it, but a long string or identifier that cannot be split stays on one line. Prettier’s own rationale is in its rationale page.
How it runs in the browser
The page loads Prettier’s standalone build with the typescript parser plugin and the estree printer plugin from jsDelivr, as described in Prettier in the browser. Your code is passed to Prettier in the page and is not sent to any server. Only the two library files are downloaded, so you need a connection the first time. Other Prettier options (trailingComma, arrowParens, bracketSpacing) keep Prettier’s defaults here.
A second example: options that change the layout
Input (three declarations, one of them a generic function):
type Props={name:string;age?:number}
export const Card=({name,age}:Props)=>{const label=age?`${name} (${age})`:name;return <li className='card'>{label}</li>}
function pick<T,K extends keyof T>(o:T,k:K):T[K]{return o[k]}
With the defaults (TSX, 2 spaces, semicolons, double quotes, width 80) Prettier 3.9.9 returns:
type Props = { name: string; age?: number };
export const Card = ({ name, age }: Props) => {
const label = age ? `${name} (${age})` : name;
return <li className="card">{label}</li>;
};
function pick<T, K extends keyof T>(o: T, k: K): T[K] {
return o[k];
}
With 4 spaces, no semicolons, single quotes and print width 40, the same code becomes 23 lines. The Props type breaks into one member per line because it no longer fits in 40 columns, the Card parameter list and the ternary each break, the JSX element moves into parentheses, and pick’s parameters go one per line with a trailing comma. One detail to notice: the JSX attribute stayed className="card" with double quotes even with single quotes selected. The quote option here governs ordinary strings, while Prettier has a separate JSX quote setting that this page leaves at its default.
Format, compile and type-check are different jobs
People searching for “typescript online” often want a place to run TypeScript. This page does not compile or execute code and does not report type errors; it re-prints the syntax with consistent layout. If you want to see compiled JavaScript, hover types or errors, use the official TypeScript Playground. If you want a consistent style in a project, run Prettier in your editor or in CI so every file gets the same result.
.ts or .tsx: pick the right language
The Language menu matters because the two syntaxes disagree about angle brackets. In a .ts file, <string>value is a type assertion. In a .tsx file, angle brackets start JSX, so that form is not allowed and generic arrow functions need a trailing comma, as in <T,>(x: T) => x. If your file has no JSX, choose TypeScript (.ts) to avoid those restrictions.
Why the output may differ from your project’s
- Different Prettier version. Prettier 3.0 changed the default for trailing commas from “es5” to “all”, and Prettier 2.0 changed the default for arrow function parentheses from “avoid” to “always”. A project on an older major version prints differently.
- A configuration file. A
.prettierrcor editor setting can change print width, quotes, bracket spacing and end-of-line. This page does not read it. Only the five options on the form are set. - Print width is a target. Prettier breaks lines that would exceed it, but a long string or identifier that cannot be split stays on one line.
- Overrides and ignore files. A
// prettier-ignorecomment is respected, but ignore files such as.prettierignoreare not.
What it never changes
Prettier reprints from the syntax tree, so it ignores your original line breaks and spacing, except that it keeps blank lines between statements (collapsing runs of them to one) and a few other deliberate choices. It does not rename variables, reorder imports, remove unused code or fix type errors. If the code has a syntax error, the tool reports the line and column instead of printing a guess.
Sources
Each source below was opened and checked in October 2026 (retrieved 2026-10).
- Prettier, options: printWidth, tabWidth, useTabs, semi, singleQuote and trailingComma defaults, and the change history
- Prettier, rationale: what Prettier does and does not change, blank-line handling
- Prettier, browser / standalone usage: how the standalone build and parser plugins load in a page
- TypeScript Handbook, JSX: .tsx files and why angle-bracket type assertions are not allowed there
- TypeScript Playground: compile, run and inspect type errors online
Frequently asked questions
Will this match my project’s Prettier output?
Only if your project uses the same Prettier major version and the same options. Prettier 3 changed the trailingComma default to "all"; a project pinned to Prettier 2 or with a .prettierrc will differ. This page does not read config files.
Why does my generic arrow function fail in TSX?
In a .tsx file,
Does formatting change what my code does?
Prettier is designed to change layout (whitespace, line breaks, parentheses, quotes, semicolons) and not behaviour (see its rationale page). It does not type-check, so a file with type errors formats fine; only syntax errors are rejected.
Can I run or compile TypeScript here?
No. This page formats code only. To compile to JavaScript, run it or see type errors, use the TypeScript Playground or your local tsc setup.
What does the print width setting do?
It tells Prettier roughly how many columns a line may use before it breaks it. It is a target, not a hard limit: a long string literal or identifier that cannot be split stays on one line. The default is 80 and this page accepts 20 to 200.
Which should I choose, .ts or .tsx?
Choose .tsx if the code contains JSX elements such as
Why did my quotes not change inside JSX?
The Quotes option controls ordinary string literals. Prettier has a separate setting for JSX attribute quotes, which this page leaves at its default (double quotes), so className="x" stays double-quoted.
Is my code uploaded?
No. Prettier runs in your browser; the only downloads are the two library files. Your code is not sent to any server.
What this does and doesn’t
This formats syntax with Prettier. It does not type-check, lint, sort imports or read your project’s configuration. Facts above are from the Prettier documentation (prettier.io/docs), checked 2026-09-30; the library version in use is shown in the hero.