A Kotlin formatter restructures Kotlin code with 4-space indentation (JetBrains Kotlin Coding Conventions), proper fun/class block indentation, when expression formatting, and blank lines between declarations. Whether you are formatting Android code or server-side Ktor services before a pull request, this tool applies Kotlin conventions automatically.
Formatted Kotlin will appear here...
Example Snippets
How to Use the Kotlin Formatter
Kotlin code generated by Android Studio, pasted from documentation, or written rapidly often has inconsistent indentation and spacing. A Kotlin formatter applies JetBrains Kotlin Coding Conventions — 4-space indentation, properly nested when expressions, and blank lines between top-level declarations — making your code review-ready.
Step 1: Paste Your Kotlin Code
Copy your Kotlin code — a class, function, or script block — and paste it into the input area. The formatter handles fun declarations, class/object/companion object blocks, when expressions, data class, sealed class, coroutines, and extension functions.
Step 2: Choose Indentation
Kotlin defaults to 4-space indentation per JetBrains guidelines. Select 2 spaces for compact output or tabs for tab-based codebases. Click Format Kotlin to apply.
Step 3: Copy or Download
The formatted Kotlin appears with syntax highlighting. Click Copy or Download to save as a .kt file.
Kotlin Formatting Conventions
The JetBrains Kotlin Coding Conventions specify: 4-space indentation, K&R brace style (opening brace on same line), blank line between top-level declarations, spaces around binary operators, and no space before colons. The when expression branches should each be on their own line indented within the block. These conventions are enforced by ktlint and IntelliJ IDEA's built-in Kotlin formatter.
FAQ
Is the Kotlin formatter free?
Yes, completely free with no signup required. Format unlimited Kotlin code in your browser.
Is my Kotlin code safe?
Yes. All formatting runs locally in your browser. Your Kotlin code is never sent to any server.
Does the formatter handle Kotlin-specific syntax?
Yes. The formatter handles fun declarations, class/object/companion object blocks, when expressions, data classes, coroutines (suspend fun), and Kotlin lambdas.
What indentation does Kotlin use?
Kotlin follows the same convention as Java and most JVM languages — 4-space indentation by default. The Kotlin Coding Conventions published by JetBrains specify 4 spaces.
Can I format minified Kotlin?
Yes. Paste any Kotlin code on a single line or with inconsistent indentation and the formatter will restructure it properly.
Does the formatter support Android Kotlin patterns?
Yes. The formatter handles standard Kotlin syntax used in both Android and server-side (Ktor/Spring) development including data classes, sealed classes, coroutines, and extension functions.