> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# highlightPreTag

> Opening HTML tag for highlighted attributes

export const Setting = ({type, default: defaultValue, defaultNote, scope, min, max, formerly}) => {
  const renderedDefault = defaultValue === '' ? '""' : defaultValue;
  const renderedNote = defaultNote ? `(${defaultNote})` : '';
  return <ul>
      <li><strong>Type:</strong> <code>{type}</code></li>
      <li><strong>Default:</strong> <code>{renderedDefault}</code>{renderedNote}</li>
      {min && <li><strong>Min:</strong> <code>{min}</code></li>}
      {max && <li><strong>Max:</strong> <code>{max}</code></li>}
      <li><strong>Scope:</strong> <a href="/doc/api-reference/api-parameters"><code>{scope}</code></a></li>
      {formerly && <li>
          <strong>Deprecated name:</strong> <code>{formerly}</code>
        </li>}
    </ul>;
};

<Setting type="string" default="<em>" scope="settings,search" />

The `highlightPreTag` parameter defines the HTML tag inserted **before** the matching text in highlighted attributes.
It works in combination with [`highlightPostTag`](/doc/api-reference/api-parameters/highlightPostTag),
which marks the end of the highlighted portion.

## Usage

* Set an empty string (`""`) to fallback to the default tag.
* To turn off highlighting, remove the searchable attribute with the [`attributesToHighlight`](/doc/api-reference/api-parameters/attributesToHighlight) parameter.

## Examples

### Set default tag

<AccordionGroup>
  <Accordion title="Current API clients" defaultOpen="true">
    <CodeGroup>
      ```cs C# theme={"system"}
      var response = await client.SetSettingsAsync(
        "INDEX_NAME",
        new IndexSettings { HighlightPreTag = "<em>" }
      );
      ```

      ```dart Dart theme={"system"}
      final response = await client.setSettings(
        indexName: "INDEX_NAME",
        indexSettings: IndexSettings(
          highlightPreTag: "<em>",
        ),
      );
      ```

      ```go Go theme={"system"}
      response, err := client.SetSettings(client.NewApiSetSettingsRequest(
        "INDEX_NAME",
        search.NewEmptyIndexSettings().SetHighlightPreTag("<em>")))
      if err != nil {
        // handle the eventual error
        panic(err)
      }
      ```

      ```java Java theme={"system"}
      UpdatedAtResponse response = client.setSettings("INDEX_NAME", new IndexSettings().setHighlightPreTag("<em>"));
      ```

      ```js JavaScript theme={"system"}
      const response = await client.setSettings({ indexName: 'theIndexName', indexSettings: { highlightPreTag: '<em>' } });
      ```

      ```kotlin Kotlin theme={"system"}
      var response =
        client.setSettings(
          indexName = "INDEX_NAME",
          indexSettings = IndexSettings(highlightPreTag = "<em>"),
        )
      ```

      ```php PHP theme={"system"}
      $response = $client->setSettings(
          'INDEX_NAME',
          ['highlightPreTag' => '<em>',
          ],
      );
      ```

      ```python Python theme={"system"}
      response = client.set_settings(
          index_name="INDEX_NAME",
          index_settings={
              "highlightPreTag": "<em>",
          },
      )
      ```

      ```ruby Ruby theme={"system"}
      response = client.set_settings("INDEX_NAME", Algolia::Search::IndexSettings.new(highlight_pre_tag: "<em>"))
      ```

      ```scala Scala theme={"system"}
      val response = Await.result(
        client.setSettings(
          indexName = "INDEX_NAME",
          indexSettings = IndexSettings(
            highlightPreTag = Some("<em>")
          )
        ),
        Duration(100, "sec")
      )
      ```

      ```swift Swift theme={"system"}
      let response = try await client.setSettings(
          indexName: "INDEX_NAME",
          indexSettings: IndexSettings(highlightPreTag: "<em>")
      )
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Legacy API clients">
    <CodeGroup>
      ```cs C# theme={"system"}
      IndexSettings settings = new IndexSettings()
      settings.HighlightPreTag = "";

      index.SetSettings(settings);
      ```

      ```go Go theme={"system"}
      res, err := index.SetSettings(search.Settings{
      	HighlightPreTag: opt.HighlightPreTag(""),
      })
      ```

      ```java Java theme={"system"}
      index.setSettings(
        new IndexSettings()
          .setHighlightPreTag("")
      );
      ```

      ```js JavaScript theme={"system"}
      index
        .setSettings({
          highlightPreTag: "",
        })
        .then(() => {
          // done
        });
      ```

      ```kotlin Kotlin theme={"system"}
      val settings = settings {
          highlightPreTag = ""
      }

      index.setSettings(settings)
      ```

      ```php PHP theme={"system"}
      $index->setSettings([
        'highlightPreTag' => ''
      ]);
      ```

      ```python Python theme={"system"}
      index.set_settings({"highlightPreTag": ""})
      ```

      ```ruby Ruby theme={"system"}
      index.set_settings(
        {
          highlightPreTag: ""
        }
      )
      ```

      ```scala Scala theme={"system"}
      client.execute {
        setSettings of "myIndex" `with` IndexSettings(
          highlightPreTag = Some("")
        )
      }
      ```

      ```swift Swift theme={"system"}
      let settings = Settings()
        .set(\.highlightPreTag, to: "")

      index.setSettings(settings) { result in
        if case .success(let response) = result {
          print("Response: \(response)")
        }
      }
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>

