flutter_html_search_highlight
π₯ Highlight and navigate search results inside HTML content in Flutter β with built-in UI and zero setup.
Search across HTML pages, highlight matches with <mark>, and give users smooth navigation (next/previous) without writing custom parsing logic.
π¬ Demo
Instantly search, highlight, and navigate across HTML content:
Single Page Search

Multi Page Search

β¨ Features
- π Search plain text inside HTML content
- π― Highlight matches using
<mark>tags - π Supports multi-page HTML content
- βοΈ Navigate between matches (next / previous)
- π Match count per page
- π§ Scroll positioning for matches
- π¨ Fully customizable UI (search bar, styles, icons)
- β‘ Built on
flutter_html+ HTML parser
π Quick Start
import 'package:flutter_html_search_highlight/flutter_html_search_highlight.dart';
HtmlPagedSearchReader(
htmlContent: "<p>Hello Flutter world</p>",
)
Thatβs it. No extra setup needed.
π¦ Installation
dependencies:
flutter_html_search_highlight: ^0.1.0
π‘ Why use this?
Instead of building everything manually on top of flutter_html, this package gives you:
β Built-in search UI β Automatic highlighting β Match navigation (next / previous) β Multi-page support β Scroll-to-match logic
All without writing complex parsing or state management.
π§ Core API (Custom UI)
Use this if you want full control over UI.
final cleaned = pages.map(HtmlSearchHighlighter.cleanHtml).toList();
final result = HtmlSearchHighlighter.searchPages(cleaned, "week's");
// Access results
result.displayPages;
result.matches;
result.matchesPerPage;
Scroll alignment helper
final offset = HtmlSearchHighlighter.scrollOffsetForMatch(
sourcePageHtml: cleaned[page],
keyword: keyword,
matchIndex: 0,
maxScrollExtent: controller.position.maxScrollExtent,
);
π Built-in Paged Reader
Multi-page HTML
HtmlPagedSearchReader(
htmlPages: const [
'<p>First page mentions <b>Flutter</b>.</p>',
'<p>Second page also talks about Flutter.</p>',
],
)
Single HTML content
HtmlPagedSearchReader(
htmlContent: '<h1>One page</h1><p>Search me.</p>',
)
π Content Modes
Force behavior explicitly:
HtmlPagedSearchReader(
htmlPages: manySections,
contentMode: HtmlContentMode.singlePage,
singlePageSeparator: '<hr/>',
)
HtmlPagedSearchReader(
htmlContent: myHtml,
contentMode: HtmlContentMode.multiPage,
)
π¨ Customization
Highlight & styles
HtmlPagedSearchReader(
htmlPages: myPages,
highlightColor: Colors.orangeAccent,
markStyle: Style(backgroundColor: Colors.lime),
htmlStyles: {
'h1': Style(fontSize: FontSize(22)),
},
)
Customize search UI
HtmlPagedSearchReader(
htmlPages: myPages,
searchFieldBuilder: (context, controller, onChanged, keyword) {
return TextField(
controller: controller,
onChanged: onChanged,
decoration: const InputDecoration(hintText: 'Search...'),
);
},
)
Customize navigation UI
HtmlPagedSearchReader(
htmlPages: myPages,
matchNavigationBuilder: (
context,
currentMatch,
totalMatches,
onPrevious,
onNext,
) {
return Row(
children: [
Text('$currentMatch/$totalMatches'),
IconButton(onPressed: onPrevious, icon: Icon(Icons.expand_less)),
IconButton(onPressed: onNext, icon: Icon(Icons.expand_more)),
],
);
},
)
π Example
Check the /example folder for a complete working demo.
βοΈ Tips
- Call
cleanHtml()once for better performance - Set
cleanPagesOnLoad: falseif already cleaned - Use pagination for large HTML content
π§Ύ Changelog
0.1.0
β¨ Initial release
- HTML search & highlight
- Paged reader with navigation
- Match tracking and scroll support
π€ Contributing
Contributions, issues, and feature requests are welcome!
π License
This package is licensed under the MIT License. See the LICENSE file for details.
β Support
If this package helps you, consider giving it a β on GitHub and a π on pub.dev.
Libraries
- flutter_html_search_highlight
- Search and highlight plain text inside HTML strings, with an optional paged reader built on flutter_html.