WebSockets

WebSockets create a fast, bi-directional connection between your server and a client's web browser.

As of version 1.7, WebSocket support has been moved into a new extension, and the existing hx-ws tag has been deprecated. All future development will occur in the extension code, and the deprecated tag will be removed in htmx version 2.0

Required Attributes

hx-ext Make sure the WS extension is initialized on every page or page fragment where you use WebSockets.
ws-connect Connects to a WebSocket. All received messages parsed as OOB Swaps.
ws-send Marks a form that, when submitted, will have its contents serialized and sent to the connected WebSocket server

Example Code

<body>
    <div hx-ext="ws" ws-connect="https://my.websocket.server.com"></div>
</body>

WebSocket Resources