A modest JavaScript framework for the HTML you already have


# Stimulus Stimulus

A modest JavaScript framework for the HTML you already have

Stimulus is a JavaScript framework with modest ambitions. It doesn't seek to take over your entire front-end—in fact, it's not concerned with rendering HTML at all. Instead, it's designed to augment your HTML with just enough behavior to make it shine. Stimulus pairs beautifully with Turbo to provide a complete solution for fast, compelling applications with a minimal amount of effort.

How does it work? Sprinkle your HTML with controller, target, and action attributes:

  1. ``` html
  2. <div data-controller="hello">
  3.   <input data-hello-target="name" type="text">
  4. <button data-action="click->hello#greet"Greet</button>
  5. <span data-hello-target="output"></span>
  6. </div>
  7. ```

Then write a compatible controller. Stimulus brings it to life automatically:

  1. ``` js
  2. // hello_controller.js
  3. import { Controller } from "@hotwired/stimulus"

  4. export default class extends Controller {
  5.   static targets = [ "name", "output" ]

  6.   greet() {
  7.     this.outputTarget.textContent =
  8.       `Hello, ${this.nameTarget.value}!`
  9.   }
  10. }
  11. ```

Stimulus continuously watches the page, kicking in as soon as attributes appear or disappear. It works with any update to the DOM, regardless of whether it comes from a full page load, a Turbo page change, or an Ajax request. Stimulus manages the whole lifecycle.

You can write your first controller in five minutes by following along in the Stimulus Handbook.

You can read more about why we created this new framework in The Origin of Stimulus.

Installing Stimulus

You can use Stimulus with any asset packaging systems. And if you prefer no build step at all, just drop a `