# HtmlCompat

# HtmlCompat

Artifact:[androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core)  
[View Source](https://cs.android.com/search?q=file:androidx/core/text/HtmlCompat.java+class:androidx.core.text.HtmlCompat)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/core/text/HtmlCompat "View this page in Java")

<br />

```
class HtmlCompat
```

<br />

*** ** * ** ***

Backwards compatible version of[Html](https://developer.android.com/reference/android/text/Html.html).

## Summary

|                                    ### Constants                                    |
|-------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [FROM_HTML_MODE_COMPACT](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#FROM_HTML_MODE_COMPACT())` = 63` Flags for[fromHtml](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#fromHtml(java.lang.String,int,android.text.Html.ImageGetter,android.text.Html.TagHandler)): Separate block-level elements with line breaks (single newline character) in between. |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [FROM_HTML_MODE_LEGACY](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#FROM_HTML_MODE_LEGACY())` = 0` Flags for[fromHtml](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#fromHtml(java.lang.String,int,android.text.Html.ImageGetter,android.text.Html.TagHandler)): Separate block-level elements with blank lines (two newline characters) in between.      |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [FROM_HTML_OPTION_USE_CSS_COLORS](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#FROM_HTML_OPTION_USE_CSS_COLORS())` = 256` Flag indicating that CSS color values should be used instead of those defined in[Color](https://developer.android.com/reference/android/graphics/Color.html).                                                                                                   |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE())` = 32` Flag indicating that texts inside`<blockquote>`elements will be separated from other texts with one newline character by default.                                                                                                            |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [FROM_HTML_SEPARATOR_LINE_BREAK_DIV](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#FROM_HTML_SEPARATOR_LINE_BREAK_DIV())` = 16` Flag indicating that texts inside`<div>elements will be separated from other texts with one newline character by default.`                                                                                                                                 |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [FROM_HTML_SEPARATOR_LINE_BREAK_HEADING](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#FROM_HTML_SEPARATOR_LINE_BREAK_HEADING())` = 2` Flag indicating that texts inside`<h1>`\~`<h6>`elements will be separated from other texts with one newline character by default.                                                                                                                   |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [FROM_HTML_SEPARATOR_LINE_BREAK_LIST](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#FROM_HTML_SEPARATOR_LINE_BREAK_LIST())` = 8` Flag indicating that texts inside`<ul>`elements will be separated from other texts with one newline character by default.                                                                                                                                 |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM())` = 4` Flag indicating that texts inside`<li>`elements will be separated from other texts with one newline character by default.                                                                                                                       |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH())` = 1` Flag indicating that texts inside`<p>`elements will be separated from other texts with one newline character by default.                                                                                                                        |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [TO_HTML_PARAGRAPH_LINES_CONSECUTIVE](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#TO_HTML_PARAGRAPH_LINES_CONSECUTIVE())` = 0` Option for[fromHtml](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#fromHtml(java.lang.String,int)): Wrap consecutive lines of text delimited by '\\n' inside`<p>`elements.                                                 |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [TO_HTML_PARAGRAPH_LINES_INDIVIDUAL](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#TO_HTML_PARAGRAPH_LINES_INDIVIDUAL())` = 1` Option for[fromHtml](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#fromHtml(java.lang.String,int)): Wrap each line of text delimited by '\\n' inside a`<p>`or a`<li>`element.                                                |

|                                      ### Public functions                                       |
|-------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Spanned](https://developer.android.com/reference/android/text/Spanned.html)      | [fromHtml](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#fromHtml(java.lang.String,int))`(source: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, flags: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Invokes[fromHtml](https://developer.android.com/reference/android/text/Html.html#fromHtml(java.lang.String, int))on API 24 and newer, otherwise`flags`are ignored and[fromHtml](https://developer.android.com/reference/android/text/Html.html#fromHtml(java.lang.String))is used.                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `java-static `[Spanned](https://developer.android.com/reference/android/text/Spanned.html)      | [fromHtml](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#fromHtml(java.lang.String,int,android.text.Html.ImageGetter,android.text.Html.TagHandler))`(` ` source: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`,` ` flags: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` imageGetter: `[Html.ImageGetter](https://developer.android.com/reference/android/text/Html.ImageGetter.html)`?,` ` tagHandler: `[Html.TagHandler](https://developer.android.com/reference/android/text/Html.TagHandler.html)`?` `)` Invokes[fromHtml](https://developer.android.com/reference/android/text/Html.html#fromHtml(java.lang.String, int, android.text.Html.ImageGetter, android.text.Html.TagHandler))on API 24 or newer, otherwise`flags`are ignored and[fromHtml](https://developer.android.com/reference/android/text/Html.html#fromHtml(java.lang.String, android.text.Html.ImageGetter, android.text.Html.TagHandler))is used. |
| `java-static `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | [toHtml](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#toHtml(android.text.Spanned,int))`(text: `[Spanned](https://developer.android.com/reference/android/text/Spanned.html)`, options: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Invokes[toHtml](https://developer.android.com/reference/android/text/Html.html#toHtml(android.text.Spanned, int))on API 24 or newer, otherwise`options`are ignored and[toHtml](https://developer.android.com/reference/android/text/Html.html#toHtml(android.text.Spanned))is used.                                                                                                                                                                                                                                                                                                                                                                                                                                      |

## Constants

### FROM_HTML_MODE_COMPACT

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
const val FROM_HTML_MODE_COMPACT = 63: Int
```

Flags for[fromHtml](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#fromHtml(java.lang.String,int,android.text.Html.ImageGetter,android.text.Html.TagHandler)): Separate block-level elements with line breaks (single newline character) in between. This inverts the[Spanned](https://developer.android.com/reference/android/text/Spanned.html)to HTML string conversion done with the option[TO_HTML_PARAGRAPH_LINES_INDIVIDUAL](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#TO_HTML_PARAGRAPH_LINES_INDIVIDUAL()).  

### FROM_HTML_MODE_LEGACY

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
const val FROM_HTML_MODE_LEGACY = 0: Int
```

Flags for[fromHtml](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#fromHtml(java.lang.String,int,android.text.Html.ImageGetter,android.text.Html.TagHandler)): Separate block-level elements with blank lines (two newline characters) in between. This is the legacy behavior prior to N.  

### FROM_HTML_OPTION_USE_CSS_COLORS

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
const val FROM_HTML_OPTION_USE_CSS_COLORS = 256: Int
```

Flag indicating that CSS color values should be used instead of those defined in[Color](https://developer.android.com/reference/android/graphics/Color.html).  

### FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
const val FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE = 32: Int
```

Flag indicating that texts inside`<blockquote>`elements will be separated from other texts with one newline character by default.  

### FROM_HTML_SEPARATOR_LINE_BREAK_DIV

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
const val FROM_HTML_SEPARATOR_LINE_BREAK_DIV = 16: Int
```

Flag indicating that texts inside`<div>elements will be separated from other texts with one newline character by default.`  

### FROM_HTML_SEPARATOR_LINE_BREAK_HEADING

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
const val FROM_HTML_SEPARATOR_LINE_BREAK_HEADING = 2: Int
```

Flag indicating that texts inside`<h1>`\~`<h6>`elements will be separated from other texts with one newline character by default.  

### FROM_HTML_SEPARATOR_LINE_BREAK_LIST

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
const val FROM_HTML_SEPARATOR_LINE_BREAK_LIST = 8: Int
```

Flag indicating that texts inside`<ul>`elements will be separated from other texts with one newline character by default.  

### FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
const val FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM = 4: Int
```

Flag indicating that texts inside`<li>`elements will be separated from other texts with one newline character by default.  

### FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
const val FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH = 1: Int
```

Flag indicating that texts inside`<p>`elements will be separated from other texts with one newline character by default.  

### TO_HTML_PARAGRAPH_LINES_CONSECUTIVE

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
const val TO_HTML_PARAGRAPH_LINES_CONSECUTIVE = 0: Int
```

Option for[fromHtml](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#fromHtml(java.lang.String,int)): Wrap consecutive lines of text delimited by '\\n' inside`<p>`elements.[BulletSpan](https://developer.android.com/reference/android/text/style/BulletSpan.html)s are ignored.  

### TO_HTML_PARAGRAPH_LINES_INDIVIDUAL

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
const val TO_HTML_PARAGRAPH_LINES_INDIVIDUAL = 1: Int
```

Option for[fromHtml](https://developer.android.com/reference/kotlin/androidx/core/text/HtmlCompat#fromHtml(java.lang.String,int)): Wrap each line of text delimited by '\\n' inside a`<p>`or a`<li>`element. This allows[ParagraphStyle](https://developer.android.com/reference/android/text/style/ParagraphStyle.html)s attached to be encoded as CSS styles within the corresponding`<p>`or`<li>`element.  

## Public functions

### fromHtml

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun fromHtml(source: String, flags: Int): Spanned
```

Invokes[fromHtml](https://developer.android.com/reference/android/text/Html.html#fromHtml(java.lang.String, int))on API 24 and newer, otherwise`flags`are ignored and[fromHtml](https://developer.android.com/reference/android/text/Html.html#fromHtml(java.lang.String))is used.  

### fromHtml

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun fromHtml(
    source: String,
    flags: Int,
    imageGetter: Html.ImageGetter?,
    tagHandler: Html.TagHandler?
): Spanned
```

Invokes[fromHtml](https://developer.android.com/reference/android/text/Html.html#fromHtml(java.lang.String, int, android.text.Html.ImageGetter, android.text.Html.TagHandler))on API 24 or newer, otherwise`flags`are ignored and[fromHtml](https://developer.android.com/reference/android/text/Html.html#fromHtml(java.lang.String, android.text.Html.ImageGetter, android.text.Html.TagHandler))is used.  

### toHtml

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun toHtml(text: Spanned, options: Int): String
```

Invokes[toHtml](https://developer.android.com/reference/android/text/Html.html#toHtml(android.text.Spanned, int))on API 24 or newer, otherwise`options`are ignored and[toHtml](https://developer.android.com/reference/android/text/Html.html#toHtml(android.text.Spanned))is used.