12 CSS Code Blocks
Twelve hand-coded CSS code blocks you can copy in one click — built for every place a developer needs to display code on the web: a minimalist dark mode code box, a mac terminal CSS code block with traffic-light chrome, a working CSS code block with copy button driven by navigator.clipboard, a CSS code block with line numbers powered by counter-increment (numbers never get copied with the source), a mobile-responsive overflow-x vs word-wrap split, a neon glow tech block, a glassmorphism code block in CSS with frosted backdrop-filter, inline <code> pill styling for editorial prose, a neumorphic embedded surface, a split-pane code-plus-live-preview container, a Stripe-style light mode editorial theme, and a pure-CSS expandable / collapsible wrapper that uses the checkbox hack — no JavaScript required. Every demo ships semantic <pre><code>, scoped .ccb-XXX class names that never collide with host styles, prefers-reduced-motion fallbacks, and MIT licensing. No frameworks, no build step.
Frequently asked questions
How do I make a CSS code block with a copy button?
<pre><code> in a container with position: relative, then absolutely position a <button> at the top-right with position: absolute; top: 12px; right: 12px. Hide it at rest (opacity: 0) and reveal on container hover via .codeblock:hover .copy { opacity: 1 }. The click handler calls navigator.clipboard.writeText(codeEl.innerText) inside a try / catch and toggles a temporary .is-done class with setTimeout for the "Copied!" confirmation state. The Copy Button demo (#03) in this gallery is the production-ready reference — it handles browsers without clipboard API permission gracefully and resets after 1.6 seconds.How do I add line numbers to a CSS code block?
counter-reset + counter-increment + a ::before pseudo-element so the numbers are generated CSS content, not real text nodes — which means line numbers never get copied with the code when a visitor triple-clicks and copies. Set counter-reset: line on the wrapper, then each row gets ::before { counter-increment: line; content: counter(line); } styled inside a fixed-width gutter (grid-template-columns: 3.4em 1fr keeps the gutter and the code in two clean columns). The Line Numbers demo (#04) ships this with an editor-style filename tab bar so it doubles as a multi-file documentation panel.How do I build a Mac terminal CSS code block with traffic-light controls?
#ff5f57, yellow #febc2e, green #28c840) inside a 9px-gap flex container, and a centered filename. Add box-shadow: inset 0 1px 1px rgba(255,255,255,.4) to each dot for the canonical highlight. Wrap the whole window in a perspective: 1600px scene with transform: rotateX(6deg) rotateZ(-.4deg) for a subtle 3D tilt that straightens on hover. The Mac Window demo (#02) is the complete pattern with traffic-light dots, filename, and Fira Code typography.How do I make a glassmorphism code block in CSS?
rgba(255,255,255,.08) for the tint, (2) backdrop-filter: blur(22px) saturate(160%) to frost everything behind the panel, and (3) two inset shadows — inset 0 1px 0 rgba(255,255,255,.3) at top for the rim-light edge and a faint inset at bottom for the glass thickness. Always add -webkit-backdrop-filter for Safari. The Glassmorphism Code Terminal demo (#07) shows the production setup over a multi-color radial-gradient backdrop with blurred orbs, plus high-contrast text and text-shadow so accessibility doesn't suffer over the busy background.Can I build an expandable / collapsible code block with no JavaScript?
<input type="checkbox" id="exp">, pair it with a <label for="exp"> that acts as the toggle button, and use the general-sibling combinator: .toggle:checked ~ .codewrap pre { max-height: 1200px } overrides the resting max-height: 190px with a transition: max-height .45s. A linear-gradient fade mask at the bottom hints at hidden content; .toggle:checked ~ .codewrap .fade { opacity: 0 } dissolves it when expanded. The Expandable demo (#12) ships this with a rotating chevron and proper aria-label on the checkbox for screen readers.How do I make a CSS code block responsive on mobile?
overflow-x: auto; white-space: pre keeps the source on one row and adds a horizontal scrollbar — preserves visual structure, costs a scroll affordance. (2) white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere wraps mid-token if needed — no scrollbar, costs the visual one-line meaning. Pick (1) for code where line structure matters (multi-line functions) and (2) for code with long single-token strings (URLs, hashes, file paths). The Responsive demo (#05) shows both side by side with a styled gradient scrollbar so you can decide per-context.How do I style inline <code><code></code> pills inside paragraphs?
<code> pills sit right inside prose: (1) font-size: .82em so the pill scales with the paragraph rather than fighting it; (2) vertical-align: middle so the rounded background never pushes the line taller than its siblings; (3) white-space: nowrap so identifiers like display: grid never get split across a line break. Add padding: 2px 8px; border-radius: 999px for the full pill shape, and use utility classes (.warn, .blue) to swap only the background and text color when you need variants. The Inline Pill demo (#08) demonstrates the pattern in a real article context with a drop-cap lead paragraph.Are these CSS code blocks accessible to screen readers?
<pre><code> elements (not styled <div>s) so assistive tech announces them as preformatted code. Icon-only buttons (the Copy button in demo #03) carry aria-label. Decorative elements — traffic-light dots, scan-line blips, glow orbs — are marked aria-hidden="true" so they don't get spelled out. The Expandable toggle (demo #12) uses a visible-label checkbox with aria-label describing the action. Every continuous animation is wrapped in @media (prefers-reduced-motion: reduce) and either disabled or reduced to a snap transition.Can I embed these code blocks in Shopify, WordPress, or any CMS?
<script> tags). For Shopify, paste into the product or page template editor — the CSS goes into theme.css or a section's <style> block. All class names use the .ccb-XXX prefix so they never collide with your theme styles, the JS scopes its queries to the demo's wrapper so multiple code blocks on one page coexist, and there are no framework or build-step dependencies.Related collections
30 CSS Badges
30 hand-coded CSS badges spanning collectibles, status indicators, certifications, notifications, membership tiers, and live-data displays. Upload progress, typing indicator, scrabble tile, keycap shortcut, transit indicator, origami medal, hreflang, E-E-A-T, crawl status, schema, search intent, core web vitals, ECG, build pipeline, countdown, live price, file extension, dice, signal bars, reading time, aurora, vaporwave, risograph, wax seal, conference lanyard, botanical tier, cyberpunk glitch, art deco, brutalist status, holographic.
14 CSS Banners & Alerts
Hand-coded CSS banner and alert patterns covering every notification surface a real product needs — dismissible alerts, sticky announcements, semantic status alerts, cookie consent, form validation, toasts, live-update banners, and promotional hero banners. Pure CSS plus scoped JS — no framework, semantic HTML, accessibility-first, copy-paste ready.
19 CSS Blockquote Designs
19 hand-coded CSS blockquote designs — pull quotes, testimonials, speech bubbles, tweet style, newspaper drop-caps, code comments and more. Semantic HTML, copy-paste ready.