explaingit

liabru/matter-js

Analysis updated 2026-06-24

18,183JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

Matter.js is a JavaScript library that simulates 2D physics in a web browser, objects fall, collide, bounce, and connect with ropes, letting you build games and animations that feel physically real.

Mindmap

mindmap
  root((matter-js))
    Physics features
      Rigid bodies
      Collision detection
      Constraints
      Sleeping bodies
    Visual output
      Canvas renderer
      Demo gallery
      Mobile touch
    Use cases
      Browser games
      Animations
      Experiments
    Setup
      npm install
      Script tag
      Plugin system
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Build a browser game where characters fall and collide with obstacles using realistic gravity and friction

USE CASE 2

Create interactive product demos or art experiments where objects bounce and stack on screen

USE CASE 3

Prototype a puzzle game with stacking, wrecking balls, and destructible structures in the browser

USE CASE 4

Add rope or joint constraints between objects to simulate cloth, pendulums, or vehicle suspension

What is it built with?

JavaScriptNode.jsCanvas API

How does it compare?

liabru/matter-jslllyasviel/style2paintsplotly/plotly.js
Stars18,18318,18618,188
LanguageJavaScriptJavaScriptJavaScript
Setup difficultyeasymoderateeasy
Complexity2/52/52/5
Audiencedeveloperdesignerdata

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

In plain English

Matter.js is a JavaScript library for simulating 2D physics in web browsers and in Node.js. Physics simulation means the library calculates how objects move, collide, bounce, and fall under the influence of gravity, allowing developers to create games, interactive animations, and visual experiments where objects behave like they would in the real world. The library supports rigid bodies (solid objects that don't deform), compound bodies (complex shapes built from simpler ones), concave and convex shapes, physical properties such as mass and density, friction, air resistance, and collision detection. It also handles constraints (like ropes or joints connecting objects), sleeping (pausing simulation for objects that have stopped moving to save processing power), raycasting (detecting what a ray of light would hit), and time scaling (slowing down or speeding up the simulation). There is a built-in canvas renderer that draws the simulation as 2D graphics, and the library works across major browsers as well as on mobile devices via touch input. Matter.js can be installed via npm or included directly in a webpage via a script tag. The engine can be extended through a plugin system. The project includes a large set of demo scenes, things like Newton's cradle, a wrecking ball, cloth simulation, and various stacking challenges, both as code examples and as a live demo gallery.

Copy-paste prompts

Prompt 1
Using Matter.js, create a browser canvas where three balls fall under gravity, bounce off the ground, and collide with each other
Prompt 2
How do I create a wrecking ball attached by a rope constraint in Matter.js that swings and knocks over a stack of boxes?
Prompt 3
Set up a Matter.js scene with a platform character that can jump and land on multiple platforms using collision detection
Prompt 4
How do I slow down time in a Matter.js simulation to 50% speed and detect when two specific bodies collide?
Prompt 5
Create a cloth simulation in Matter.js using constraints between small bodies arranged in a grid

Frequently asked questions

What is matter-js?

Matter.js is a JavaScript library that simulates 2D physics in a web browser, objects fall, collide, bounce, and connect with ropes, letting you build games and animations that feel physically real.

What language is matter-js written in?

Mainly JavaScript. The stack also includes JavaScript, Node.js, Canvas API.

How hard is matter-js to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is matter-js for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Scan in gitsafehub Deploy in gitdeployhub liabru on gitmyhub

Verify against the repo before relying on details.