XPath is a standard expression language designed to navigate, query, and select specific elements or nodes within XML and HTML documents.
Individuals working with structured data, such as web developers or data analysts, read this when they are needing to extract or manipulate information from complex XML or HTML document structures.
External context
For those building their own pages, knowing about XPath means that the content can be precisely targeted by external applications and programming languages. Because it is a widely supported standard defined for querying XML, using clear structure helps ensure that tools can reliably compute and extract specific values from your data.
XPath Wikipedia contributors, “XPath”, en.wikipedia.orgLicence01What it is and how it works
XPath models an XML or HTML document as a tree of nodes: elements, attributes, text, comments, and more. A location path consists of steps separated by / or //. Each step has an axis (default child), a node test (like div or @href), and optional predicates in square brackets that filter the node set (e.g., [@class='price']). The engine evaluates the path from a context node — often the document root — and returns a node set in document order. Axes like ancestor, following-sibling, or descendant let you traverse sideways or upward, not just down. Predicates can use functions such as contains(), starts-with(), or position() to refine matches. Because XPath 1.0 is implemented in every browser and most scraping libraries, it works the same in Chrome DevTools, Python lxml, Screaming Frog, and custom crawlers.
XPath is a way to find and pick out specific pieces of a web page's code, like grabbing every headline or checking if a meta tag exists.
02What to do about it
Start by learning the 20% of syntax you'll use daily: // for any descendant, @attr for attributes, text() for inner text, and predicates for filtering. Open Chrome DevTools, press Ctrl+F in the Elements panel, and type an XPath like //meta[@property='og:title'] to verify it selects the right tag. Build a cheat sheet of your site's recurring patterns — product cards, pagination links, breadcrumb items — and turn them into reusable XPath expressions. Add those expressions to your crawler configuration (Screaming Frog custom extraction, Sitebulb, or a Python script) so every audit automatically pulls the same data points. Schedule a weekly spot-check: run the XPath against a handful of live URLs and confirm the extracted values still match what you see in the browser.
03How it is measured or noticed
You'll see XPath in three places. First, in SEO tool settings: custom extraction fields, JavaScript rendering rules, or structured data validators often accept XPath. Second, in code repositories: search for xpath, lxml, selenium, or // in your team's scrapers and test suites. Third, in browser consoles: typing $x("//h1") returns matching nodes instantly. If a crawler reports missing data, check whether the XPath still matches the live DOM — site redesigns often change class names or wrapper elements, breaking previously stable paths. A sudden drop in extracted fields across many URLs is a strong signal that an XPath needs updating.
04Common mistakes
- Using absolute paths like
/html/body/div[2]/section/div— they break when any wrapper is added or removed. - Relying on auto-generated class names such as
css-1x2y3z— these change on every deploy. - Ignoring namespaces on XML sitemaps or Atom feeds —
//urlreturns nothing if the default namespace isn't registered. - Assuming XPath sees JavaScript-rendered content — it only sees the initial HTML unless you run it inside a headless browser.
- Writing overly broad expressions like
//divthat return thousands of nodes and slow down crawls.
05Limits
XPath operates on the parsed DOM tree, not on visual layout. It cannot select elements based on CSS computed styles, screen position, or user interactions. It also does not understand JSON-LD embedded in `` tags — you must extract the script text first, then parse the JSON separately. XPath 1.0 lacks regular expressions and advanced string manipulation; for those you need XPath 2.0/3.0 (Saxon, BaseX) or post-processing in your host language. It is often confused with CSS selectors, which are shorter for simple cases but less powerful for sibling/ancestor traversal and text-based filtering. Finally, XPath cannot query across iframes or shadow DOM boundaries without switching context.
06Worked example
This expression finds every product card by a stable partial class match, then drills down to the price span that carries a Schema.org itemprop, and finally returns the content attribute value — the machine-readable price. It survives a redesign that adds wrapper divs or changes the exact class suffix, because contains(@class,'product-card') still matches. Test it in DevTools with $x("//div[contains(@class,'product-card')]//span[@itemprop='price']/@content") and you'll get an array of attribute nodes whose value properties are the prices you need.
//div[contains(@class,'product-card')]//span[@itemprop='price']/@content
The entry above is written by GetLoopLoop. What follows is what independent catalogues hold about the same term — none of it is the source of this page.
- Also called
- XML Path Language
- Introduced
- 1999
- Developed by
- World Wide Web Consortium
- Part of
- XSLT, XQuery, XSL
- Kind of thing
- query language, programming language
The same term on Wikipedia
Catalogued in 33 languagesFrequently asked questions
What is XPath and why do SEO tools use it?
XPath is a query language for selecting nodes in an XML or HTML document tree. Crawlers, scrapers, and audit tools use it because it gives a precise, repeatable way to target elements like the canonical link, H1, or product price without depending on visual position on the page.
How is XPath different from CSS selectors?
Both select DOM nodes, but XPath can move in any direction through the tree, filter by text content, and target nodes by position. CSS selectors only travel downward and match by tag, class, or attribute, so tasks like "find the link whose anchor text contains 'Privacy'" usually need XPath.
Do I need to learn XPath for technical SEO?
It depends on how deep you go. If you only run audits, most tools let you point and click. If you build custom extractions in Screaming Frog, custom scrapers, or Looker Studio connectors, basic XPath pays for itself within an afternoon.
Why does my XPath match nothing when the page clearly has the element?
The most common reason is namespace handling, especially with feeds or SVG. Another frequent cause is matching against rendered text when the element is hidden, or using text() when you need string(.) to concatenate child nodes.
Can XPath see elements that are rendered with JavaScript?
Only after they exist in the DOM. XPath evaluates the parsed HTML, so if your tool fetches the raw source before JS executes, dynamically injected nodes will be missing and your expression will return no results.
Wikimedia Commons
Related visuals with source and licence credit

Asked out loud
spoken, not typedThe same term in the words somebody uses speaking to an assistant rather than typing into a box — written from the situation, which is why each one carries the situation it came from.
Use //span[@itemprop='price']/@content to grab the Schema.org price attribute directly, or //*[contains(@class,'price')] if the markup is inconsistent. Paste the expression into the extraction field, run a test, and confirm the preview shows the values you expect before the meeting.
Yes, almost certainly. Pages rendered with JavaScript often have nodes that do not exist in the raw HTML your scraper downloaded. Switch your fetcher to a headless browser, or target the underlying JSON the page hydrates from, and the same XPath will start returning values.
Anchor on the schema, not the styling. Something like //h1 or //*[@itemprop='name'] survives redesigns because the meaning does not change, while a class like .product-title__heading--xl rarely makes it through a redesign. Test against a handful of pages from different templates before you trust it.