Monospace code block with an optional file name, line numbers, and a copy button. Plain text, no syntax highlighting.
format-price.ts
export function formatPrice(amount: number) { return new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", }).format(amount);}
format-price.ts
export function formatPrice(amount: number) { return new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", }).format(amount);}format-price.ts
export function formatPrice(amount: number) { return new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", }).format(amount);}format-price.ts
export function formatPrice(amount: number) { return new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", }).format(amount);}format-price.ts
export function formatPrice(amount: number) { return new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", }).format(amount);}@php
$code = <<<'CODE'
export function formatPrice(amount: number) {
return new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
}).format(amount);
}
CODE;
@endphp
<x-markas.code-block :code="$code" title="format-price.ts" />Examples
Line numbers
Counter.tsx
import { useState } from "react";export function Counter() { const [count, setCount] = useState(0); const add = () => setCount(count + 1); return ( <button onClick={add}> Clicked {count} times </button> );}
Counter.tsx
import { useState } from "react";export function Counter() { const [count, setCount] = useState(0); const add = () => setCount(count + 1); return ( <button onClick={add}> Clicked {count} times </button> );}Counter.tsx
import { useState } from "react";export function Counter() { const [count, setCount] = useState(0); const add = () => setCount(count + 1); return ( <button onClick={add}> Clicked {count} times </button> );}Counter.tsx
import { useState } from "react";export function Counter() { const [count, setCount] = useState(0); const add = () => setCount(count + 1); return ( <button onClick={add}> Clicked {count} times </button> );}Counter.tsx
import { useState } from "react";export function Counter() { const [count, setCount] = useState(0); const add = () => setCount(count + 1); return ( <button onClick={add}> Clicked {count} times </button> );}Terminal commands
Terminal
pnpm add markasuipnpm markasui initpnpm markasui add carousel
Terminal
pnpm add markasuipnpm markasui initpnpm markasui add carouselTerminal
pnpm add markasuipnpm markasui initpnpm markasui add carouselTerminal
pnpm add markasuipnpm markasui initpnpm markasui add carouselTerminal
pnpm add markasuipnpm markasui initpnpm markasui add carousel@php
$code = <<<'CODE'
pnpm add markasui
pnpm markasui init
pnpm markasui add carousel
CODE;
@endphp
<x-markas.code-block :code="$code" title="Terminal" />import { CodeBlock } from "@/components/markas/CodeBlock";
const code = [
"pnpm add markasui",
"pnpm markasui init",
"pnpm markasui add carousel",
].join("\n");
export default function Example() {
return <CodeBlock code={code} title="Terminal" />;
}<script lang="ts">
import CodeBlock from "$lib/components/markas/CodeBlock.svelte";
const code = [
"pnpm add markasui",
"pnpm markasui init",
"pnpm markasui add carousel",
].join("\n");
</script>
<CodeBlock {code} title="Terminal" />---
import CodeBlock from "@/components/markas/CodeBlock.astro";
const code = [
"pnpm add markasui",
"pnpm markasui init",
"pnpm markasui add carousel",
].join("\n");
---
<CodeBlock code={code} title="Terminal" />Without title
{ "name": "acme-dashboard", "private": true, "scripts": { "dev": "vite", "build": "vite build" }}
{ "name": "acme-dashboard", "private": true, "scripts": { "dev": "vite", "build": "vite build" }}{ "name": "acme-dashboard", "private": true, "scripts": { "dev": "vite", "build": "vite build" }}{ "name": "acme-dashboard", "private": true, "scripts": { "dev": "vite", "build": "vite build" }}{ "name": "acme-dashboard", "private": true, "scripts": { "dev": "vite", "build": "vite build" }}Long lines
create-invoice.sh
curl -X POST https://api.example.com/v1/invoices -H "Authorization: Bearer $API_TOKEN" -d '{"customer":"cus_1024","amount":25000}'
create-invoice.sh
curl -X POST https://api.example.com/v1/invoices -H "Authorization: Bearer $API_TOKEN" -d '{"customer":"cus_1024","amount":25000}'create-invoice.sh
curl -X POST https://api.example.com/v1/invoices -H "Authorization: Bearer $API_TOKEN" -d '{"customer":"cus_1024","amount":25000}'create-invoice.sh
curl -X POST https://api.example.com/v1/invoices -H "Authorization: Bearer $API_TOKEN" -d '{"customer":"cus_1024","amount":25000}'create-invoice.sh
curl -X POST https://api.example.com/v1/invoices -H "Authorization: Bearer $API_TOKEN" -d '{"customer":"cus_1024","amount":25000}'@php
$code = <<<'CODE'
curl -X POST https://api.example.com/v1/invoices -H "Authorization: Bearer $API_TOKEN" -d '{"customer":"cus_1024","amount":25000}'
CODE;
@endphp
<x-markas.code-block :code="$code" title="create-invoice.sh" show-line-numbers />import { CodeBlock } from "@/components/markas/CodeBlock";
const code = [
'curl -X POST https://api.example.com/v1/invoices -H "Authorization: Bearer $API_TOKEN" -d \'{"customer":"cus_1024","amount":25000}\'',
].join("\n");
export default function Example() {
return <CodeBlock code={code} title="create-invoice.sh" showLineNumbers />;
}<script setup lang="ts">
import CodeBlock from "@/components/markas/CodeBlock.vue";
const code = [
'curl -X POST https://api.example.com/v1/invoices -H "Authorization: Bearer $API_TOKEN" -d \'{"customer":"cus_1024","amount":25000}\'',
].join("\n");
</script>
<template>
<CodeBlock :code="code" title="create-invoice.sh" show-line-numbers />
</template><script lang="ts">
import CodeBlock from "$lib/components/markas/CodeBlock.svelte";
const code = [
'curl -X POST https://api.example.com/v1/invoices -H "Authorization: Bearer $API_TOKEN" -d \'{"customer":"cus_1024","amount":25000}\'',
].join("\n");
</script>
<CodeBlock {code} title="create-invoice.sh" showLineNumbers />---
import CodeBlock from "@/components/markas/CodeBlock.astro";
const code = [
'curl -X POST https://api.example.com/v1/invoices -H "Authorization: Bearer $API_TOKEN" -d \'{"customer":"cus_1024","amount":25000}\'',
].join("\n");
---
<CodeBlock code={code} title="create-invoice.sh" showLineNumbers />Installation
npx markasui@latest add code-blockpnpm dlx markasui@latest add code-blockyarn dlx markasui@latest add code-blockbunx --bun markasui@latest add code-block- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Install the dependency:
npm install alpinejs - Copy the component source below to
resources/views/components/markas/code-block.blade.php.
resources/views/components/markas/code-block.blade.php
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/CodeBlock.tsx.
src/components/markas/CodeBlock.tsx
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/CodeBlock.vue.
src/components/markas/CodeBlock.vue
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/lib/components/markas/CodeBlock.svelte.
src/lib/components/markas/CodeBlock.svelte
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/CodeBlock.astro.
src/components/markas/CodeBlock.astro
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/app/markas/code-block.component.ts.
src/app/markas/code-block.component.ts
Usage
@php
$code = <<<'CODE'
pnpm add markasui
pnpm markasui add carousel
CODE;
@endphp
<x-markas.code-block :code="$code" title="Terminal" />Needs Alpine.js for the copy button.
import { CodeBlock } from "@/components/markas/CodeBlock";
const code = `pnpm add markasui
pnpm markasui add carousel`;
<CodeBlock code={code} title="Terminal" />;<script setup lang="ts">
const code = `pnpm add markasui
pnpm markasui add carousel`;
</script>
<template>
<CodeBlock :code="code" title="Terminal" />
</template><script lang="ts">
import CodeBlock from "$lib/components/markas/CodeBlock.svelte";
const code = `pnpm add markasui\npnpm markasui init`;
</script>
<CodeBlock {code} title="Terminal" showLineNumbers />---
import CodeBlock from "@/components/markas/CodeBlock.astro";
const code = `pnpm add markasui\npnpm markasui init`;
---
<CodeBlock code={code} title="Terminal" showLineNumbers />A small bundled script handles the copy button of every code block on the page.
import { Component } from "@angular/core";
import { CodeBlock } from "./markas/code-block.component";
@Component({
selector: "app-example",
imports: [CodeBlock],
template: `
<div markas-code-block [code]="code" title="Terminal" showLineNumbers></div>
`,
})
export class Example {
code = "pnpm add markasui\npnpm markasui init";
}- Code is plain text without syntax highlighting, so it stays small and identical in every framework.
- Add
showLineNumbers(show-line-numbersin Blade and Vue) for longer snippets. - The copy button uses
navigator.clipboard, which needs HTTPS or localhost.
Props
| Name | Type | Default | Description |
|---|---|---|---|
code | string | - | The code to show and copy. Passed as a string so all three frameworks render the same lines. |
title | string | - | Optional file name or caption shown in the header. |
showLineNumbers | boolean | false | Show line numbers. They are hidden from screen readers and not selectable. |
copyLabel | string | Copy code | Text of the copy button. |
copiedLabel | string | Copied | Text shown for two seconds after the code is copied. |
Accessibility
- The pre element has tabindex=0, so keyboard users can focus it and scroll long lines horizontally.
- The copy button is a native button with visible text, and the copied message is announced through aria-live.
- Line numbers are aria-hidden so screen readers read only the code.
Related components
More data components with the same classes in every framework.
- AvatarRound profile photo in three sizes, with name initials as a fallback when the image is empty or fails to load.
- CardCard that groups content with an optional title, description, body, and footer.
- CarouselRow of slides built on CSS scroll snap, with previous and next buttons, optional dots, and arrow key navigation. No autoplay.
- KbdKeycap for keyboard shortcuts using the native kbd element, in two sizes, with key combinations rendered as separate keys.
- Scroll AreaScrollable container with a thin token-styled scrollbar that keyboard users can focus and scroll. No JavaScript.
- SeparatorHorizontal or vertical dividing line, decorative by default, with an optional label in the middle such as "or".