Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/text/Html#nestedclasses) \| [Constants](https://developer.android.com/reference/android/text/Html#constants) \| [Methods](https://developer.android.com/reference/android/text/Html#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/text/Html#inhmethods)

# Html

*** ** * ** ***

` public class Html `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.text.Html |

<br />

*** ** * ** ***

This class processes HTML strings into displayable styled text. Not all HTML tags are supported.

## Summary

| ### Nested classes ||
|---|---|
| ` interface` | `https://developer.android.com/reference/android/text/Html.ImageGetter` Retrieves images for HTML \<img\> tags. |
| ` interface` | `https://developer.android.com/reference/android/text/Html.TagHandler` Is notified when HTML tags are encountered that the parser does not know how to interpret. |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/text/Html#FROM_HTML_MODE_COMPACT` Flags for `https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String,%20int,%20android.text.Html.ImageGetter,%20android.text.Html.TagHandler)`: Separate block-level elements with line breaks (single newline character) in between. |
| `int` | `https://developer.android.com/reference/android/text/Html#FROM_HTML_MODE_LEGACY` Flags for `https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String,%20int,%20android.text.Html.ImageGetter,%20android.text.Html.TagHandler)`: Separate block-level elements with blank lines (two newline characters) in between. |
| `int` | `https://developer.android.com/reference/android/text/Html#FROM_HTML_OPTION_USE_CSS_COLORS` Flag indicating that CSS color values should be used instead of those defined in `https://developer.android.com/reference/android/graphics/Color`. |
| `int` | `https://developer.android.com/reference/android/text/Html#FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE` Flag indicating that texts inside \<blockquote\> elements will be separated from other texts with one newline character by default. |
| `int` | `https://developer.android.com/reference/android/text/Html#FROM_HTML_SEPARATOR_LINE_BREAK_DIV` Flag indicating that texts inside \<div\> elements will be separated from other texts with one newline character by default. |
| `int` | `https://developer.android.com/reference/android/text/Html#FROM_HTML_SEPARATOR_LINE_BREAK_HEADING` Flag indicating that texts inside \<h1\>\~\<h6\> elements will be separated from other texts with one newline character by default. |
| `int` | `https://developer.android.com/reference/android/text/Html#FROM_HTML_SEPARATOR_LINE_BREAK_LIST` Flag indicating that texts inside \<ul\> elements will be separated from other texts with one newline character by default. |
| `int` | `https://developer.android.com/reference/android/text/Html#FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM` Flag indicating that texts inside \<li\> elements will be separated from other texts with one newline character by default. |
| `int` | `https://developer.android.com/reference/android/text/Html#FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH` Flag indicating that texts inside \<p\> elements will be separated from other texts with one newline character by default. |
| `int` | `https://developer.android.com/reference/android/text/Html#TO_HTML_PARAGRAPH_LINES_CONSECUTIVE` Option for `https://developer.android.com/reference/android/text/Html#toHtml(android.text.Spanned,%20int)`: Wrap consecutive lines of text delimited by '\\n' inside \<p\> elements. |
| `int` | `https://developer.android.com/reference/android/text/Html#TO_HTML_PARAGRAPH_LINES_INDIVIDUAL` Option for `https://developer.android.com/reference/android/text/Html#toHtml(android.text.Spanned,%20int)`: Wrap each line of text delimited by '\\n' inside a \<p\> or a \<li\> element. |

| ### Public methods ||
|---|---|
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/text/Html#escapeHtml(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence text) ` Returns an HTML escaped representation of the given plain text. |
| ` static https://developer.android.com/reference/android/text/Spanned` | ` https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String,%20int)(https://developer.android.com/reference/java/lang/String source, int flags) ` Returns displayable styled text from the provided HTML string. |
| ` static https://developer.android.com/reference/android/text/Spanned` | ` https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String,%20android.text.Html.ImageGetter,%20android.text.Html.TagHandler)(https://developer.android.com/reference/java/lang/String source, https://developer.android.com/reference/android/text/Html.ImageGetter imageGetter, https://developer.android.com/reference/android/text/Html.TagHandler tagHandler) ` *This method was deprecated in API level 24. use `https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String,%20int,%20android.text.Html.ImageGetter,%20android.text.Html.TagHandler)` instead.* |
| ` static https://developer.android.com/reference/android/text/Spanned` | ` https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String,%20int,%20android.text.Html.ImageGetter,%20android.text.Html.TagHandler)(https://developer.android.com/reference/java/lang/String source, int flags, https://developer.android.com/reference/android/text/Html.ImageGetter imageGetter, https://developer.android.com/reference/android/text/Html.TagHandler tagHandler) ` Returns displayable styled text from the provided HTML string. |
| ` static https://developer.android.com/reference/android/text/Spanned` | ` https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String)(https://developer.android.com/reference/java/lang/String source) ` *This method was deprecated in API level 24. use `https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String,%20int)` instead.* |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/text/Html#toHtml(android.text.Spanned,%20int)(https://developer.android.com/reference/android/text/Spanned text, int option) ` Returns an HTML representation of the provided Spanned text. |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/text/Html#toHtml(android.text.Spanned)(https://developer.android.com/reference/android/text/Spanned text) ` *This method was deprecated in API level 24. use `https://developer.android.com/reference/android/text/Html#toHtml(android.text.Spanned,%20int)` instead.* |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Constants

### FROM_HTML_MODE_COMPACT

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FROM_HTML_MODE_COMPACT
```

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

<br />

Constant Value: 63 (0x0000003f)

### FROM_HTML_MODE_LEGACY

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FROM_HTML_MODE_LEGACY
```

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

