Beta Feature
Let us know so we can improve!
tile/code
Shows preformatted source code content with an optional language label.
| Name | Required | Lightning Type | Default | Description |
|---|---|---|---|---|
| code | Yes | lightning__multilineTextType | The source code text string, which includes any programming or markup language. | |
| language | No | lightning__textType | A programming language identifier shown as a header label. For example: javascript, python, sql. |
Display a block of preformatted source code in a monospace font, preserving whitespace, indentation, and line breaks exactly as written. Use tile/code to show a snippet, command, config file, or query.
For inline code within a sentence, use tile/text with variant: "code" instead. For rich-formatted content, use tile/markdown instead.
Note
Embed newlines as \n and include any indentation directly in the code string. Whitespace is preserved exactly as you entered it.
1{
2 "definition": "tile/code",
3 "attributes": {
4 "code": "const greeting = 'Hello, World!';\nconsole.log(greeting);",
5 "language": "javascript"
6 }
7}When the snippet doesn’t match a supported language, omit language to hide the header.
1{
2 "definition": "tile/code",
3 "attributes": {
4 "code": "some_command --flag value\nanother_command | pipe_to_here"
5 }
6}Use the language attribute with these languages.
javascripttypescriptpythonjavaccppcsharpgorustrubyphpsqlhtmlcssjsonyamlxmlbashmarkdownConsider these guidelines when working with code.
language to a lowercase identifier such as "python" or "sql", so the header label appears.Note any limitations that apply to this component.
No known limitations for tile/code in Slackbot.
No known limitations for tile/code in ChatGPT.
language isn’t supported. The code block renders as monospace text without syntax highlighting.
Beta Feature