### Change tag for the current search

<AccordionGroup>
  <Accordion title="Current API clients" defaultOpen>
    <CodeGroup>
      ```cs C# theme={"system"}
      var response = await client.SearchSingleIndexAsync<Hit>(
        "INDEX_NAME",
        new SearchParams(new SearchParamsObject { Query = "query", HighlightPreTag = "<strong>" })
      );
      ```

      ```dart Dart theme={"system"}
      final response = await client.searchSingleIndex(
        indexName: "INDEX_NAME",
        searchParams: SearchParamsObject(
          query: "query",
          highlightPreTag: "<strong>",
        ),
      );
      ```

      ```go Go theme={"system"}
      response, err := client.SearchSingleIndex(client.NewApiSearchSingleIndexRequest(
        "INDEX_NAME").WithSearchParams(search.SearchParamsObjectAsSearchParams(
        search.NewEmptySearchParamsObject().SetQuery("query").SetHighlightPreTag("<strong>"))))
      if err != nil {
        // handle the eventual error
        panic(err)
      }
      ```

      ```java Java theme={"system"}
      SearchResponse response = client.searchSingleIndex(
        "INDEX_NAME",
        new SearchParamsObject().setQuery("query").setHighlightPreTag("<strong>"),
        Hit.class
      );
      ```

      ```js JavaScript theme={"system"}
      const response = await client.searchSingleIndex({
        indexName: 'indexName',
        searchParams: { query: 'query', highlightPreTag: '<strong>' },
      });
      ```

      ```kotlin Kotlin theme={"system"}
      var response =
        client.searchSingleIndex(
          indexName = "INDEX_NAME",
          searchParams = SearchParamsObject(query = "query", highlightPreTag = "<strong>"),
        )
      ```

      ```php PHP theme={"system"}
      $response = $client->searchSingleIndex(
          'INDEX_NAME',
          ['query' => 'query',
              'highlightPreTag' => '<strong>',
          ],
      );
      ```

      ```python Python theme={"system"}
      response = client.search_single_index(
          index_name="INDEX_NAME",
          search_params={
              "query": "query",
              "highlightPreTag": "<strong>",
          },
      )
      ```

      ```ruby Ruby theme={"system"}
      response = client.search_single_index(
        "INDEX_NAME",
        Algolia::Search::SearchParamsObject.new(query: "query", highlight_pre_tag: "<strong>")
      )
      ```

      ```scala Scala theme={"system"}
      val response = Await.result(
        client.searchSingleIndex(
          indexName = "INDEX_NAME",
          searchParams = Some(
            SearchParamsObject(
              query = Some("query"),
              highlightPreTag = Some("<strong>")
            )
          )
        ),
        Duration(100, "sec")
      )
      ```

      ```swift Swift theme={"system"}
      let response: SearchResponse<Hit> = try await client.searchSingleIndex(
          indexName: "INDEX_NAME",
          searchParams: SearchSearchParams.searchSearchParamsObject(SearchSearchParamsObject(
              query: "query",
              highlightPreTag: "<strong>"
          ))
      )
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Legacy API clients">
    <CodeGroup>
      ```cs C# theme={"system"}
      index.Search(new Query("query")
      {
          HighlightPreTag = ""
      });
      ```

      ```go Go theme={"system"}
      res, err := index.Search(
      	"query",
      	opt.HighlightPreTag(""),
      )
      ```

      ```java Java theme={"system"}
      index.search(
        new Query("query")
          .setHighlightPreTag("")
      );
      ```

      ```js JavaScript theme={"system"}
      index
        .search("query", {
          highlightPreTag: "",
        })
        .then(({ hits }) => {
          console.log(hits);
        });
      ```

      ```kotlin Kotlin theme={"system"}
      val query = query("query") {
          highlightPreTag = ""
      }

      index.search(query)
      ```

      ```php PHP theme={"system"}
      $results = $index->search('query', [
        'highlightPreTag' => ''
      ]);
      ```

      ```python Python theme={"system"}
      results = index.search("query", {"highlightPreTag": ""})
      ```

      ```ruby Ruby theme={"system"}
      results = index.search(
        "query",
        {
          highlightPreTag: ""
        }
      )
      ```

      ```scala Scala theme={"system"}
      client.execute {
        search into "myIndex" query Query(
          query = Some("query"),
          highlightPreTag = Some("")
        )
      }
      ```

      ```swift Swift theme={"system"}
      let query = Query("query")
        .set(\.highlightPreTag, to: "")

      index.search(query: query) { result in
        if case .success(let response) = result {
          print("Response: \(response)")
        }
      }
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>
