What Programming Language Does Scratch Use
Scratch is built using a combination of JavaScript, Blockly, and Squeak (a dialect of Smalltalk), depending on the specific component, historical version, and runtime environment you examine. While users code visually by snapping graphical blocks together, the...
Scratch is built using a combination of JavaScript, Blockly, and Squeak (a dialect of Smalltalk), depending on the specific component, historical version, and runtime environment you examine. While users code visually by snapping graphical blocks together, the underlying infrastructure relies on web technologies for the modern online editor and Smalltalk or JavaScript for the execution engines that bring those blocks to life.
Contents
Understanding the programming languages behind Scratch requires looking beyond the colorful interface to examine how code is interpreted, rendered, and executed. Developed by the Lifelong Kindergarten Group at the MIT Media Lab, Scratch has evolved through several major architectural shifts since its initial public release. Each version leveraged different programming paradigms and software toolkits to achieve its goal of making computer science accessible to children, educators, and novice programmers worldwide.
The Evolution of Scratch Architecture and Core Technologies
To understand what programming language Scratch uses, one must trace its development across three major eras: the early desktop iterations, the transition phases, and the modern web-based ecosystem. Each iteration reflects distinct choices in software engineering, prioritizing offline performance, browser compatibility, or cross-device accessibility.
In its earliest incarnations—specifically Scratch 1.0 through Scratch 1.4—the entire application ran as a desktop program written in Squeak, an open-source implementation of the Smalltalk programming language. Squeak provided a dynamic, object-oriented environment where virtually everything, from the user interface elements to the graphics rendering engine, was written in Smalltalk. This choice allowed developers to create live, mutable coding environments where scripts could be modified while running.
When the development team built Scratch 2.0, released in 2013, they shifted the core execution environment to Adobe Flash while maintaining a desktop wrapper powered by Adobe AIR. This meant the visual editor and the runtime were heavily dependent on ActionScript, the object-oriented programming language native to the Flash platform. However, the backend asset management and server infrastructure relied heavily on Python and PostgreSQL, establishing a multi-language architecture that separated the client-side user experience from server-side database administration.
The most profound architectural overhaul arrived with Scratch 3.0, released in January 2019. With the widespread deprecation and eventual end-of-life of Adobe Flash, the MIT Media Lab rebuilt the platform entirely using modern web standards. Today, Scratch runs natively in web browsers without requiring third-party plugins, relying on a sophisticated stack of web technologies that replaced both Squeak and ActionScript.
JavaScript as the Engine of Modern Scratch
In the current version of Scratch, JavaScript serves as the primary programming language powering the user interface, the block-handling logic, and the execution runtime. When a user interacts with the Scratch website or opens the offline editor app, they are running JavaScript executed by the browser's JavaScript engine (such as Google Chrome's V8 or Mozilla Firefox's SpiderMonkey).
The modern Scratch codebase is divided into several major modular open-source repositories managed on GitHub:
- scratch-gui: Built using React, a popular JavaScript library for building user interfaces. This component manages the layout, the sprite panes, the stage where projects render, and the overall navigation menus.
- scratch-blocks: A heavily customized fork of Google Blockly, which itself is a JavaScript library for building visual block-based programming editors. This repository handles how blocks snap together, how text and input fields render inside blocks, and how syntax validation rules prevent invalid block combinations.
- scratch-vm (Virtual Machine): The core logic engine written in JavaScript. It maintains the state of the project, handles sprite positioning, manages variable scopes, and executes the compiled block logic frame by frame.
- scratch-render: A WebGL-based rendering engine written in JavaScript that draws sprites, backdrops, and graphical effects onto the HTML5 canvas with hardware acceleration.
Through this JavaScript-centric stack, actions taken in the visual drag-and-drop workspace translate directly into JavaScript function calls executed by the virtual machine, ensuring smooth performance across modern desktop browsers, Chromebooks, and tablet devices.
The Role of Blockly and Visual Syntax Frameworks
While JavaScript provides the runtime environment, Blockly provides the visual grammar. Scratch does not invent block-based programming entirely from scratch; instead, it adapts foundational concepts from visual programming research and implements them through customized web libraries.
Google Blockly is written in JavaScript and provides the structural framework for rendering visual blocks. However, the engineers at MIT significantly modified Blockly for Scratch 3.0 to match the distinctive shape, color-coding, and snapping mechanics that users associate with the platform. These modifications include custom collision detection so blocks highlight when another compatible block approaches, specialized input fields for numbers and strings, and extensible categories for math, motion, looks, and sound.
| Scratch Version | Primary Underlying Language | Frontend Framework | Execution Environment |
|---|---|---|---|
| Scratch 1.x | Smalltalk (Squeak) | Squeak GUI | Desktop Virtual Machine |
| Scratch 2.0 | ActionScript / Python | Adobe Flash / AIR | Flash Player / Browser Plugin |
| Scratch 3.0 | JavaScript | React / WebGL | Modern Web Browser / HTML5 |
This shift to JavaScript and Blockly eliminated the security vulnerabilities and platform restrictions associated with Adobe Flash, ensuring that students can code seamlessly across Windows, macOS, ChromeOS, and iPadOS devices without installing external runtime plugins.
How Visual Blocks Translate to Underlying Code
A common point of curiosity for intermediate programmers is how visual blocks translate into textual code that computers can execute. Scratch does not generate intermediate Python or C++ source code behind the scenes. Instead, it uses an interpretive virtual machine architecture implemented in JavaScript.
When a user snaps a "move 10 steps" block beneath a "when green flag clicked" hat block, the scratch-blocks library records this relationship as a JSON-based workspace schema. The scratch-vm reads this JSON structure and maps each block ID to a predefined JavaScript function handler.
For example, executing a motion block triggers a JavaScript method that calculates the new Cartesian coordinates ($x, y$) of the sprite based on its current heading and speed, updates the internal state variables, and passes rendering instructions to the WebGL graphics engine. This interpretive execution model allows beginners to inspect variables, stop scripts mid-execution, and alter parameters on the fly without waiting for a traditional compiler pass.
Backend Infrastructure and Community Databases
Beyond the client-side editor running in the browser, the global Scratch community platform relies on a robust server-side technology stack to store user projects, handle user authentication, and moderate shared content.
The official Scratch website infrastructure is built primarily using Python, utilizing frameworks like Django to manage web routing, user profiles, cloud variable synchronization, and API endpoints. Database operations—such as storing project metadata, user comments, and love-it/favorite metrics—are handled by PostgreSQL, ensuring data integrity and fast query responses for millions of active monthly users. Additionally, cloud variables use WebSocket connections to facilitate real-time multiplayer data exchange between running projects, backed by high-performance server daemons.
Frequently Asked Questions
Can you view the JavaScript code behind a Scratch project?
While the Scratch editor hides textual code behind visual blocks, advanced users can inspect the underlying project file structure by changing the file extension from .sb3 to .zip and extracting its contents. Inside, you will find a project.json file containing the complete syntax tree of the blocks, along with all imported image assets and audio files. However, converting this JSON directly into readable JavaScript requires third-party transpilers rather than native Scratch tools.
Is Scratch considered a real programming language?
Yes, Scratch is a fully functional event-driven programming language. Although it utilizes a graphical user interface instead of text syntax, it supports core computational concepts such as variables, conditionals, loops, arrays (lists), event handlers, and object-oriented principles (cloning sprites). Computer science departments worldwide and organizations like the AP Computer Science curriculum recognize block-based programming as a legitimate entry point for algorithmic thinking.
Why did Scratch abandon Adobe Flash?
Scratch 2.0 relied heavily on Adobe Flash and AIR. As mobile devices grew in popularity—particularly Apple's iOS ecosystem, which never supported Flash—and major web browser vendors announced the deprecation of Flash due to security vulnerabilities and performance bottlenecks, MIT migrated to HTML5, JavaScript, and WebGL to future-proof the platform.
How does Scratch handle text-based programming extensions?
Scratch supports hardware extensions such as micro:bit, LEGO Education SPIKE Prime, and Arduino boards. The communication between the web browser and physical hardware is mediated by a background desktop utility called Scratch Link. Scratch Link runs as a native application on Windows and macOS, translating Web Bluetooth or USB protocol messages from the JavaScript browser environment into low-level hardware commands understood by the physical devices.
Can I export Scratch projects to Python or C++?
Scratch does not include a native one-click export button for text-based programming languages. However, the active open-source developer community has created third-party tools and libraries—such as sb3topy—that parse the .sb3 project file structure and translate blocks into equivalent Python scripts, though complex projects often require manual code adjustments.
Next Actions for Further Exploration
If you want to dive deeper into the technical architecture of Scratch, explore the official open-source repositories hosted by the MIT Media Lab on GitHub under the LLK (Lifelong Kindergarten) organization. Reviewing the scratch-vm documentation provides direct insight into how event loops and sprite rendering operate under the hood, offering a bridge between visual block-based logic and professional web development.