Methane@methane-ui/*
CSS LayoutsComponentsSkillsTheme BuilderGitHub
← All Components

<mth-code-block>

@methane-ui/code~6.8 KB brotli shell + lazy engine~1.4 KB shell · lazy engine chunk

Read-only syntax-highlighted code block using the CSS Custom Highlight API (CSS.highlights) with accessible token span fallback, line highlighting, and clipboard copy.

When NOT to use: Use a lightweight @methane-ui/css layout class instead of a custom element when static CSS suffices.

Live Interactive Preview

Interactive StageLive Custom Element · <mth-code-block> (@methane-ui/code)
Ready · interact with <mth-code-block>, or toggle Theme, Direction (LTR/RTL), or props above.

Multi-Framework Playground & Snippets

<script type="module" src="@methane-ui/code/code-block"></script>
<mth-code-block language="text" show-copy>Example</mth-code-block>

Properties & Attributes

PropertyAttributeTypeDefaultDescription
codecodestring""code property.
languagelanguagestring"text"language property.
labellabelstring""label property.
lineNumbersline-numbersbooleanfalselineNumbers property.
highlightLineshighlight-linesstring""highlightLines property.
showCopyshow-copybooleantrueshowCopy property.

Events

EventDetail TypeDescription
mth-copy{ code: string }Emitted event mth-copy.

Accessibility Checklist

CategoryRequirementVerified By
ariaAll aria-* IDREFs resolve within the same DOM root (ADR-003).scanSameRootAria
focusdelegatesFocus: true with zero host internals.role (ADR-014).lint-plugin & spec-compiler
contrastRenders legible borders, focus outlines, and selection indicators under forced-colors: active.Playwright forced-colors matrix
statesExposes ElementInternals CustomStateSet flags: :state(copied), :state(line-numbers), :state(custom-highlight).Conformance suite
i18nRoutes 5 UI/ARIA strings through @methane-ui/core i18n catalog.Locale context test