PHPackages                             codealfa/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. codealfa/css2xpath

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

codealfa/css2xpath
==================

CSS to XPath Converter

1.0(1y ago)04GPL-3.0-or-laterPHPPHP &gt;=8.0

Since Sep 30Pushed 5mo ago1 watchersCompare

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

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

CSS to XPath Converter
======================

[](#css-to-xpath-converter)

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

[](#installation)

Run the following command to use the library in your projects.

```
composer require codealfa/css2xpath

```

Basic Usage
-----------

[](#basic-usage)

```
use CodeAlfa\Css2Xpath\Css2XpathConverter;
use CodeAlfa\Css2Xpath\SelectorFactory;

$converter = new Css2XpathConverter(new SelectorFactory());
$xPath = $converter->convert('p#main, div.container');
var_dump($xPath);
```

Output:

```
p[@id="main"]|div[@class and contains(concat(" ", normalize-space(@class), " "), " container ")]

```

Notes
-----

[](#notes)

- The Selector classes are extendable if you need to add or change functionality. You'll just need to create your own `SelectorFactory` or extend the existing one to inject into the `Css2XpathConverter` class.
- Some CSS pseudo-selectors only make sense in the context of a web browser, so only the following pseudo-selectors are implemented. All others are ignored:
    - :enabled
    - :disabled
    - :read-only
    - :read-write
    - :checked
    - :required
    - :root
    - :empty
    - :first-child
    - :last-child
    - :only-child
    - :first-of-type
    - :last-of-type
    - :only-of-type
    - :not
    - :has

License
-------

[](#license)

GPL-3.0 or later

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance56

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

595d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7a4ff3c397fe055d711ae5f763439c0db8c44fe0ff2c01b1dc28c00b51b8ef0a?d=identicon)[codealfa](/maintainers/codealfa)

---

Top Contributors

[![codealfa](https://avatars.githubusercontent.com/u/10180134?v=4)](https://github.com/codealfa "codealfa (36 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)[russ666/yii2-countdown

jQuery countdown widget for Yii2

11100.0k](/packages/russ666-yii2-countdown)

PHPackages © 2026

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