Can I use non-SVG icons and detect dark/light mode in Sanity config?

7 replies
Last updated: Jan 28, 2026
Hey Everyone! I managed to set the icon with the defineConfig of the sanity.config.js file, which changes the icon in the upper left corner of Sanity Structure. But my questions are:1. Is the icon required to be an SVG? That's all I could get to work.
2. Can I access if a user switches between Dark and Light mode? If the icon is a white svg, then it can't be seen in Light mode. Same if it is a dark svg in dark mode.
AI Update

Great questions about customizing the Studio icon! Let me address both:

1. Icon Format - Not Limited to SVG

The icon property in defineConfig accepts React components, which gives you flexibility beyond just SVG. While SVG is common and recommended, you can use any React component that returns JSX.

Here's how it works:

import {defineConfig} from 'sanity'

// You can use a functional component that returns an SVG
const MyIcon = () => (
  <svg viewBox="0 0 100 100">
    {/* your svg paths */}
  </svg>
)

export default defineConfig({
  projectId: '<projectId>',
  dataset: 'production',
  icon: MyIcon, // Pass the component
  // ... other config
})

You can also use icons from @sanity/icons which are SVG-based React components that integrate well with Sanity's design system.

2. Detecting Dark/Light Mode for Theme-Aware Icons

Yes, you can detect the Studio's theme! The @sanity/ui package provides usePrefersDark(), which returns whether the user prefers dark mode based on the Sanity UI theme context (not just the system preference).

Since the icon property accepts a React component, you can create a theme-aware wrapper:

import {defineConfig} from 'sanity'
import {usePrefersDark} from '@sanity/ui'

const ThemeAwareIcon = () => {
  const prefersDark = usePrefersDark()
  
  return prefersDark ? (
    <svg viewBox="0 0 100 100">
      {/* Light-colored icon for dark mode */}
    </svg>
  ) : (
    <svg viewBox="0 0 100 100">
      {/* Dark-colored icon for light mode */}
    </svg>
  )
}

export default defineConfig({
  icon: ThemeAwareIcon,
  // ... other config
})

Even Simpler: Use currentColor

The easiest approach is to use currentColor in your SVG's fill or stroke attributes. This automatically adapts to Sanity's theme without any conditional logic:

const StudioIcon = () => (
  <svg viewBox="0 0 100 100" fill="currentColor">
    {/* your svg paths */}
  </svg>
)

export default defineConfig({
  icon: StudioIcon,
  // ... other config
})

With currentColor, Sanity UI's theming system automatically applies the appropriate color - your icon will be dark in light mode and light in dark mode, perfectly matching the Studio's appearance!

Show original thread
7 replies

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?