Theming
Default theme
The theme object is where you define your application's color palette, type scale, font stacks, breakpoints, border radius values, and more.
Colors
The colors
key allows you to customize the color palettes for your project. Hope UI uses color palettes of 10 shades ranging from 50
to 900
.
tsx
import { createPalette } from "@hope-ui/core";// example theme objectexport default {colors: {light: {primary: createPalette({50: "#eff6ff",100: "#dbeafe",200: "#bfdbfe",300: "#93c5fd",400: "#60a5fa",500: "#3b82f6",600: "#2563eb",700: "#1d4ed8",800: "#1e40af",900: "#1e3a8a",}),},},dark: {// ...dark palettes, if needed},};
tsx
import { createPalette } from "@hope-ui/core";// example theme objectexport default {colors: {light: {primary: createPalette({50: "#eff6ff",100: "#dbeafe",200: "#bfdbfe",300: "#93c5fd",400: "#60a5fa",500: "#3b82f6",600: "#2563eb",700: "#1d4ed8",800: "#1e40af",900: "#1e3a8a",}),},},dark: {// ...dark palettes, if needed},};
the createPalette
function will generate three additional values:
mainChannel
: RGB color channel of the500
shade.lightChannel
: RGB color channel of the100
shade.darkChannel
: RGB color channel of the900
shade.
These values allow you to create translucent colors using CSS variables.
tsx
<Box bg={theme => `rgb(${theme.vars.colors.primary.mainChannel} / 0.8)`}>Box with translucent background</Box>
tsx
<Box bg={theme => `rgb(${theme.vars.colors.primary.mainChannel} / 0.8)`}>Box with translucent background</Box>
Below is the list of all colors available in the default Hope UI theme. Switching to dark mode will show the proper values from the dark palette.
If you want to use your own colors, two popular options are TailwindCSS and OpenColor.
Common
Black alpha
White alpha
Primary
Neutral
Success
Info
Warning
Danger
Typography
To manage typography options, the theme object supports the following keys:
fonts
(font families)fontSizes
fontWeights
lineHeights
letterSpacings
tsx
export default {fonts: {sans: "ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'",serif: "ui-serif, Georgia, Cambria, 'Times New Roman', Times, serif",mono: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace",},fontSizes: {xs: "0.75rem",sm: "0.875rem",base: "1rem",lg: "1.125rem",xl: "1.25rem","2xl": "1.5rem","3xl": "1.875rem","4xl": "2.25rem","5xl": "3rem","6xl": "3.75rem","7xl": "4.5rem","8xl": "6rem","9xl": "8rem",},fontWeights: {hairline: 100,thin: 200,light: 300,normal: 400,medium: 500,semibold: 600,bold: 700,extrabold: 800,black: 900,},lineHeights: {none: 1,shorter: 1.25,short: 1.375,base: 1.5,tall: 1.625,taller: 2,"3": "0.75rem","4": "1rem","5": "1.25rem","6": "1.5rem","7": "1.75rem","8": "2rem","9": "2.25rem","10": "2.5rem",},letterSpacings: {tighter: "-0.05em",tight: "-0.025em",normal: "0",wide: "0.025em",wider: "0.05em",widest: "0.1em",},};
tsx
export default {fonts: {sans: "ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'",serif: "ui-serif, Georgia, Cambria, 'Times New Roman', Times, serif",mono: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace",},fontSizes: {xs: "0.75rem",sm: "0.875rem",base: "1rem",lg: "1.125rem",xl: "1.25rem","2xl": "1.5rem","3xl": "1.875rem","4xl": "2.25rem","5xl": "3rem","6xl": "3.75rem","7xl": "4.5rem","8xl": "6rem","9xl": "8rem",},fontWeights: {hairline: 100,thin: 200,light: 300,normal: 400,medium: 500,semibold: 600,bold: 700,extrabold: 800,black: 900,},lineHeights: {none: 1,shorter: 1.25,short: 1.375,base: 1.5,tall: 1.625,taller: 2,"3": "0.75rem","4": "1rem","5": "1.25rem","6": "1.5rem","7": "1.75rem","8": "2rem","9": "2.25rem","10": "2.5rem",},letterSpacings: {tighter: "-0.05em",tight: "-0.025em",normal: "0",wide: "0.025em",wider: "0.05em",widest: "0.1em",},};
Space
The space
key allows you to customize the global spacing scale for your project.
tsx
export default {space: {"0.5": "0.125rem","1": "0.25rem","1.5": "0.375rem","2": "0.5rem","2.5": "0.625rem","3": "0.75rem","3.5": "0.875rem","4": "1rem","5": "1.25rem","6": "1.5rem","7": "1.75rem","8": "2rem","9": "2.25rem","10": "2.5rem","12": "3rem","14": "3.5rem","16": "4rem","20": "5rem","24": "6rem","28": "7rem","32": "8rem","36": "9rem","40": "10rem","44": "11rem","48": "12rem","52": "13rem","56": "14rem","60": "15rem","64": "16rem","72": "18rem","80": "20rem","96": "24rem",},};
tsx
export default {space: {"0.5": "0.125rem","1": "0.25rem","1.5": "0.375rem","2": "0.5rem","2.5": "0.625rem","3": "0.75rem","3.5": "0.875rem","4": "1rem","5": "1.25rem","6": "1.5rem","7": "1.75rem","8": "2rem","9": "2.25rem","10": "2.5rem","12": "3rem","14": "3.5rem","16": "4rem","20": "5rem","24": "6rem","28": "7rem","32": "8rem","36": "9rem","40": "10rem","44": "11rem","48": "12rem","52": "13rem","56": "14rem","60": "15rem","64": "16rem","72": "18rem","80": "20rem","96": "24rem",},};
Sizes
The sizes
key allows you to customize the global sizing of components you build for your project.
jsx
export default {sizes: {...space,max: "max-content",min: "min-content",full: "100%",screenW: "100vw",screenH: "100vh",xs: "20rem",sm: "24rem",md: "28rem",lg: "32rem",xl: "36rem","2xl": "42rem","3xl": "48rem","4xl": "56rem","5xl": "64rem","6xl": "72rem","7xl": "80rem","8xl": "90rem",},};
jsx
export default {sizes: {...space,max: "max-content",min: "min-content",full: "100%",screenW: "100vw",screenH: "100vh",xs: "20rem",sm: "24rem",md: "28rem",lg: "32rem",xl: "36rem","2xl": "42rem","3xl": "48rem","4xl": "56rem","5xl": "64rem","6xl": "72rem","7xl": "80rem","8xl": "90rem",},};
Radii
The radii
key allows you to customize the global radii (border radius) scale for your project.
tsx
export default {radii: {none: "0",xs: "0.125rem",sm: "0.25rem",md: "0.375rem",lg: "0.5rem",xl: "0.75rem","2xl": "1rem","3xl": "1.5rem",full: "9999px",},};
tsx
export default {radii: {none: "0",xs: "0.125rem",sm: "0.25rem",md: "0.375rem",lg: "0.5rem",xl: "0.75rem","2xl": "1rem","3xl": "1.5rem",full: "9999px",},};
Shadows
The shadows
key allows you to customize the global shadow scale for your project.
tsx
export default {shadows: {none: "0 0 #0000",xs: "0px 1px 2px rgb(16 24 40 / 5%)",sm: "0px 1px 3px rgb(16 24 40 / 10%), 0px 1px 2px rgb(16 24 40 / 6%)",md: "0px 4px 8px -2px rgb(16 24 40 / 10%), 0px 2px 4px -2px rgb(16 24 40 / 6%)",lg: "0px 12px 16px -4px rgb(16 24 40 / 8%), 0px 4px 6px -2px rgb(16 24 40 / 3%)",xl: "0px 20px 24px -4px rgb(16 24 40 / 8%), 0px 8px 8px -4px rgb(16 24 40 / 3%)","2xl": "0px 24px 48px -12px rgb(16 24 40 / 18%)","3xl": "0px 32px 64px -12px rgb(16 24 40 / 14%)",inner: "inset 0 2px 4px 0 rgb(0 0 0 / 0.06)",},};
tsx
export default {shadows: {none: "0 0 #0000",xs: "0px 1px 2px rgb(16 24 40 / 5%)",sm: "0px 1px 3px rgb(16 24 40 / 10%), 0px 1px 2px rgb(16 24 40 / 6%)",md: "0px 4px 8px -2px rgb(16 24 40 / 10%), 0px 2px 4px -2px rgb(16 24 40 / 6%)",lg: "0px 12px 16px -4px rgb(16 24 40 / 8%), 0px 4px 6px -2px rgb(16 24 40 / 3%)",xl: "0px 20px 24px -4px rgb(16 24 40 / 8%), 0px 8px 8px -4px rgb(16 24 40 / 3%)","2xl": "0px 24px 48px -12px rgb(16 24 40 / 18%)","3xl": "0px 32px 64px -12px rgb(16 24 40 / 14%)",inner: "inset 0 2px 4px 0 rgb(0 0 0 / 0.06)",},};
zIndices
The zIndices
key allows you to customize the global z-indices (z-index) scale for your project.
tsx
export default {zIndices: {hide: -1,base: 0,docked: 10,sticky: 1000,banner: 1100,overlay: 1200,modal: 1300,dropdown: 1400,popover: 1500,tooltip: 1600,skipLink: 1700,toast: 1800,},};
tsx
export default {zIndices: {hide: -1,base: 0,docked: 10,sticky: 1000,banner: 1100,overlay: 1200,modal: 1300,dropdown: 1400,popover: 1500,tooltip: 1600,skipLink: 1700,toast: 1800,},};