A code formatter rewrites source code into one consistent layout so that people argue about logic rather than spacing. This code formatter uses Prettier, the widely used opinionated formatter, and covers four languages that developers paste around all day: TypeScript, GraphQL, YAML and Markdown. Choose Format to beautify, Validate to find syntax errors, or Minify for GraphQL.
What the code formatter does
Prettier supports JavaScript, TypeScript, JSON, GraphQL, Markdown, YAML, HTML, CSS and more. [1] This page loads it in standalone form and adds only the plugin for the language you pick. TypeScript needs the TypeScript and estree plugins, GraphQL, YAML and Markdown each need one. Your code is parsed into a syntax tree and printed again from scratch, which is why the result looks the same no matter how the input was spaced.
Format and beautify
Paste code, pick the language and press Run. The tool applies Prettier with your choice of indent: two spaces, four spaces or tabs. Prettier's tab width setting defaults to two spaces, and the tabs option indents with tabs instead. [1] For TypeScript you can also choose single quotes. Prettier defaults to double quotes and, when a string contains more of one quote type, uses the less frequent one to avoid escapes. [1]
The same page works as a TypeScript beautifier, a GraphQL beautifier, a YAML beautifier and a Markdown beautifier. Markdown output is tidied too: a list written with asterisks becomes a list with dashes and headings get blank lines around them.
Validate and find the error line
Choose Validate to check syntax without keeping the formatted text. Because Prettier has to parse the code before it can print it, a syntax error stops it, and the error reports where. The tool shows the line and the column of the first problem, so you can jump straight to a missing bracket or a stray comma. This makes it a quick TypeScript validator and GraphQL validator for snippets.
Validation is about syntax. A valid result does not mean your TypeScript type-checks or that a GraphQL query matches your schema. Those checks need your project files, which this page does not have.
Minify GraphQL
In GraphQL the whitespace between tokens, commas and comments carry no meaning. The specification lists white space, line terminators, comments, commas and the byte order mark as ignored tokens, and says white space inside a string is significant. [2] The Minify action follows that rule. It removes comments, commas and spare white space, keeps strings and block strings intact and leaves a single space only where two names or numbers would otherwise run together. It parses the query with Prettier first, so broken GraphQL is rejected rather than minified.
Why other languages have no minify
YAML and Markdown give meaning to indentation and line breaks, so removing white space would change the document. TypeScript can only be minified safely by a full compiler that understands every construct. Rather than offer a risky option, the tool says so and suggests Format or Validate.
Worked example
Paste const a:number=1;interface A{b:string} with TypeScript selected. The result is const a: number = 1; followed by an interface block with b: string; on its own indented line. Paste query{user(id:1){name,email}} with GraphQL selected and you get a nested, indented query with name and email on separate lines. Switch to Minify and the query shrinks back to one short line.
Tips
- Format before you commit so diffs show real changes.
- Validate YAML before you put it in a CI or deployment file.
- Use single quotes if your TypeScript project style guide asks for them.
- If a long Markdown table looks wrong, check that every row has the same number of pipes.
Why use one consistent style
A shared layout removes whole classes of review comments. When every file is printed the same way, a diff shows only real changes, new contributors do not need to learn a house style, and merge conflicts caused by re-indenting disappear. Running a snippet through the formatter before you paste it into a bug report or a pull request also makes it easier for others to read. It is quick to try a few indent settings and see which one matches your project before you change any configuration files.
The formatter handles one language at a time, so split mixed content first. A Markdown file that contains a fenced TypeScript block is formatted as Markdown; copy the block out if you want the code inside it formatted as TypeScript.
Common mistakes
- Choosing the wrong language, which gives a syntax error on perfectly good code.
- Pasting JavaScript with JSX into the TypeScript option. This tool uses the plain TypeScript parser, so JSX in .tsx style may not parse.
- Expecting Validate to type-check. It only checks syntax.
- Minifying a GraphQL document with comments you need. Comments are removed.
Privacy and limits
Everything runs in your browser. The page accepts up to one million characters. Larger files are better handled with the Prettier command line in your project, which also reads your team configuration.
Related tools
For a dedicated YAML check with multiple documents, use the YAML validator. For JavaScript or CSS, the matching beautifier tools use the layout options those languages expect.
What next
Use this often? Add Code Formatt to your Home screen.
Frequently asked questions
What does this code formatter support?
TypeScript, GraphQL, YAML and Markdown. Each one is formatted with Prettier using its own parser, so TypeScript and GraphQL files follow the same rules a Prettier setup in your editor would.
How do I use it as a TypeScript validator or GraphQL validator?
Choose the language, paste the code and pick Validate. If the parser cannot read it you see the line and column of the first error. If it can, you see a valid message.
Does the formatter change what my code does?
No. Prettier changes layout, not meaning. It adds or removes white space, line breaks, semicolons and quotes according to its rules. It does not rename anything or reorder logic.
Can I minify YAML, Markdown or TypeScript here?
No. White space is meaningful in YAML and Markdown, and minifying TypeScript safely needs a full compiler. Minify is offered for GraphQL, where white space, commas and comments are ignored.
Is my code uploaded anywhere?
No. Prettier and its plugins run in your browser. Only the plugin for the language you choose is loaded.
Sources
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.