     [Answers](https://scrapfly.io/blog)   /  [xpath](https://scrapfly.io/blog/tag/xpath)   /  [How to select sibling elements in XPath?](https://scrapfly.io/blog/answers/how-to-select-sibling-elements-using-xpath)   # How to select sibling elements in XPath?

 by [Bernardas Alisauskas](https://scrapfly.io/blog/author/bernardas) Apr 19, 2023 1 min read [\#xpath](https://scrapfly.io/blog/tag/xpath) 

 [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-select-sibling-elements-using-xpath "Share on LinkedIn")    

 

 

To select sibling elements in XPath the `preceding-sibling` and `following-sibling` axes can be used - see these interactive examples:

1. `preceding-sibling::span` will select any siblings that precede (i.e. are above) the current element:

&lt;!-- we can find tax rate by navigating from price--&gt; &lt;div&gt; &lt;article&gt; &lt;h1&gt;title&lt;/h1&gt; &lt;p&gt;paragraph&lt;/p&gt; &lt;span&gt;(no tax)&lt;/span&gt; &lt;h3&gt;2.99&lt;/h3&gt; &lt;/article&gt; &lt;/div&gt; 2. `following-sibling::span` will select siblings that follow (i.e. are below) the current element:

&lt;!-- we can find currency by navigating from price--&gt; &lt;div&gt; &lt;article&gt; &lt;h1&gt;title&lt;/h1&gt; &lt;p&gt;paragraph&lt;/p&gt; &lt;p&gt;paragraph with &lt;a href="/foo.html"&gt;link&lt;/a&gt;&lt;/p&gt; &lt;span&gt;(no tax)&lt;/span&gt; &lt;h3&gt;2.99&lt;/h3&gt; &lt;span&gt;USD&lt;/span&gt; &lt;/article&gt; &lt;/div&gt; Note that the wildcard character can be used instead of explicit element names (e.g. `following-sibling::*`) to select siblings of any element name.

For more on XPath, see [our full introduction article](https://scrapfly.io/blog/posts/parsing-html-with-xpath#basic-navigation)



 

   Table of Contents















 

   Join the Newsletter  Get monthly web scraping insights 

 

  



Scale Your Web Scraping

Anti-bot bypass, browser rendering, and rotating proxies, all in one API. Start with 1,000 free credits.

  No credit card required  1,000 free API credits  Anti-bot bypass included 

 [Start Free](https://scrapfly.io/register) [View Docs](https://scrapfly.io/docs/onboarding) 

 Not ready? Get our newsletter instead. 

 

## Explore this Article with AI

 [ ChatGPT ](https://chat.openai.com/?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-select-sibling-elements-using-xpath) [ Gemini ](https://www.google.com/search?udm=50&aep=11&q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-select-sibling-elements-using-xpath) [ Grok ](https://x.com/i/grok?text=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-select-sibling-elements-using-xpath) [ Perplexity ](https://www.perplexity.ai/search/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-select-sibling-elements-using-xpath) [ Claude ](https://claude.ai/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-select-sibling-elements-using-xpath) 



 ## Related Articles

 [  

 python data-parsing 

### Parsing HTML with Xpath

Introduction to xpath in the context of web-scraping. How to extract data from HTML documents using xpath, best practice...

 

 ](https://scrapfly.io/blog/posts/parsing-html-with-xpath) [  

 data-parsing xpath 

### Ultimate XPath Cheatsheet for HTML Parsing in Web Scraping

Ultimate companion for HTML parsing using XPath selectors. This cheatsheet contains all syntax explanations with interac...

 

 ](https://scrapfly.io/blog/posts/xpath-cheatsheet) [  

 css-selectors 

### How to select elements by class using CSS selectors?

To select elements by class the .class selector can be used. To select by exact class value the \[class="exact value"\] ca...

 

 ](https://scrapfly.io/blog/posts/how-to-select-elements-by-class-css-selectors) 

  ## Related Questions

- [ Q How to select all elements between two elements in XPath? ](https://scrapfly.io/blog/answers/how-to-select-all-elements-between-two-known-elements-in-xpath)
- [ Q Is it possible to select preceding siblings using CSS selectors? ](https://scrapfly.io/blog/answers/how-to-select-preceding-sibling-element-css-selectors)
- [ Q How to select following siblings using CSS selectors? ](https://scrapfly.io/blog/answers/how-to-select-following-sibling-element-css-selectors)
- [ Q How to count selections in XPath and why? ](https://scrapfly.io/blog/answers/how-to-count-selectors-in-xpath-and-why)
 
  



   



 Scale your web scraping effortlessly, **1,000 free credits** [Start Free](https://scrapfly.io/register)