ClassiJSYou already know it. Star on GitHub

Examples

Getting Started
OverviewInstallationGetting StartedWork List
Components
Buttons
Basic ButtonsToggle ButtonsButton StatesButton IconsMenu ButtonsMenu Bottom ButtonsSplit ButtonsSplit Bottom ButtonsLeft Text ButtonsRight Text ButtonsLink ButtonsButton with CountSegmented ButtonsVertical Segmented Buttons
Tabs
Basic TabsPlain TabsFramed TabsIcon TabsAdvanced TabsHeader TabsRemote Content TabsLazy TabsReorderable TabsOverflow TabsTab Positions
Menus and Toolbars
Basic ToolbarDocked ToolbarsBreadcrumb ToolbarToolbar OverflowToolbar MenusStatus Bar
Panels
Basic PanelFramed PanelHeader Positioning
Feedback and Overlays
Anchored TooltipsPointer TooltipsRich TooltipsClosable TooltipsPopoversLoading MaskProgress BarWindowsMessage BoxesToast Notifications
Form Fields
Forms and FieldsetsField GroupsCombo BoxTag FieldNumber FieldDate/Month PickerField TypesCheckboxRadioText FieldText AreaColor FieldSelect Field
Advanced Forms
Multi-selectSlider FieldRating FieldForm ValidationRepeatable FieldsUpload ProgressForm Examples
Trees
Basic TreesJSON Tree
Code Block
Basic Code BlockTitle and Line NumbersWrapped CodeEditable Code
Navigation
Thumbnail View

No results found.

Code Block - Basic Code Block

Code Block - Basic Code Block

Basic Code Block

