Home / Snippets / Typography /
Terminal/console style
Style code blocks to look like a real terminal window with a title bar, monospace font, dark background, and $ prompt indicators.
Quick implementation
.terminal {
background: oklch(0.10 0.01 240);
border-radius: 0.5rem;
overflow: hidden;
font-family: var(--font-mono, "JetBrains Mono", monospace);
font-size: 0.875rem;
line-height: 1.7;
}
.terminal__titlebar {
background: oklch(0.18 0.01 240);
padding: 0.6rem 1rem;
display: flex;
align-items: center;
gap: 0.5rem;
}
.terminal__dot {
width: 0.75rem;
height: 0.75rem;
border-radius: 50%;
}
.terminal__dot--close { background: oklch(0.65 0.22 27); }
.terminal__dot--min { background: oklch(0.75 0.18 85); }
.terminal__dot--expand { background: oklch(0.62 0.20 145); }
.terminal__title {
flex: 1;
text-align: center;
color: oklch(0.55 0.01 240);
font-size: 0.78rem;
}
.terminal__body {
padding: 1.25rem 1.5rem;
color: oklch(0.88 0.02 140);
}
.terminal__line { display: block; }
.terminal__line--output { color: oklch(0.70 0.01 240); padding-left: 1.25rem; }
.terminal__line--success{ color: oklch(0.75 0.18 145); padding-left: 1.25rem; }
.terminal__line--error { color: oklch(0.65 0.20 27); padding-left: 1.25rem; }
.terminal__prompt {
color: oklch(0.62 0.20 145);
margin-right: 0.5rem;
user-select: none;
}
.terminal__cursor {
display: inline-block;
width: 0.55rem;
height: 1em;
background: oklch(0.88 0.02 140);
vertical-align: text-bottom;
animation: terminal-blink 1.1s step-end infinite;
}
@keyframes terminal-blink {
0%, 100% { opacity: 1; }
50% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
.terminal__cursor { animation: none; opacity: 1; }
}
Prompt this to your LLM
Includes role, constraints, two framework variants, and edge cases to handle.
You are a senior frontend engineer building a documentation site that
displays CLI commands in realistic terminal windows.
Goal: A pure-CSS .terminal component that looks like a macOS terminal
window — complete with a title bar, three colored traffic-light dots,
a dark background, green prompt indicators, and distinct output colors
for success and error states. No JavaScript required.
Technical constraints:
- Use oklch() for all colors — no hex or rgba values.
- Use a CSS custom property var(--font-mono) for the monospace font
family, falling back to "JetBrains Mono", monospace.
- The title bar uses display: flex with the dots on the left and a
centered title text; achieve centering without absolute positioning
(use flex: 1 on the title span).
- Each line of terminal output is a <span class="terminal__line">;
output, success, and error lines each get a modifier class and a
left padding to visually indent beneath the prompt.
- The $ prompt character uses user-select: none so it is excluded from
copy-paste selection.
- A blinking cursor uses animation with step-end timing (not ease) so
it snaps on/off rather than fading.
- Include @media (prefers-reduced-motion: reduce) that disables the
cursor blink and sets opacity: 1.
Framework variant (pick one):
A) Vanilla HTML/CSS — plain class-based markup with no JS.
B) React component — accept a lines prop (array of
{ text, type: "command"|"output"|"success"|"error" } objects) and
a title prop; render the title bar and body programmatically.
Edge cases to handle:
- Long command lines should wrap within the terminal body rather than
overflow; set overflow-wrap: break-word on .terminal__body.
- On narrow viewports the terminal should not break the page layout —
add overflow-x: auto to .terminal so users can scroll horizontally
when content is wider than the viewport.
- Ensure the component works on light-mode sites too by scoping the
dark background to the component itself rather than relying on a
page-level dark-mode class.
Return CSS only (or a React component if variant B is chosen).
Why terminal UI builds developer trust
Documentation that presents CLI commands inside a realistic terminal chrome does more than look nice — it signals technical credibility. Readers immediately understand the context (shell, not browser console, not a code editor) before reading a single character. The visual metaphor does communicative work that prose cannot. When a developer lands on a "Getting Started" page and sees a properly styled terminal block with green prompts and traffic-light dots, their cognitive load drops: they know exactly where to look and what to type.
This psychological shortcut is well understood in developer-experience design. Tools like iTerm2, Warp, and Hyper have made terminal chrome visually iconic. Borrowing those conventions in documentation turns an abstract code block into a believable simulation of the workflow the reader is about to follow — reducing friction at the critical first-impression moment.
Monospace font considerations
Not all monospace fonts are equal in a terminal context. The ideal terminal font has a few properties: consistent glyph widths across all code points (including box-drawing characters), clear distinction between 0 and O, 1 and l, and | and I, and comfortable rendering at small sizes (12–14 px). JetBrains Mono, used here via var(--font-mono), scores well on all three counts and includes ligatures for common programming operators if desired.
The font-size: 0.875rem default (14 px at base 16) mimics common terminal defaults without feeling cramped. Pair it with a generous line-height: 1.7 — tighter than body text typically needs, but comfortable for scanning command output line-by-line. Avoid using em-based line heights on monospace text because the em square of many monospace fonts is unusually tall, which can produce excessive leading.
Line-height and readability in output blocks
Terminal output is scanned, not read. Users skim for success or error signals, then focus on the relevant lines. A line-height between 1.6 and 1.8 creates just enough vertical rhythm to allow the eye to land on individual lines without losing its place in a wall of text. Going tighter risks lines blurring together; going looser wastes vertical space and breaks the illusion of a real terminal window.
The user-select: none on the .terminal__prompt span is a small but meaningful touch. When a developer triple-clicks a command line to copy it, they want the command — not the $ prefix. Excluding the prompt from selection means the clipboard contains exactly what they will paste into their own terminal, without needing to manually trim the leading dollar sign.
Color also carries semantic weight in output blocks. The component uses three distinct oklch values: muted grey for neutral output, green for success confirmations, and red-orange for errors. These map directly to the conventions established by shell programs themselves — and because they are expressed in oklch(), they maintain perceptually consistent lightness across hues, so no single color feels heavier or more prominent than intended.