# Installation

import { Code } from 'astro:components';
import integrity from '../../../data/integrity.json';

htmx is a single JavaScript file with no dependencies. No build step is required to use it.

## CDN

Add this in your `<head>` tag:

<Code lang="html" code={`<script src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta4" integrity="${integrity.min}" crossorigin="anonymous"></script>`} />

### Unminified

<Code lang="html" code={`<script src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta4/dist/htmx.js" integrity="${integrity.full}" crossorigin="anonymous"></script>`} />

### ES Module

<Code lang="html" code={`<script type="module" src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta4/dist/htmx.esm.min.js" integrity="${integrity.esmMin}" crossorigin="anonymous"></script>`} />

### ES Module (unminified)

<Code lang="html" code={`<script type="module" src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta4/dist/htmx.esm.js" integrity="${integrity.esm}" crossorigin="anonymous"></script>`} />

## Download

Instead of using a CDN, consider [self-hosting in production](https://blog.wesleyac.com/posts/why-not-javascript-cdn).

1. Download <a download href="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta4/dist/htmx.min.js">htmx.min.js</a>
2. Save it to your project (e.g., `/js/htmx.min.js`)
3. Add this in your `<head>` tag:

```html
<script src="/js/htmx.min.js"></script>
```

### Other formats

Download: <a download href="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta4/dist/htmx.js">htmx.js</a> (unminified)

Download: <a download href="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta4/dist/htmx.esm.min.js">htmx.esm.min.js</a> (ES module)

Download: <a download href="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta4/dist/htmx.esm.js">htmx.esm.js</a> (ES module, unminified)

## npm

```sh
npm install htmx.org@4.0.0-beta4
```

```javascript
import 'htmx.org';
```

### Named import

```javascript
import htmx from 'htmx.org';

// Now you can use htmx.ajax(), htmx.find(), etc.
```

## htmax

The `htmax.js` file bundles htmx with the most popular extensions in a single file:

* [SSE](https://four.htmx.org/extensions/hx-sse)
* [WebSockets](https://four.htmx.org/extensions/hx-ws)
* [preload](https://four.htmx.org/extensions/hx-preload)
* [browser-indicator](https://four.htmx.org/extensions/hx-browser-indicator)
* [download](https://four.htmx.org/extensions/hx-download)
* [optimistic](https://four.htmx.org/extensions/hx-optimistic)
* [targets](https://four.htmx.org/extensions/hx-targets)
* [live](https://four.htmx.org/extensions/hx-live).

The extensions are automatically available, you can just use their attributes directly (e.g. `hx-sse:connect`, `hx-ws:connect`).

```html
<script src="/js/htmax.min.js"></script>
```