# Code Block Learn how to integrate Shiki, a beautiful yet powerful syntax highlighter.

Shiki (式, a Japanese word for "Style") is a beautiful and powerful syntax highlighter based on TextMate grammar and themes, the same engine as VS Code's syntax highlighting. It provides accurate and fast syntax highlighting for almost any mainstream programming language.

Shiki Documentation →
## Installation [Install Shiki](https://shiki.style/guide/install) with your preferred package manager. ```console npm install -D shiki ``` ## Create a Component A reusable component should suffice in most projects. Tap the `code` tab below to access the source, then follow the steps below. 1. Implement a new `` component in `/src/lib/components/CodeBlock/CodeBlock.svelte`. 2. Implement the required component prop types in `/src/lib/components/CodeBlock/types.ts`. 3. Implement several variations of our `` component in any SvelteKit route `+page.svelte`. ```svelte
{@html generatedHtml}
``` A few things of note about this component: - You will need to import and configure any number of [Shiki themes](https://shiki.style/themes). - You will need to import and configure any number of [supported languages](https://shiki.style/languages). - The component has been implemented using Skeleton's [component style guidelines](http://localhost:4321/docs/resources/contribute/components). - This provides a number of style props for easy customization via Skeleton's standard conventions. - The component exposes `code`, `lang`, and `theme` properties to configure on-the-fly. - The Code Block `
` tag is auto-generated by Shiki; target utility classes with: `[&>pre]:myClassHere`.

## Programmatic Usage

This use case falls outside the scope of Skeleton. The following is provided merely as guidance.

In some cases you may not have direct access to the source code, such as content from a blog posts or CMS pages. In fact the code may even come pre-baked with surrounding `
` or `` elements. For this, you'll need to follow the general steps below. Specific implementation may differ based on your app and meta-framework.

1. Query all `
` or `` blocks using Javascript tools like `document.querySelectorAll()`. Be as specific as possible.
2. Ensure you have a clean instance of the source code itself, with no extra markup injected within.
3. Use Shiki's [codeToHtml](https://shiki.style/guide/install#shorthands) feature to parse the code as styled HTML markup.
4. Then append each instance of the code blocks in your DOM.

For more instructions, please refer to this guide by [Joy of Code](https://joyofcode.xyz/) explaining how to [implement Shiki via MDX](https://joyofcode.xyz/sveltekit-markdown-blog#using-components-inside-markdown).

## Custom Themes

Shiki provides support for generating a custom highlighter theme:

- [Loading Custom Themes](https://shiki.style/guide/load-theme)
- [List of Bundled Themes](https://shiki.style/themes)

Shiki theme values can be defined using Skeleton custom theme properties, such as `rgba(--color-primary-500)`.

## Accessibility

See [Salma Alam-Naylor's](https://whitep4nth3r.com/about/) guidelines for [creating accessible code blocks](https://whitep4nth3r.com/blog/how-to-make-your-code-blocks-accessible-on-your-website/) that meet WGAC standards.