Code Block Icons
Once the plugin is installed, code fences automatically get a small icon.
Icons are chosen either by the language or by the filename in the block’s title
.
-
Enable the features
Section titled “Enable the features”astro.config.mjs Icons({codeblock: true,extractSafelist: true,starlight: { ... },}) -
Add the cache to
Section titled “Add the cache to .gitignore”.gitignore
.gitignore .starlight-icons -
Install the Material Icon Theme collection
Section titled “Install the Material Icon Theme collection”Terminal window npm i -D @iconify-json/material-icon-themeTerminal window pnpm add -D @iconify-json/material-icon-themeTerminal window yarn add -D @iconify-json/material-icon-themeTerminal window bun add -D @iconify-json/material-icon-themeTerminal window ni -D @iconify-json/material-icon-theme
Example
Section titled “Example”Based on language
Section titled “Based on language”```ts title="app.ts"console.log('hi')```
Rendered
console.log('hi')
Based on filename
Section titled “Based on filename”```md title="README.md"# README```
Rendered
# README
Customization
Section titled “Customization”Set CSS variables to configure codeblock icons.
:root { --spi-codeblock-icon-size: 1.2rem; --spi-codeblock-icon-gap-right: 0.5rem; --spi-codeblock-icon-gap-left: 0.5rem;}