Buttons and labels
Stay organized with collections
Save and categorize content based on your preferences.
You can put a button or label anywhere you can put a block in the toolbox.

JSON
{
"kind": "flyoutToolbox",
"contents": [
{
"kind": "block",
"type":"logic_operation"
},
{
"kind": "label",
"text": "A label",
"web-class": "myLabelStyle"
},
{
"kind": "label",
"text": "Another label"
},
{
"kind": "block",
"type": "logic_negate"
},
{
"kind": "button",
"text": "A button",
"callbackKey": "myFirstButtonPressed"
},
{
"kind": "block",
"type": "logic_boolean"
}
]
}
XML
<xml id="toolbox" style="display: none">
<block type="logic_operation"></block>
<label text="A label" web-class="myLabelStyle"></label>
<label text="Another label"></label>
<block type="logic_negate"></block>
<button text="A button" callbackKey="myFirstButtonPressed"></button>
<block type="logic_boolean"></block>
</xml>
<style>
.myLabelStyle>.blocklyFlyoutLabelText {
font-style: italic;
fill: green;
}
</style>
You may specify a CSS class name to apply to your button or label.
In the above example, the first label uses a custom style, while the second
label uses the default style.
Buttons should have callback functions; labels should not. To set the callback
for a given button click, use
yourWorkspace.registerButtonCallback(yourCallbackKey, yourFunction).
Your function should accept as an argument the button that was clicked.
The "Create variable..." button in the variable category is a good example of a
button with a callback.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-24 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-24 UTC."],[],[],null,["# Buttons and labels\n\nYou can put a button or label anywhere you can put a block in the toolbox.\n\n### JSON\n\n {\n \"kind\": \"flyoutToolbox\",\n \"contents\": [\n {\n \"kind\": \"block\",\n \"type\":\"logic_operation\"\n },\n {\n \"kind\": \"label\",\n \"text\": \"A label\",\n \"web-class\": \"myLabelStyle\"\n },\n {\n \"kind\": \"label\",\n \"text\": \"Another label\"\n },\n {\n \"kind\": \"block\",\n \"type\": \"logic_negate\"\n },\n {\n \"kind\": \"button\",\n \"text\": \"A button\",\n \"callbackKey\": \"myFirstButtonPressed\"\n },\n {\n \"kind\": \"block\",\n \"type\": \"logic_boolean\"\n }\n ]\n }\n\n### XML\n\n \u003cxml id=\"toolbox\" style=\"display: none\"\u003e\n \u003cblock type=\"logic_operation\"\u003e\u003c/block\u003e\n \u003clabel text=\"A label\" web-class=\"myLabelStyle\"\u003e\u003c/label\u003e\n \u003clabel text=\"Another label\"\u003e\u003c/label\u003e\n \u003cblock type=\"logic_negate\"\u003e\u003c/block\u003e\n \u003cbutton text=\"A button\" callbackKey=\"myFirstButtonPressed\"\u003e\u003c/button\u003e\n \u003cblock type=\"logic_boolean\"\u003e\u003c/block\u003e\n \u003c/xml\u003e\n\n \u003cstyle\u003e\n .myLabelStyle\u003e.blocklyFlyoutLabelText {\n font-style: italic;\n fill: green;\n }\n \u003c/style\u003e\n\nYou may specify a CSS class name to apply to your button or label.\nIn the above example, the first label uses a custom style, while the second\nlabel uses the default style.\n\nButtons should have callback functions; labels should not. To set the callback\nfor a given button click, use \n\n yourWorkspace.registerButtonCallback(yourCallbackKey, yourFunction).\n\nYour function should accept as an argument the button that was clicked.\nThe \"Create variable...\" button in the variable category is a good example of a\nbutton with a callback."]]