+++ title = "htmx Web Socket extension" +++ The Web Sockets extension enables easy, bi-directional communication with [Web Sockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications) servers directly from HTML. This replaces the experimental `hx-ws` attribute built into previous versions of htmx. For help migrating from older versions, see the [Migrating](#migrating-from-previous-versions) guide at the bottom of this page. Use the following attributes to configure how WebSockets behave: * `ws-connect=""` or `ws-connect=":"` - A URL to establish a `WebSocket` connection against. * Prefixes `ws` or `wss` can optionally be specified. If not specified, HTMX defaults to adding the location's scheme-type, host and port to have browsers send cookies via websockets. * `ws-send` - Sends a message to the nearest websocket based on the trigger value for the element (either the natural event or the event specified by [`hx-trigger`]) ## Installing The fastest way to install `ws` is to load it via a CDN. Remember to always include the core htmx library before the extension and [enable the extension](#usage). ```HTML ``` An unminified version is also available at https://cdn.jsdelivr.net/npm/htmx-ext-ws/dist/ws.js. While the CDN approach is simple, you may want to consider [not using CDNs in production](https://blog.wesleyac.com/posts/why-not-javascript-cdn). The next easiest way to install `ws` is to simply copy it into your project. Download the extension from `https://cdn.jsdelivr.net/npm/htmx-ext-ws`, add it to the appropriate directory in your project and include it where necessary with a `