# HTML Note: This guide applies to Dokka Gradle plugin (DGP) v2 mode. The DGP v1 mode is no longer supported. To upgrade from v1 to v2 mode, follow the [Migration guide](dokka-migration.html). HTML is Dokka's default and recommended output format. It provides support for Kotlin Multiplatform, Android, and Java projects. Additionally, you can use the HTML format to document both single and multi-project builds. For examples of the HTML output format, check the following docs: * [kotlinx.coroutines](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/) * [Bitmovin](https://cdn.bitmovin.com/player/android/3/docs/index.html) * [Hexagon](https://hexagontk.com/stable/api/) * [Ktor](https://api.ktor.io/) * [OkHttp](https://square.github.io/okhttp/5.x/okhttp/okhttp3/) * [Gradle](https://docs.gradle.org/current/kotlin-dsl/index.html) ## Generate HTML documentation HTML as an output format is supported by all runners. To generate HTML documentation, follow these steps depending on your build tool or runner: * For [Gradle](dokka-gradle.html#generate-documentation), you can run the following tasks: * `dokkaGenerate` to generate documentation in [all available formats based on the applied plugins](dokka-gradle.html#configure-documentation-output-format). This is the recommended task for most users. When using this task in IntelliJ IDEA, it logs a clickable link to the output. * `dokkaGeneratePublicationHtml` to generate documentation only in HTML format. This task exposes the output directory as an `@OutputDirectory`. Use this task when you need to consume the generated files in other Gradle tasks, such as uploading them to a server, moving them into a GitHub Pages directory, or packaging them into a `javadoc.jar`. This task is intentionally not listed in Gradle task groups because it is not meant for everyday use. Tip: If you're using IntelliJ IDEA, you may see the `dokkaGenerateHtml` Gradle task. This task is simply an alias of `dokkaGeneratePublicationHtml`. Both tasks perform exactly the same operation. * For [Maven](dokka-maven.html#generate-documentation), run the `dokka:dokka` goal. * For [CLI runner](dokka-cli.html#generate-documentation), run with HTML dependencies set. Note: HTML pages generated by this format need to be hosted on a web server in order to render everything correctly. You can use any free static site hosting service, such as [GitHub Pages](https://docs.github.com/en/pages/getting-started-with-github-pages/about-github-pages). Locally, you can use the [built-in IntelliJ web server](https://www.jetbrains.com/help/idea/php-built-in-web-server.html). ## Configuration HTML format is Dokka's base format. You can configure it using the following options: Gradle Kotlin DSL: ```KOTLIN // build.gradle.kts dokka { pluginsConfiguration.html { customAssets.from("logo.png") customStyleSheets.from("styles.css") footerMessage.set("(c) Your Company") separateInheritedMembers.set(false) templatesDir.set(file("dokka/templates")) mergeImplicitExpectActualDeclarations.set(false) } } ``` Gradle Groovy DSL: ```GROOVY // build.gradle dokka { pluginsConfiguration { html { customAssets.from("logo.png") customStyleSheets.from("styles.css") footerMessage.set("(c) Your Company") separateInheritedMembers.set(false) templatesDir.set(file("dokka/templates")) mergeImplicitExpectActualDeclarations.set(false) } } } ``` Maven: ```XML org.jetbrains.dokka dokka-maven-plugin ... ${project.basedir}/my-image.png ${project.basedir}/my-styles.css (c) MyOrg 2022 Maven false ${project.basedir}/dokka/templates false ``` CLI: Via [command line options](dokka-cli.html#run-with-command-line-options): ```BASH java -jar dokka-cli-2.2.0.jar \ ... -pluginsConfiguration "org.jetbrains.dokka.base.DokkaBase={\"customAssets\": [\"my-image.png\"], \"customStyleSheets\": [\"my-styles.css\"], \"footerMessage\": \"(c) 2022 MyOrg\", \"separateInheritedMembers\": false, \"templatesDir\": \"dokka/templates\", \"mergeImplicitExpectActualDeclarations\": false} " ``` Via [JSON configuration](dokka-cli.html#run-with-json-configuration): ```JSON { "moduleName": "Dokka Example", "pluginsConfiguration": [ { "fqPluginName": "org.jetbrains.dokka.base.DokkaBase", "serializationFormat": "JSON", "values": "{\"customAssets\": [\"my-image.png\"], \"customStyleSheets\": [\"my-styles.css\"], \"footerMessage\": \"(c) 2022 MyOrg\", \"separateInheritedMembers\": false, \"templatesDir\": \"dokka/templates\", \"mergeImplicitExpectActualDeclarations\": false}" } ] } ``` ### Configuration options The table below contains all the possible configuration options and their purpose: | Option |Description | ----------------------- | `customAssets` |List of paths for image assets to be bundled with documentation. The image assets can have any file extension. For more information, see [Customizing assets](#customize-assets). | | `customStyleSheets` |List of paths for `.css` stylesheets to be bundled with documentation and used for rendering. For more information, see [Customizing styles](#customize-styles). | | `templatesDir` |Path to the directory containing custom HTML templates. For more information, see [Templates](#templates). | | `footerMessage` |The text displayed in the footer. | | `separateInheritedMembers` |This is a boolean option. If set to `true`, Dokka renders properties/functions and inherited properties/inherited functions separately. This is disabled by default. | | `mergeImplicitExpectActualDeclarations` |This is a boolean option. If set to `true`, Dokka merges declarations that are not declared as [expect/actual](https://kotlinlang.org/docs/multiplatform-connect-to-apis.html), but have the same fully qualified name. This can be useful for legacy codebases. This is disabled by default. | For more information about configuring Dokka plugins, see [Configuring Dokka plugins](dokka-plugins.html#configure-dokka-plugins). ## Customization To help you add your own look and feel to your documentation, the HTML format supports a number of customization options. ### Customize styles You can use your own stylesheets by using the `customStyleSheets` [configuration option](#configuration). These are applied to every page. It's also possible to override Dokka's default stylesheets by providing files with the same name: | Stylesheet name |Description | -------------------------------- | `style.css` |Main stylesheet, contains most of the styles used across all pages | | `logo-styles.css` |Header logo styling | | `prism.css` |Styles for [PrismJS](https://prismjs.com/) syntax highlighter | The source code for all of Dokka's stylesheets is [available on GitHub](https://github.com/Kotlin/dokka/tree/2.2.0/dokka-subprojects/plugin-base/src/main/resources/dokka/styles). ### Customize assets You can provide your own images to be bundled with documentation by using the `customAssets` [configuration option](#configuration). These files are copied to the `/images` directory. You can use the `customAssets` property with collections of files ([FileCollection](https://docs.gradle.org/8.10/userguide/lazy_configuration.html#working_with_files_in_lazy_properties)): ```KOTLIN customAssets.from("example.png", "example2.png") ``` It's possible to override Dokka's images and icons by providing files with the same name. The most useful and relevant one is `logo-icon.svg`, which is the image used in the header. The rest is mostly icons. You can find all images used by Dokka on [GitHub](https://github.com/Kotlin/dokka/tree/2.2.0/dokka-subprojects/plugin-base/src/main/resources/dokka/images). ### Change the logo To customize the logo, you can begin by [providing your own asset](#customize-assets) for `logo-icon.svg`. If you don't like how it looks, or you want to use a `.png` file instead of the default `.svg` file, you can [override the logo-styles.css stylesheet](#customize-styles) to customize it. For an example of how to do this, see our [custom format example project](https://github.com/Kotlin/dokka/tree/2.2.0/examples/gradle/dokka-customFormat-example). The maximum supported logo dimensions are 120 pixels in width and 36 pixels in height. If you use a larger image, it will be automatically resized. ### Modify the footer You can modify text in the footer by using the `footerMessage` [configuration option](#configuration). ### Templates Dokka provides the ability to modify [FreeMarker](https://freemarker.apache.org/) templates used for generating documentation pages. You can change the header completely, add your own banners/menus/search, load analytics, change body styling, and so on. Dokka uses the following templates: | Template |Description | ------------------------- | `base.ftl` |Defines the general design of all pages to be rendered. | | `includes/header.ftl` |The page header that by default contains the logo, version, source set selector, light/dark theme switch, and search. | | `includes/footer.ftl` |The page footer that contains the `footerMessage` [configuration option](#configuration) and copyright. | | `includes/page_metadata.ftl` |Metadata used within `` container. | | `includes/source_set_selector.ftl` |[The source set](https://kotlinlang.org/docs/multiplatform-discover-project.html#source-sets) selector in the header. | The base template is `base.ftl` and it includes all the remaining listed templates. You can find the source code for all of Dokka's templates [on GitHub](https://github.com/Kotlin/dokka/tree/2.2.0/dokka-subprojects/plugin-base/src/main/resources/dokka/templates). You can override any template by using the `templatesDir` [configuration option](#configuration). Dokka searches for the exact template names within the given directory. If it fails to find user-defined templates, it uses the default templates. #### Variables The following variables are available inside all templates: | Variable |Description | ------------------------- | `${pageName}` |The page name | | `${footerMessage}` |The text which is set by the `footerMessage` [configuration option](#configuration) | | `${sourceSets}` |A nullable list of [source sets](https://kotlinlang.org/docs/multiplatform-discover-project.html#source-sets) for multi-platform pages. Each item has `name`, `platform`, and `filter` properties. | | `${projectName}` |The project name. It's available only within the `template_cmd` directive. | | `${pathToRoot}` |The path to root from the current page. It's useful for locating assets and is available only within the `template_cmd` directive. | Variables `projectName` and `pathToRoot` are available only within the `template_cmd` directive as they require more context, and thus they need to be resolved at later stages: ```HTML <@template_cmd name="projectName"> ${projectName} ``` #### Directives You can also use the following Dokka-defined [directives](https://freemarker.apache.org/docs/ref_directive_userDefined.html): | Variable |Description | ------------------------- | `<@content/>` |The main page content. | | `<@resources/>` |Resources such as scripts and stylesheets. | | `<@version/>` |The subproject version taken from configuration. If the [versioning plugin](https://github.com/Kotlin/dokka/tree/2.2.0/dokka-subprojects/plugin-versioning) is applied, it is replaced with a version navigator. |