Skip to main contentCarbon Design System

Code snippet

Color

Single line

ClassPropertyColor token
.bx--snippetbackground$field
.bx--snippettext color$text-primary
.bx--snippet__iconsvg$icon-primary
.bx--copy-btn:hoverbackground-color$layer-hover
.bx--copy-btn:focusborder$focus
.bx--copy-btn:activebackground-color$layer-active
States of a single line codesnippet

Enabled, focus, hover, and active states

Multi-line

ClassPropertyColor token
.bx--snippetbackground$field
.bx--snippettext color$text-primary
.bx--snippet__iconsvg$icon-primary
.bx--copy-btn:hover
.bx--snippet-btn:hover
background-color$layer-hover
.bx--copy-btn:focus
.bx--snippet-btn:focus
border$focus
.bx--copy-btn:active
.bx--snippet-btn:active
background-color$layer-active
States of a multi-line codesnippet

States for copy button: active, enabled, hover, focus, disabled

States of a multi-line codesnippet

States for show toggle: enabled, hover, focus

Inline snippet

ClassPropertyColor token
.bx--snippet--inlinebackground-color$field
.bx--snippet--inlinecolor$text-primary
.bx--snippet--inline:hoverbackground-color$field-hover
.bx--snippet--inline:focusfocus$focus
.bx--snippet--inline:activebackground-color$layer-active
States of an inline codesnippet

States for inline codesnippet: enabled, hover, active, focus

Syntax colors

Carbon has defined a set of accessible syntax colors. View an incontext example on CodePen.

Typography

ClassFont-size (px/rem)Font-weightType token
.bx--snippet.code12 / 0.75Regular / 400$code-01
.bx--snippet--inline.code12 / 0.75Regular / 400$code-01

Structure

Single line

ClassPropertypx / remSpacing token
.bx--snippet--singleheight40 / 3–
.bx--snippet--singlemax-width768 / 48–
.bx--snippet--singlepadding-right48 / 3$spacing-09
.bx--snippet--singlepadding-left16 / 1$spacing-05
code snippet style 1

Structure and spacing measurements for code snippet | px / rem

Multi-line code snippet

ClassPropertypx / remSpacing token
.bx--snippet--multimin-height288 / 18–
.bx--snippet--multimax-heightVaries based on content–
.bx--snippet--multimax-width768 / 48–
.bx--snippetpadding16 / 1$spacing-05
.bx--snippet-containerpadding-right40 / 2.5$spacing-08
.bx--snippet__iconheight, width16px–
.bx--snippet-buttonheight, width40 / 2.5–
.bx--copy-buttonheight, width32 / 2–
Structure and spacing measurements for multi-line snippet

Structure and spacing measurements for multi-line snippet | px / rem

Inline code snippet

ClassPropertypx / remSpacing token
.bx--snippet--inlineheight16 / 1–
.bx--snippet--inlinewidthVaries based on content–
.bx--snippet--inlineborder-radius2-
.bx--snippet--inline codepadding-right, padding-left8 / 0.5\$spacing-03
Structure and spacing measurements for inline snippet

Structure and spacing measurements for inline code snippet | px / rem