Kotlin Formatter
Format and beautify Kotlin source code online. Fix indentation and normalize Kotlin syntax.
Input
Output
What is Kotlin?
Kotlin is a modern, statically typed programming language that runs on the JVM and is the preferred language for Android development. It is fully interoperable with Java and offers concise, expressive syntax. You can read more on Wikipedia.
The Kotlin Formatter normalizes indentation (2 spaces per level), fixes brace alignment, and removes trailing whitespace — following the official Kotlin coding conventions. New to Kotlin? The Kotlin Tour is a great place to start.
How to Use
Paste your Kotlin code
Paste raw or messy Kotlin source code into the left editor, or click Upload to load a .kt file.
Instant formatting
The formatter automatically normalizes indentation (2 spaces), fixes brace and bracket alignment, and cleans up whitespace.
Copy or download
Use the Copy button to copy the result, or Download to save it as a main.kt file.
Formatting Example
Example: Format a Kotlin data class
Unformatted input:
data class User(val name:String,val age:Int){fun greet():String="Hello, $name!"
fun isAdult()=age>=18}Formatted output:
data class User(val name: String, val age: Int) {
fun greet(): String = "Hello, $name!"
fun isAdult() = age >= 18
}Frequently Asked Questions
Does this formatter handle Kotlin data classes?
Yes. Kotlin data class declarations with multi-line constructor parameters are handled by the parenthesis-based indentation logic, producing clean, readable output.
Can I format Kotlin Android code?
Yes — Android Kotlin code (Activities, ViewModels, Composables) is standard Kotlin syntax. Paste any .kt file content and the formatter will normalize its indentation.
Does this replace ktlint or detekt?
This is a lightweight online indentation formatter, not a full static analysis tool. For production Kotlin projects, ktlint or detekt provide comprehensive style checking aligned with the Kotlin coding conventions. This tool is ideal for quick formatting without setup.
Is my Kotlin code safe when I use this tool?
Yes, completely. All formatting runs directly in your browser — no code is ever uploaded to a server. Your Kotlin source stays private and secure at all times.