Description #
Stimulus is a modest JavaScript framework that enhances static HTML with behavior using minimal JavaScript, designed to work effortlessly with server-rendered apps.
History #
Stimulus was released in 2018 by Basecamp (now 37signals), the same team behind Ruby on Rails. It was built to pair with Rails’ Hotwire approach to bring JavaScript interactivity without adopting heavy SPAs.
Hello World Code #
<div data-controller="hello">
<h1 data-hello-target="output">Hello, World!</h1>
</div>
<script>
application.register("hello", class extends Stimulus.Controller {
connect() {
this.outputTarget.textContent = "Hello, World!";
}
});
</script>
How to Run #
Option 1: Online
https://jsfiddle.net
Option 2: Local
npm install stimulus
Key Concepts #
- Progressive enhancement
- Controller-based structure
- Data attributes for binding
- Small JavaScript footprint
- Works with Rails and any backend
- Declarative targets and actions
- Hotwire-compatible
- No build step required
- Easy DOM manipulation
- Encourages server-first rendering
Try It Online #
Fun Facts #
- Stimulus powers Hey.com, Basecamp, and many Rails apps with interactive UIs.
- It encourages HTML to remain the source of truth — avoiding “JavaScript fatigue.”
- You can write zero client-side routes yet still create rich user experiences.
- It pairs seamlessly with Turbo and Hotwire to eliminate full-page reloads.
- Stimulus is ideal for developers who love convention over configuration and minimalism.