Style the studio by over-riding custom variables

2 replies
Last updated: Feb 4, 2021
πŸ‘‹ Hey all - hoping this is fairly simple ask but it has me confused. I'm working on customising the studio i've put in my logo and adjusted the colours etc.. - The logo size is pushing the navbar container height up (and i'd like to keep the logo at this set size as it looks best) I just want to align the other navbar items (buttons, search etc...) into the middle of the container using align-items: center. It's not obvious how i'd be able to do or override these styles? Help!
AI Update

I understand the frustration! Unfortunately, Sanity Studio doesn't provide a straightforward way to adjust the internal alignment of navbar items when you have a larger logo.

The Challenge

The studio.components.navbar property in your config allows you to replace the entire navbar component, but when you use renderDefault(props), it renders the complete default navbar as a single unit. You can't easily access or style the internal flex container that holds the individual navbar items (search, buttons, etc.) through the standard configuration API.

Practical Solutions

Here are your realistic options:

1. Adjust Your Logo to Fit the Navbar (Recommended)

The most maintainable approach is to constrain your logo to work within the navbar's default height constraints:

import {defineConfig} from 'sanity'

export default defineConfig({
  // ...
  icon: () => (
    <img 
      src="/your-logo.svg" 
      alt="Logo" 
      style={{
        maxHeight: '1.75rem', // Adjust to fit default navbar height
        width: 'auto',
        display: 'block'
      }} 
    />
  ),
})

This keeps your logo at an optimal size while preventing it from pushing the navbar height up.

2. Custom CSS Override (Use with Caution)

If you absolutely need to keep your larger logo and center the navbar items, you can inject custom CSS. However, this approach is fragile and may break with Studio updates since you're targeting internal class names:

import {defineConfig} from 'sanity'

export default defineConfig({
  // ...
  studio: {
    components: {
      layout: (props) => {
        // Inject custom styles on mount
        if (typeof document !== 'undefined') {
          const styleId = 'custom-navbar-alignment'
          if (!document.getElementById(styleId)) {
            const style = document.createElement('style')
            style.id = styleId
            style.innerHTML = `
              [data-ui="Navbar"] > div {
                align-items: center !important;
              }
            `
            document.head.appendChild(style)
          }
        }
        return props.renderDefault(props)
      }
    }
  }
})

Note: This targets Sanity's internal DOM structure using [data-ui="Navbar"], which isn't officially documented and could change. Use !important to override internal styles.

3. Build a Completely Custom Navbar

You can replace the navbar entirely without using renderDefault, but this means rebuilding all navbar functionality yourself (search bar, user menu, presence indicators, project switcher, etc.). This is a significant undertaking and requires deep knowledge of Sanity UI components.

My Recommendation

Go with option #1 - adjust your logo size. The Studio's navbar is designed with specific ergonomic constraints, and working within those constraints is the most reliable long-term approach. If your logo looks best at a larger size, consider using it in other parts of your application while keeping a scaled-down version for the navbar.

If you really need complete control over the Studio chrome, you might explore embedding the Studio as a component within a larger custom application where you control the surrounding UI, but that's a much larger architectural decision.

you can add custom styles (https://www.sanity.io/docs/styling#overriding-variables-d7f9b5cc2adb ), maybe something like this?

:global([class*="Navbar_root_"]) {
  align-items: center;
}
πŸ™Œ thanks
user B

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?