Code blocks
Code
is used 23
times on 11
pages.
Pages which use Code
Used 23 times.
Pages
- /style-guide/components/available-notifications/ - Source
- /style-guide/components/glossary-definition/ - Source
- /style-guide/components/glossary-tooltip/ - Source
- /style-guide/components/glossary/ - Source
- /style-guide/components/render/ - Source
- /workers-ai/features/json-mode/ - Source
- /workers-ai/features/prompting/ - Source
- /workers/get-started/prompting/ - Source
Partials
Code blocks are powered by Expressive Code ↗, a project by Astro. This is just a small showcase of the wide functionality of this component.
Learn more about formatting in the code block formatting guide.
Write-Output "This one has a title!"
// Collapsingconst foo = {3 collapsed lines
1: 1, 2: 2, 3: 3,};
// Line numbersconst foo = "bar";const bar = "baz";
// Example with wrapfunction getLongString() { return "This is a very long string that will most probably not fit into the available space unless the container is extremely wide";}
function demo() { console.log("These are inserted and deleted marker types"); // The return statement uses the default marker type return true;}
function thisIsJavaScript() { // This entire block gets highlighted as JavaScript, // and we can still add diff markers to it! console.log('Old code to be removed') console.log('New and shiny code!')}
```powershell title="PowerShell"Write-Output "This one has a title!"```
```js collapse={3-5}// Collapsingconst foo = { 1: 1, 2: 2, 3: 3,};```
```js showLineNumbers// Line numbersconst foo = "bar";const bar = "baz";```
```js wrap// Example with wrapfunction getLongString() { return "This is a very long string that will most probably not fit into the available space unless the container is extremely wide";}```
```js "return true;" ins="inserted" del="deleted"function demo() { console.log("These are inserted and deleted marker types"); // The return statement uses the default marker type return true;}```
```diff lang="js" function thisIsJavaScript() { // This entire block gets highlighted as JavaScript, // and we can still add diff markers to it!- console.log('Old code to be removed')+ console.log('New and shiny code!') }```
If you would like to include the output of your code block, create a second code block below and add the output
property to the opening code fence.
npx wrangler vectorize create tutorial-index --dimensions=3 --metric=cosine
✅ Successfully created index 'tutorial-index'
[[vectorize]]binding = "VECTORIZE_INDEX" # available in your Worker on env.VECTORIZE_INDEXindex_name = "tutorial-index"
```shnpx wrangler vectorize create tutorial-index --dimensions=3 --metric=cosine```
```sh output✅ Successfully created index 'tutorial-index'
[[vectorize]]binding = "VECTORIZE_INDEX" # available in your Worker on env.VECTORIZE_INDEXindex_name = "tutorial-index"```
If you add the playground
option to the opening code fence for a Worker example, it will
add a "Run Worker in Playground" link that will take the user to the Worker's playground
export default { fetch() { return new Response("Test!"); },};
```js playgroundexport default { fetch() { return new Response("Test!"); },};```
Add graphql-api-explorer
to the opening code fence to create a graphql
code block with a Run in GraphQL API Explorer button that leads to GraphQL API Explorer ↗.
query ASingleDatasetExample($zoneTag: string, $start: Time, $end: Time) { viewer { zones(filter: { zoneTag: $zoneTag }) { firewallEventsAdaptive( filter: { datetime_gt: $start, datetime_lt: $end } limit: 2 orderBy: [datetime_DESC] ) { action datetime host: clientRequestHTTPHost } } }}
```graphql graphql-api-explorer title="A GraphQL query"query ASingleDatasetExample($zoneTag: string, $start: Time, $end: Time) { viewer { zones(filter: { zoneTag: $zoneTag }) { firewallEventsAdaptive( filter: { datetime_gt: $start, datetime_lt: $end } limit: 2 orderBy: [datetime_DESC] ) { action datetime host: clientRequestHTTPHost } } }}```
In the GraphQL API Explorer, the Variables section is automatically filled based on the names and types of the variables defined in your query:
- Variables that include
start
and are of typeTime
are set to six hours before the current time - Variables that include
end
and are of typeTime
are set to the current time - Variables that include
start
and are of typeDate
are set to 24 hours before the current date - Variables that include
end
and are of typeDate
are set to the current date - Variables that include
zoneTag
and are of typestring
are set to "ZONE_ID" - Variables that include
accountTag
and are of typestring
are set to "ACCOUNT_ID" - Variables that include
id
and are of typestring
are set to "REPLACE_WITH_ID" - Variables that include
limit
and are of typeint
are set to 100 - Any other variable with a type of
string
is set to "REPLACE_WITH_STRING"
You can also add custom variables by setting their values as a JSON string in the graphql-api-explorer
metadata. The custom variables will be merged with the automatically populated variables.
In the following example, the custom value is custom-variable
:
```graphql graphql-api-explorer='{"uID": "custom-variable"}' title="A GraphQL query"query GraphqlExample($zoneTag: string, $start: Time, $end: Time) { viewer { zones(filter: { zoneTag: $zoneTag }) { ... } }}```
So, the Variables would look something like this:
{"zoneTag":"ZONE_ID", "start":"2025-09-11T14:00:00Z", "end":"2025-09-11T20:00:00Z", "uId": "custom-variable"}
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark