PHPackages                             theseer/css2xpath - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. theseer/css2xpath

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

theseer/css2xpath
=================

PHP Library to translate CSS selectors into XPath

2.0.0(6y ago)720.0k—2.9%21BSD-3-ClausePHPPHP ^7.2|^8.0

Since Oct 29Pushed 2y agoCompare

[ Source](https://github.com/theseer/css2xpath)[ Packagist](https://packagist.org/packages/theseer/css2xpath)[ RSS](/packages/theseer-css2xpath/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)DependenciesVersions (4)Used By (1)

CSS2XPath
=========

[](#css2xpath)

This is yet another library to translate various CSS selectors to their XPath equivalent.

[![Build Status](https://camo.githubusercontent.com/895bb0b50022d0ac89c906f964947af112f6570b90317d3349b8c212b84a42a1/68747470733a2f2f7472617669732d63692e6f72672f746865736565722f6373733278706174682e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/theseer/css2xpath)[![Latest Stable Version](https://camo.githubusercontent.com/7e7897cbc111448bb7acc175be3fed847157e172d24b6c312cd714684d13a2a5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746865736565722f6373733278706174682e737667)](https://packagist.org/packages/theseer/css2xpath)

Example
-------

[](#example)

```
$translator = new TheSeer\CSS2XPath\Translator();

// Will output //*[contains(concat(" ",normalize-space(@class)," ")," note ")]
echo $translator->translate('.note');

// Will output //*[@id="me"]
echo $translator->translate('#me');
```

Installation
------------

[](#installation)

You can add this library as a local, per-project dependency to your project using Composer:

```
composer require theseer/css2xpath

```

Selectors supported
-------------------

[](#selectors-supported)

The following selectors are currently covered:

- \#id
- tag#id
- tag #id
- tag
- tag tag
- tag &gt; tag
- tag + tag
- tag ~ tag
- tag, tag
- .classname
- tag.classname
- tag .classname
- tag.classname, tag.classname
- tag.classname tag.classname
- tag.classname &gt; tag.classname
- tag#id + tag &gt; tag
- tag\[id\]:contains(Selectors)
- tag\[attribute\]\[attribute\]
- tag\[attribute\]
- tag\[attribute=example\]
- tag\[attribute^=exa\]
- tag\[class$=mple\]
- tag\[attribute\*=e\]
- tag\[attribute|=dialog\]
- tag\[attribute!=made\_up\]
- tag\[attribute!="made\_up"\]
- tag\[attribute~=example\]
- tag:not(.classname)
- tag:contains(selectors)
- tag:nth-child(n)
- tag:nth-child(even)
- tag:nth-child(odd)
- tag:nth-child(3n+8)
- tag:nth-child(2n+1)
- tag:nth-child(3)
- tag:nth-child(4n)
- tag:only-child
- tag:last-child
- tag:first-child
- foo|bar
- tag\[attribute^=exa\]\[attribute$=mple\]
- tag:enabled
- tag:checked
- tag:disabled
- :empty
- :root

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~333 days

Total

3

Last Release

2456d ago

Major Versions

1.1.0 → 2.0.02019-08-28

PHP version history (2 changes)1.0.0PHP ^7.0

2.0.0PHP ^7.2|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/0fc8fe1ac311fb26137cc3b26cd6c1bbb58c9ac4f287eb9d8242a741cef9a502?d=identicon)[theseer](/maintainers/theseer)

---

Top Contributors

[![theseer](https://avatars.githubusercontent.com/u/111333?v=4)](https://github.com/theseer "theseer (17 commits)")

### Embed Badge

![Health badge](/badges/theseer-css2xpath/health.svg)

```
[![Health](https://phpackages.com/badges/theseer-css2xpath/health.svg)](https://phpackages.com/packages/theseer-css2xpath)
```

###  Alternatives

[synatree/yii2-dynamic-relations

Allows Yii2 views to contain a dynamically expanding set of fields based on model relations.

112.8k](/packages/synatree-yii2-dynamic-relations)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
