---
title: "Attribute Selectors"
description: "Documentation for the vlt client and the vlt registry."
url: "https://docs.vlt.io/client/selectors/attribute-selectors"
image: "https://docs.vlt.io/og/client/selectors/attribute-selectors"
lang: "en"
---

# Attribute Selectors

Attribute selectors match packages based on values found in their `package.json` metadata. They work similarly to [CSS attribute selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors) but operate on package metadata fields instead of HTML attributes.

## Syntax

| Selector         | Description                                                       |
| ---------------- | ----------------------------------------------------------------- |
| `[attr]`         | Has the property `attr`                                           |
| `[attr=value]`   | Property `attr` exactly equals `value`                            |
| `[attr^=value]`  | Property `attr` starts with `value`                               |
| `[attr$=value]`  | Property `attr` ends with `value`                                 |
| `[attr~=value]`  | Property `attr` is a whitespace-separated list containing `value` |
| `[attr\|=value]` | Property `attr` equals `value` or starts with `value-`            |
| `[attr*=value]`  | Property `attr` contains `value`                                  |
| `[attr=value i]` | Case-insensitive comparison                                       |
| `[attr=value s]` | Case-sensitive comparison (default)                               |

## Examples

### Match by name

Select a package with an exact name:

```bash title="Terminal"
$ vlt query '[name=react]'
```

Select all scoped packages:

```bash title="Terminal"
$ vlt query '[name^="@"]'
```

Select packages in the `@vltpkg` scope:

```bash title="Terminal"
$ vlt query '[name^="@vltpkg"]'
```

### Match by version

Select packages on a specific version:

```bash title="Terminal"
$ vlt query '[version=1.0.0]'
```

Select packages with major version 2:

```bash title="Terminal"
$ vlt query '[version^=2]'
```

### Match by any property

Select packages that have a `repository` field:

```bash title="Terminal"
$ vlt query '[repository]'
```

Select packages with a specific license:

```bash title="Terminal"
$ vlt query '[license=MIT]'
```

Select packages whose description mentions "parser":

```bash title="Terminal"
$ vlt query '[description*=parser]'
```

### Case-insensitive matching

Find packages with "React" in the description regardless of case:

```bash title="Terminal"
$ vlt query '[description*=react i]'
```

### What gets selected

Given a project with these dependencies:

```
my-app
├── @vltpkg/cli@1.0.0
├── react@18.2.0
├── react-dom@18.2.0
└── typescript@5.3.0
```

The query `[name^=react]` selects:

```
my-app
├── @vltpkg/cli@1.0.0
├── react@18.2.0          ✅ name starts with "react"
├── react-dom@18.2.0      ✅ name starts with "react"
└── typescript@5.3.0
```

## Combining with other selectors

Attribute selectors can be combined with [combinators](https://docs.vlt.io/client/selectors/combinators.md) and [pseudo-classes](https://docs.vlt.io/client/selectors/pseudo-classes.md):

```bash title="Terminal"
$ vlt query ':root > [license=MIT]'
```

This selects only direct dependencies with an MIT license.

## Nested properties

For nested `package.json` properties (like `engines.node` or `peerDependenciesMeta`), use the [`:attr()` pseudo-class](https://docs.vlt.io/client/selectors/pseudo-classes/attr.md):

```bash title="Terminal"
$ vlt query ':attr(peerDependenciesMeta, foo, [optional=true])'
```

## See also

- [`:attr()` pseudo-class](https://docs.vlt.io/client/selectors/pseudo-classes/attr.md) — match nested `package.json` properties
- [ID Selectors](https://docs.vlt.io/client/selectors/id-selectors.md) — shorthand for `[name=value]`