<br />

Constant Value: 0 (0x00000000)

### FROM_HTML_OPTION_USE_CSS_COLORS

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FROM_HTML_OPTION_USE_CSS_COLORS
```

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

<br />

Constant Value: 256 (0x00000100)

### FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE
```

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

<br />

Constant Value: 32 (0x00000020)

### FROM_HTML_SEPARATOR_LINE_BREAK_DIV

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_DIV
```

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

<br />

Constant Value: 16 (0x00000010)

### FROM_HTML_SEPARATOR_LINE_BREAK_HEADING

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_HEADING
```

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

<br />

Constant Value: 2 (0x00000002)

### FROM_HTML_SEPARATOR_LINE_BREAK_LIST

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_LIST
```

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

<br />

Constant Value: 8 (0x00000008)

### FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM
```

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

<br />

Constant Value: 4 (0x00000004)

### FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH
```

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

<br />

Constant Value: 1 (0x00000001)

### TO_HTML_PARAGRAPH_LINES_CONSECUTIVE

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int TO_HTML_PARAGRAPH_LINES_CONSECUTIVE
```

Option for `https://developer.android.com/reference/android/text/Html#toHtml(android.text.Spanned,%20int)`: Wrap consecutive lines of text delimited by '\\n' inside \<p\> elements. `https://developer.android.com/reference/android/text/style/BulletSpan`s are ignored.

<br />

Constant Value: 0 (0x00000000)

### TO_HTML_PARAGRAPH_LINES_INDIVIDUAL

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int TO_HTML_PARAGRAPH_LINES_INDIVIDUAL
```

Option for `https://developer.android.com/reference/android/text/Html#toHtml(android.text.Spanned,%20int)`: Wrap each line of text delimited by '\\n' inside a \<p\> or a \<li\> element. This allows `https://developer.android.com/reference/android/text/style/ParagraphStyle`s attached to be encoded as CSS styles within the corresponding \<p\> or \<li\> element.

<br />

Constant Value: 1 (0x00000001)

## Public methods

### escapeHtml

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static String escapeHtml (CharSequence text)
```

Returns an HTML escaped representation of the given plain text.

<br />

| Parameters ||
|---|---|
| `text` | `CharSequence` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

### fromHtml

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Spanned fromHtml (String source, 
                int flags)
```

Returns displayable styled text from the provided HTML string. Any \<img\> tags in the HTML will display as a generic replacement image which your program can then go through and replace with real images.

This uses TagSoup to handle real HTML, including all of the brokenness found in the wild.

<br />

| Parameters ||
|---|---|
| `source` | `String` <br /> |
| `flags` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/text/Spanned` | <br /> |

### fromHtml

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Spanned fromHtml (String source, 
                Html.ImageGetter imageGetter, 
                Html.TagHandler tagHandler)
```

<br />

**This method was deprecated in API level 24.**   

use `https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String,%20int,%20android.text.Html.ImageGetter,%20android.text.Html.TagHandler)` instead.

Returns displayable styled text from the provided HTML string with the legacy flags `https://developer.android.com/reference/android/text/Html#FROM_HTML_MODE_LEGACY`.

<br />

| Parameters ||
|---|---|
| `source` | `String` <br /> |
| `imageGetter` | `Html.ImageGetter` <br /> |
| `tagHandler` | `Html.TagHandler` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/text/Spanned` | <br /> |

### fromHtml

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Spanned fromHtml (String source, 
                int flags, 
                Html.ImageGetter imageGetter, 
                Html.TagHandler tagHandler)
```

Returns displayable styled text from the provided HTML string. Any \<img\> tags in the HTML will use the specified ImageGetter to request a representation of the image (use null if you don't want this) and the specified TagHandler to handle unknown tags (specify null if you don't want this).

This uses TagSoup to handle real HTML, including all of the brokenness found in the wild.

<br />

| Parameters ||
|---|---|
| `source` | `String` <br /> |
| `flags` | `int` <br /> |
| `imageGetter` | `Html.ImageGetter` <br /> |
| `tagHandler` | `Html.TagHandler` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/text/Spanned` | <br /> |

### fromHtml

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Spanned fromHtml (String source)
```

<br />

**This method was deprecated in API level 24.**   

use `https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String,%20int)` instead.

Returns displayable styled text from the provided HTML string with the legacy flags `https://developer.android.com/reference/android/text/Html#FROM_HTML_MODE_LEGACY`.

<br />

| Parameters ||
|---|---|
| `source` | `String` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/text/Spanned` | <br /> |

### toHtml

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static String toHtml (Spanned text, 
                int option)
```

Returns an HTML representation of the provided Spanned text. A best effort is made to add HTML tags corresponding to spans. Also note that HTML metacharacters (such as "\<" and "\&") within the input text are escaped.

<br />

| Parameters ||
|---|---|
| `text` | `Spanned`: input text to convert <br /> |
| `option` | `int`: one of `https://developer.android.com/reference/android/text/Html#TO_HTML_PARAGRAPH_LINES_CONSECUTIVE` or `https://developer.android.com/reference/android/text/Html#TO_HTML_PARAGRAPH_LINES_INDIVIDUAL` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | string containing input converted to HTML <br /> |

### toHtml

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static String toHtml (Spanned text)
```

<br />

**This method was deprecated in API level 24.**   

use `https://developer.android.com/reference/android/text/Html#toHtml(android.text.Spanned,%20int)` instead.

<br />

<br />

| Parameters ||
|---|---|
| `text` | `Spanned` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |