# Getting Started

## Installation

HtmlFlow requires **Java 17 or later** and is published on
[Maven Central](https://central.sonatype.com/artifact/com.github.xmlet/htmlflow).
Add the core artifact for Java projects; Kotlin projects add the `htmlflow-kotlin`
artifact, which adds a Kotlin-friendly DSL on top of the core.

**Java**

```xml title="pom.xml (Maven)"
<dependency>
  <groupId>com.github.xmlet</groupId>
  <artifactId>htmlflow</artifactId>
  <version>5.0.4</version>
</dependency>
```

```groovy title="build.gradle (Gradle)"
implementation 'com.github.xmlet:htmlflow:5.0.4'
```

**Kotlin**

```xml title="pom.xml (Maven)"
<dependency>
  <groupId>com.github.xmlet</groupId>
  <artifactId>htmlflow-kotlin</artifactId>
  <version>5.0.4</version>
</dependency>
```

```groovy title="build.gradle (Gradle)"
implementation 'com.github.xmlet:htmlflow-kotlin:5.0.4'
```

## Quick Start

The quickest way to produce HTML is `HtmlFlow.doc(...)`, which writes directly to any
`Appendable`: `System.out`, a `StringBuilder`, a `Writer`, or other.
Build the document fluently and HtmlFlow emits the markup as you go.

**Java**

```java
import htmlflow.HtmlFlow;

public class Example {
  public static void main(String[] args) {
    HtmlFlow
      .doc(System.out)
        .html()
          .head()
            .title().text("Getting Started").__()
          .__() // head
          .body()
            .h1().text("Hello, HtmlFlow!").__()
            .p().text("Rendered with type-safe HTML.").__()
          .__() // body
        .__(); // html
  }
}
```

**Kotlin**

```kotlin
import htmlflow.*
import org.xmlet.htmlapifaster.*

fun main() {
  System.out.doc {
    html {
      head {
        title { text("Getting Started") }
      }
      body {
        h1 { text("Hello, HtmlFlow!") }
        p { text("Rendered with type-safe HTML.") }
      } // body
    } // html
  }
}
```

Running either program prints:

```html
<!DOCTYPE html>
<html>
  <head>
    <title>Getting Started</title>
  </head>
  <body>
    <h1>Hello, HtmlFlow!</h1>
    <p>Rendered with type-safe HTML.</p>
  </body>
</html>
```

`HtmlFlow.doc(...)` renders eagerly and is ideal for one-off documents. When you need to
render the **same** template repeatedly with different data (the common case in a web
application), use a reusable `HtmlFlow.view(...)`, which binds a data model and resolves
its static HTML only once. That, along with the rest of the API, is covered next in
[Core Concepts](https://htmlflow.org/docs/core-concepts).
