ConfigsSep 11, 2026·2 min read

htmlq — Like jq but for HTML, Using CSS Selectors

Extract content from HTML files on the command line using CSS selectors, built in Rust for speed and simplicity.

Agent ready

Review-first install path

This asset needs a review step. The copied prompt tells the agent to dry-run, show the writes, then proceed only after confirmation.

Needs Confirmation · 64/100Policy: confirm
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
htmlq
Review-first command
npx -y tokrepo@latest install baff9069-ade5-11f1-9bc6-00163e2b0d79 --target codex

Dry-run first, confirm the writes, then run this command.

Introduction

htmlq is a command-line tool that lets you extract data from HTML using CSS selectors, the same way jq works for JSON. Written in Rust, it reads HTML from stdin and prints matching elements, attributes, or text to stdout.

What htmlq Does

  • Selects HTML elements using standard CSS selector syntax
  • Extracts specific attributes with the -a flag (e.g., -a href for links)
  • Outputs plain text content with -t, stripping all HTML tags
  • Pipes cleanly with curl, wget, or any command that outputs HTML
  • Pretty-prints matched HTML with proper indentation using -p

Architecture Overview

htmlq is a single-binary CLI tool written in Rust. It uses the html5ever parser (the same HTML parser used by Firefox's Servo engine) for spec-compliant DOM construction, and the kuchikiki library for CSS selector matching. The tool reads the entire HTML document into memory, applies the selector, and streams matching nodes to stdout.

Self-Hosting & Configuration

  • Install with cargo install htmlq from crates.io
  • Available via Homebrew on macOS: brew install htmlq
  • Available on most Linux distributions via package managers
  • No configuration file needed; all options are command-line flags
  • Works with piped input only; does not fetch URLs on its own

Key Features

  • CSS3 selector syntax for precise element targeting
  • Attribute extraction mode for scraping links, images, or metadata
  • Text-only output mode for clean data extraction
  • Pretty-print mode for readable HTML output
  • Small static binary with no runtime dependencies

Comparison with Similar Tools

  • pup — similar HTML selector tool written in Go, supports pseudo-classes
  • xidel — more powerful with XPath and XQuery, but heavier
  • hq — Python-based HTML/JSON query tool with jq-like syntax
  • Beautiful Soup — Python library for HTML parsing, not a CLI tool

FAQ

Q: Can htmlq fetch URLs directly? A: No. Pipe HTML into it from curl, wget, or a file: curl -s URL | htmlq 'selector'.

Q: Does it support XPath? A: No, only CSS selectors. Use xidel if you need XPath support.

Q: Can I chain multiple selectors? A: Yes. Standard CSS combinator syntax works: htmlq 'div.content > p'.

Q: What license does htmlq use? A: MIT license.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets