---
title: ":has()"
description: "Documentation for the vlt client and the vlt registry."
url: "https://docs.vlt.io/client/selectors/pseudo-classes/has"
image: "https://docs.vlt.io/og/client/selectors/pseudo-classes/has"
lang: "en"
---

# :has()

The `:has()` pseudo-class matches packages that **depend on** a match for a given selector expression. It's the dependency graph equivalent of the [CSS `:has()` selector](https://developer.mozilla.org/en-US/docs/Web/CSS/:has).

## Syntax

```
:has(<selector-list>)
```

The selector list is evaluated against the whole graph, then packages with a direct dependency on one of its matches are kept. Nest `:has()` to walk further up the graph, one dependency hop per level.

## Examples

### Packages with a peer dependency on react

```bash title="Terminal"
$ vlt query ':has(:peer[name=react])'
```

Given this dependency graph:

```
my-app
├── react@18.2.0
├── react-dom@18.2.0
│   └── react@18.2.0 (peer)
└── @testing-library/react@14.0.0
    └── react@18.2.0 (peer)
```

`:has(:peer[name=react])` selects packages that have a peer dependency on react:

```
my-app
├── react@18.2.0
├── react-dom@18.2.0                 ✅ has peer dep on react
│   └── react@18.2.0 (peer)
└── @testing-library/react@14.0.0   ✅ has peer dep on react
    └── react@18.2.0 (peer)
```

### Packages that depend on vulnerable packages

```bash title="Terminal"
$ vlt query ':has(:cve)'
```

This finds packages whose **direct dependencies** have known CVEs.

### Packages that depend on outdated packages

```bash title="Terminal"
$ vlt query ':has(:outdated(major))'
```

### Packages that depend on changed packages

Find packages that have a dependency that was modified:

```bash title="Terminal"
$ vlt query ':has(:diff(main))'
```

See [Affected Dependencies](https://docs.vlt.io/client/affected.md) for using this to test only what a branch could have broken.

### Reaching further than one hop

`:has()` only looks one dependency deep, so `>` inside it is redundant — these select the same packages:

```bash title="Terminal"
$ vlt query ':has(> [name=lodash])'
$ vlt query ':has([name=lodash])'
```

To match packages that depend on lodash _through_ another package, nest another `:has()`:

```bash title="Terminal"
# depends on something that depends on lodash
$ vlt query ':has(:has([name=lodash]))'
```

## See also

- [`:not()`](https://docs.vlt.io/client/selectors/pseudo-classes/not.md) — negation pseudo-class
- [`:is()`](https://docs.vlt.io/client/selectors/pseudo-classes/is.md) — forgiving selector list matching
- [Combinators](https://docs.vlt.io/client/selectors/combinators.md) — `>`, ``, `~`
- [Affected Dependencies](https://docs.vlt.io/client/affected.md) — what a change breaks
