Skip to content

Themes

bxp-code ships with dark and light themes and supports full color customization on both BxpCode and BxpCodeTabs.

Built-in Themes

Dark Theme (Default)

tsx
<BxpCode
  code={`const theme: string = "dark";`}
  lang="typescript"
  theme="dark"
/>
jsx
<BxpCode code={`const theme = "dark";`} lang="javascript" theme="dark" />

Default colors:

ElementColor
Header#16161e
Background#1a1b26
Border#2a2a3a

Light Theme

tsx
<BxpCode
  code={`const theme: string = "light";`}
  lang="typescript"
  theme="light"
/>
jsx
<BxpCode code={`const theme = "light";`} lang="javascript" theme="light" />

Default colors:

ElementColor
Header#e8e8e8
Background#fafafa
Border#d0d7de

Custom Colors

Override theme colors with headerColor and backgroundColor:

tsx
<BxpCode
  code={`// Ocean theme`}
  lang="javascript"
  theme="dark"
  headerColor="#1e3a5f"
  backgroundColor="#0d1b2a"
/>

Color Presets

GitHub Dark

tsx
<BxpCode
  code={`const github = "dark";`}
  lang="javascript"
  headerColor="#161b22"
  backgroundColor="#0d1117"
/>

Purple Night

tsx
<BxpCode
  code={`const mood = "purple";`}
  lang="javascript"
  headerColor="#2d1b4e"
  backgroundColor="#1a0f2e"
/>

Forest

tsx
<BxpCode
  code={`const nature = "forest";`}
  lang="javascript"
  headerColor="#1b3d2f"
  backgroundColor="#0f261c"
/>

BxpCodeTabs Theming

BxpCodeTabs provides additional color props for fine-grained control:

tsx
<BxpCodeTabs
  theme="dark"
  headerColor="#1e1e2e"
  backgroundColor="#181825"
  borderColor="#45475a"
  tabIndicatorColor="#cba6f7"
  tabActiveColor="#1e1e2e"
  tabActiveTextColor="#cdd6f4"
  tabTextColor="#6c7086"
  copyButtonColor="rgba(30, 30, 46, 0.9)"
  lineNumberColor="#585b70"
  tabs={[
    { lang: "rust", code: `fn main() { println!("Styled!"); }` },
    { lang: "go", code: `func main() { fmt.Println("Styled!") }` },
  ]}
/>

→ See BxpCodeTabs Customization for all color props.

Dynamic Theme Switching

tsx
import { useState } from "react";
import { BxpCode } from "bxp-code";

function ThemeSwitcher() {
  const [theme, setTheme] = useState<"dark" | "light">("dark");

  return (
    <div>
      <button
        onClick={() => setTheme((t) => (t === "dark" ? "light" : "dark"))}
      >
        Toggle Theme
      </button>
      <BxpCode code={`const dynamic = true;`} lang="javascript" theme={theme} />
    </div>
  );
}
jsx
import { useState } from "react";
import { BxpCode } from "bxp-code";

function ThemeSwitcher() {
  const [theme, setTheme] = useState("dark");

  return (
    <div>
      <button
        onClick={() => setTheme((t) => (t === "dark" ? "light" : "dark"))}
      >
        Toggle Theme
      </button>
      <BxpCode code={`const dynamic = true;`} lang="javascript" theme={theme} />
    </div>
  );
}

Color Reference

PropApplies toDescription
headerColorBothHeader / tab bar background
backgroundColorBothCode area background
borderColorBxpCodeTabsContainer & header border
tabActiveColorBxpCodeTabsActive tab background
tabActiveTextColorBxpCodeTabsActive tab text
tabTextColorBxpCodeTabsInactive tab text
tabIndicatorColorBxpCodeTabsActive tab bottom indicator
copyButtonColorBxpCodeTabsCopy button background
lineNumberColorBxpCodeTabsLine number gutter text

Released under the MIT License.