# is-relative-url

> Check if a URL is relative

Latest version **4.1.1** (published 2026-09-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install is-relative-url
pnpm add is-relative-url
yarn add is-relative-url
bun add is-relative-url
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.1.1 |
| Published | 2026-09-14 |
| First published | 2014-07-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=14.16 |
| Dependencies | 1 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 26 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | url, relative, absolute, uri, is, check |

## Links

- npm: https://www.npmjs.com/package/is-relative-url
- Repository: https://github.com/sindresorhus/is-relative-url
- Homepage: https://github.com/sindresorhus/is-relative-url#readme
- Issues: https://github.com/sindresorhus/is-relative-url/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/is-relative-url

## Dependencies (1)

- [is-absolute-url](https://npm.io/package/is-absolute-url.md) ^4.0.1

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 4.1.1 (latest) — 2026-09-14
- 4.1.0 — 2025-09-10
- 4.0.0 — 2022-06-06
- 3.0.0 — 2019-04-06
- 2.0.0 — 2015-11-14
- 1.0.0 — 2014-08-13
- 0.1.1 — 2014-07-05
- 0.1.0 — 2014-07-04

## README

# is-relative-url

> Check if a URL is relative

## Install

```sh
npm install is-relative-url
```

## Usage

```js
import isRelativeUrl from 'is-relative-url';

isRelativeUrl('foo/bar');
//=> true

isRelativeUrl('https://sindresorhus.com/foo/bar');
//=> false

isRelativeUrl('//sindresorhus.com');
//=> true
```

## API

### isRelativeUrl(url, options?)

#### url

Type: `string`

The URL to check.

#### options

Type: `object`

##### allowProtocolRelative

Type: `boolean`\
Default: `true`

Allow [protocol-relative URLs](https://en.wikipedia.org/wiki/URL#Protocol-relative_URLs) (e.g., `//example.com`) to be considered relative.

Setting this to `false` treats URLs starting with two slash or backslash separators (`//`, `\\`, `/\`, `\/`) as absolute.

This does not prevent open redirects. For redirect validation, parse against a fixed trusted HTTP(S) base, reject parse failures or mismatched origins/protocols, and use the parsed URL without further changes.

> [!NOTE]
> Protocol-relative URLs are [technically relative](https://datatracker.ietf.org/doc/html/rfc3986#section-4.2) according to [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986), as they require the current page's protocol to resolve into absolute URLs. However, they can still navigate to external domains, which may be a security concern in certain contexts (e.g., preventing open redirects).

## Related

See [is-absolute-url](https://github.com/sindresorhus/is-absolute-url) for the inverse.

---
_Source: https://npm.io/package/is-relative-url · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
