After reading this document, you may wish to try the Getting Started codelab.
Blockly is 100% client side, requiring no support from the server (unless one wants to use the cloud-storage feature). There are no 3rd party dependencies (unless one wants to recompile the core). Everything is open source.
Get the Code
- It is easier to stay up to date with changes in Blockly
- It encourages using plugins instead of monkeypatching Blockly
If you need more convincing you can watch our 2021 Blockly on npm talk. If you are already using a package manager, you can install Blockly with
npm install --save blockly
You can reference Blockly in your application code with:
import Blockly from 'blockly';
If you aren't using a package manager for your project, but don't want to have to copy the code yourself, you can use unpkg.
Unpkg grabs the latest version of the published code, so there won't be any version control with this method. It is great for demos or quick experiments, and we use it in many codelabs.
You can also copy the entire source code from GitHub. However, you will have to manually sync to our repository at regular intervals in order to receive the latest updates and fixes to Blockly.
First, download the source code from GitHub. If you know how to use Git or Subversion, we highly recommend syncing from our repository so that your code stays up to date.
Once you have the code, point your browser at
verify that blocks can be dragged around.
In your application code, you can load Blockly with:
You may need to include other files as well, which are explained in the "Injecting Blockly" guides linked in the next section.
With your installation of Blockly verified as working, inject Blockly into a
web page using a fixed-size
→ More info on injecting fixed-sized Blockly...
More advanced web pages may wish to allow Blockly to resize to fill the page.
→ More info on injecting resizable Blockly...
Blockly is highly configurable. For instance, you may set the theme or renderer on a workspace, set a workspace to RTL mode, or select from a variety of zoom and scroll modes.
Configuration is done per-workspace, by passing a configuration struct when injecting a Blockly workspace.
→ More info on configuring a workspace...
In addition to the default blocks that come with Blockly, custom blocks need to be built to call your web application's API. An example is this maze game which has custom blocks for movement.
→ More info on creating custom blocks...
→ More info on code generators...
Importing and Exporting Blocks
If your application needs to save and store the user's blocks and restore them at a later visit, use this call to serialize to JSON:
var json = Blockly.serialization.workspaces.save(workspace);
And deserializing JSON to blocks is just as easy:
Blockly comes with an optional cloud-storage feature. It enables users to save, load, share, and publish their programs. If your project is hosted on App Engine you can take advantage of this service.
→ More info on Cloud Storage...