Options
NameValueTypeDefaultDescription
codestringrequiredSource code to display.
langstring"astro"Syntax language used for highlighting.
titlestringNoneDisplays a header with this title and the language.
lineNumbersbooleanfalseShows line numbers.
editablebooleanfalseAllows editing code in a text area.
copybooleantrueShows the copy button.
labelstring"Code editor"Accessible label for the editable text area.
wrapbooleanfalseWraps long lines instead of scrolling horizontally.
Styles
--cj-code-background#FFFFFF
--cj-code-border-color#B5B8C8
/* Choose a color to generate CSS overrides. */
_code.scssscss
.cj-code-block {
  display: block;
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--cj-code-border-color, #b5b8c8);
  color: #000;
  background: var(--cj-code-background, #fff);
}
.cj-code-block__copy[hidden] {
  display: none;
}
.cj-code-block__copy--floating {
  position: absolute;
  z-index: 1;
  top: 4px;
  right: 4px;
}
.cj-code-block__editable {
  position: relative;
}
.cj-code-block__highlight {
  display: none;
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.cj-code-block__editable[data-highlighted] .cj-code-block__highlight {
  display: block;
}
.cj-code-block__highlight pre,
.cj-code-block .cj-code-block__highlight pre.astro-code {
  box-sizing: border-box;
  width: max-content;
  min-width: 100%;
  max-height: none;
  overflow: visible;
  margin: 0;
  padding: 8px 12px;
  border: 0;
  font: 12px/1.4 monospace;
  tab-size: 4;
}
.cj-code-block--wrap .cj-code-block__highlight pre {
  width: 100%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.cj-code-block__editor {
  position: relative;
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 110px;
  margin: 0;
  padding: 8px 12px;
  resize: vertical;
  border: 0;
  background: var(--cj-code-background, #fff);
  color: #222;
  font: 12px/1.4 monospace;
  tab-size: 4;
}
.cj-code-block__editable[data-highlighted] .cj-code-block__editor {
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: #222;
  background: transparent;
}
.cj-code-block__editor:focus-visible {
  outline: 1px dotted #333;
  outline-offset: -2px;
}
.cj-options {
  margin: 16px 0;
  color: #333;
  font: 12px/1.5 var(--cj-font);
}
.cj-disclosure {
  position: relative;
}
.cj-disclosure__button {
  list-style: none;
}
.cj-disclosure__button::-webkit-details-marker {
  display: none;
}
.cj-disclosure__arrow {
  width: 0;
  height: 0;
  border: 4px solid transparent;
  border-top-color: #416da3;
  border-bottom: 0;
}
.cj-disclosure__content {
  position: absolute;
  box-sizing: border-box;
  z-index: var(--cj-z-disclosure, 20000);
  top: calc(100% + 3px);
  right: 0;
  width: min(46rem, calc(100vw - 16px));
  max-height: min(70vh, 36rem);
  overflow: auto;
  padding: 0 12px;
  border: 1px solid #99bce8;
  background: #fff;
  box-shadow: 0 2px 4px #0003;
}
.cj-disclosure__content[data-above] {
  top: auto;
  bottom: calc(100% + 3px);
}
.cj-options__title {
  margin: 0 0 5px;
  color: #15428b;
  font: bold 12px var(--cj-font);
}
.cj-options__note {
  margin: 0 0 8px;
}
.cj-options__scroll {
  overflow-x: auto;
  border: 1px solid #99bce8;
}
.cj-options__table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}
.cj-options__table th,
.cj-options__table td {
  padding: 5px 8px;
  border-right: 1px solid #d0dbe9;
  border-bottom: 1px solid #d0dbe9;
  vertical-align: top;
}
.cj-options__table thead th {
  color: #15428b;
  background: linear-gradient(#f1f6fd, #d6e5f6);
  white-space: nowrap;
}
.cj-options__table tbody th {
  color: #15428b;
  font-weight: normal;
  white-space: nowrap;
}
.cj-options__table tr > :last-child {
  border-right: 0;
}
.cj-options__table tbody tr:last-child > * {
  border-bottom: 0;
}
.cj-options__table tbody tr:nth-child(even) {
  background: #f5f8fc;
}
.cj-options__table code {
  font: 11px/1.5 monospace;
}
.cj-options__type,
.cj-options__default {
  white-space: nowrap;
}
.cj-options--compact {
  display: contents;
}
.cj-options--compact .cj-options__scroll {
  border: 0;
}
.cj-options--compact .cj-options__table :is(th, td) {
  padding: 5px 10px;
  border-inline-end: 0;
  vertical-align: middle;
}
.cj-options--compact .cj-options__table thead th {
  background: #f1f6fd;
}
.cj-options--compact .cj-options__table tbody tr:nth-child(even) {
  background: none;
}
.cj-options--compact .cj-options__table td:last-child {
  min-inline-size: 18ch;
}
.cj-code-block__header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 25px;
  padding: 0 8px;
  border-bottom: 1px solid #b5cbe5;
  background: linear-gradient(#f1f6fd, #d6e5f6);
  color: #15428b;
  font:
    bold 11px tahoma,
    arial,
    sans-serif;
}
.cj-code-block__language {
  margin-left: auto;
  font-weight: normal;
  color: #607b98;
}
.cj-code-block pre.astro-code {
  box-sizing: border-box;
  overflow: auto;
  max-height: min(70vh, 38rem);
  margin: 0;
  padding: 8px 12px;
  border: 0;
  background: var(--cj-code-background, #fff) !important;
  font: 12px/1.4 monospace;
  tab-size: 4;
  user-select: text;
  -webkit-user-select: text;
}
.cj-code-block pre.astro-code code {
  font: inherit;
  user-select: text;
  -webkit-user-select: text;
}
.cj-code-block:has(> .cj-code-block__copy--floating) pre.astro-code,
.cj-code-block:has(> .cj-code-block__copy--floating) .cj-code-block__editor,
.cj-code-block:has(> .cj-code-block__copy--floating)
  .cj-code-block__highlight
  pre {
  padding-right: 72px;
}
.cj-code-block--numbered code {
  counter-reset: cj-code-line;
}
.cj-code-block--numbered .line::before {
  counter-increment: cj-code-line;
  content: counter(cj-code-line);
  display: inline-block;
  min-width: 3ch;
  margin-right: 12px;
  color: #8795a4;
  text-align: right;
  user-select: none;
  -webkit-user-select: none;
}
.cj-code-block--wrap pre.astro-code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.cj-options__value {
  min-width: 130px;
}
.cj-options__value .cj-field,
.cj-options__value .cj-select {
  width: 100%;
}
.cj-options__value .cj-field__input {
  width: 100%;
}
.cj-options__value .cj-number-field .cj-trigger-field {
  flex: 1;
  width: 100%;
}
.cj-options__value [aria-invalid="true"] {
  border-color: #c24040;
  outline: 1px solid #c24040;
}
.cj-options__static {
  color: #7a8794;
}

A highlighted code block without a title.

const message = 'Hello, ClassiJS!';
console.log(message);

Code

---
import { CodeBlock } from 'classijs';
import 'classijs/styles.css';

const source = "const message = 'Hello, ClassiJS!';\nconsole.log(message);";
---
<CodeBlock code={source} lang="js" />