Skip to content

zk-code-block ​

A block of code with its language, a title, line numbers, highlighted lines and a copy button.

Props ​

PropTypeDefaultDescription
codestring|nullnullThe code. Without it, the content of the slot
languagestring|nullnullLanguage: a language-x class on <code> and a label
titlestring|nullnullTitle, usually a file name
lineNumbersboolfalseAdds data-line-numbers: number the lines with CSS counters on .code-line::before
highlightLinesarray[]Numbers of the lines to mark (data-highlight)
wrapboolfalseAdds data-wrap: your style lets the long lines wrap
copyablebooltrueShows the copy button
copyLabelstring'Copy'Text of the copy button
idstring|nullnullIdentifier of the <code>; by default made from the code
classstring|nullnullCSS class(es) merged onto the root element

Undeclared attributes forward to the root element.

There is no syntax highlighting: the text is escaped and each line is a <span class="code-line">. To highlight, render the code with your highlighter on the server and style its classes, or load one in the browser on .language-x. Needs the script copy of zk-scripts: the component asks for it by itself. Class hooks: code-block, code-block-header, code-block-title, code-block-language, code-block-copy, code-block-pre, code-line.

Examples ​

Basic ​

blade
<x-zk-code-block language="php" title="index.php" :line-numbers="true" :highlight-lines="[2]" :code="$source" />

Documentation of 3.2.0 , built from c93e21f on 3.2.0 by pipeline #2919741884 on 2026-10-06.