# How to return highlight as an html instead of string?

**URL:** https://discuss.elastic.co/t/how-to-return-highlight-as-an-html-instead-of-string/239892
**Category:** Elasticsearch
**Created:** [July 4, 2020, 2:01pm UTC](https://discuss.elastic.co/t/how-to-return-highlight-as-an-html-instead-of-string/239892 "2020-07-04T14:01:50Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![NikolaP93](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@NikolaP93](https://discuss.elastic.co/u/NikolaP93)
#### Post date: [July 4, 2020, 2:01pm UTC](https://discuss.elastic.co/t/how-to-return-highlight-as-an-html-instead-of-string/239892/1 "2020-07-04T14:01:51Z")

</div>

So I have a problem , I created a custom highlight like so:

```auto
customHighlight={() => ({

                                           highlight: {

                                                pre_tags: ['<mark>'],

                                                post_tags: ['</mark>'],

                                                fields: {

                                                    text: {},

                                                    title: {},

                                                },

                                                number_of_fragments: 0,

                                            },

                                        })}

```

However, my search results return this

`<mark>Blast</mark> from the past`

Why is this not returned as HTML, but rather as a string?

```auto

```

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [July 7, 2020, 8:32am UTC](https://discuss.elastic.co/t/how-to-return-highlight-as-an-html-instead-of-string/239892/2 "2020-07-07T08:32:14Z")

</div>

Hi Nikola,

> [@NikolaP93](#):
>
> Why is this not returned as HTML, but rather as a string?

If you mean why doesn't it have `<!DOCTYPE html><html lang="en">` at the top it's because the assumption is an HTML snippet for embedding in a page is considered more useful than a page.  
We typically return multiple results so snippets make more sense. We make no guarantees about what original text we highlight either e.g. if it's full of naughty `<script>....` tags.  
This cleansing/formatting is your app's responsibility.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [August 4, 2020, 8:32am UTC](https://discuss.elastic.co/t/how-to-return-highlight-as-an-html-instead-of-string/239892/3 "2020-08-04T08:32:16Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
