Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Promo Code Banner Navbar Block for React

A two-row navbar for a stationery subscription: a promo row with a discount code and a Copy button that folds away when dismissed, above a standard bar with four links, Sign in and a Shine Button.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

A two-row navbar for React with Base UI. Above the bar sits a promo row for Brightbarn, a stationery subscription: "Spring sale: 20% off annual plans", the code SPRING20 in an outline badge and a Copy button that puts the code on the clipboard and says so. It's the top bar banner's strip: a faint tint of the theme's muted colour under the spine's top rule, with a ghost button at the end that folds the row's height away (at once under reduced motion), moves focus on to the bar's wordmark and says "Promotion dismissed." in a polite status. Under it the standard bar has the wordmark, Plans, Notebooks, Gifts and Journal, Sign in and a Subscribe Shine Button; on a phone the links and both actions are in a sheet from the top. Open, the block is about 108 pixels high (two lines of promo on a phone: 124); closed, it's one bar. It's built from Copy Button, Badge, Navigation Menu, Sheet, Shine Button, Button and Guides. For shops and subscriptions with a code to hand out.

FAQ

How do I change the offer and the code?

Edit PROMO at the top: the lead words (lead), the offer, and the code that is shown in the badge and copied. Keep the sentence short (about 30 characters): it stays on one line on a desktop and the code and Copy button wrap beneath it on a phone.

How does Copy say what happened?

Copy writes the code to the clipboard and swaps its icon for a check for three seconds. The result is also spoken: a single polite status in the row says "Code SPRING20 copied." or, if the clipboard refuses (a page not served over HTTPS), "Couldn't copy. The code is SPRING20." The code stays selectable text in the badge.

How does the row fold away, and where does focus go?

The row sits in a one-row CSS grid: dismissing it eases the row from 1fr to 0fr, fading as it goes, and its padding lives inside the fold so it folds to nothing; its top rule then lies on the bar's own. No height is measured in script. The row becomes inert and drops its "Promotion" label so no empty landmark is left. Focus goes where Tab would have taken it, to the bar's wordmark, instead of being lost with the button. With reduced motion it closes at once.

How do I keep the row closed after a visitor dismisses it?

Remember it under a key for this offer, such as dismissed-spring-sale, in a cookie the server reads, and leave the row out of the page. Reading localStorage from an effect would show the row and then fold it away on every visit, moving the whole page under it. The block keeps the choice for the current page only.

How does it work on a phone?

The promo wraps to two lines (the code and Copy on the second) and stays under 165 pixels with the bar at 320. Below md the links and Sign in fold into a menu button that opens a sheet from the top, its header lined up with the bar (the wordmark where it was, the close button where the menu button was); Subscribe stays on the bar down to 368 pixels and is in the sheet below that.

  • Pro

    A slim announcement strip for a writing app's release: one centred line with the version, the news and an underlined link, and a ghost button that folds the strip away.

  • Pro

    A one-bar marketing navbar for a product roadmap tool: a wordmark, a Product menu of four areas with icons and one-line descriptions, plain links with the current page marked, Sign in and a Shine Button, and a sheet with the same links on phones.

  • Pro

    A one-bar navbar for a design-handoff tool with its news inside the row: an Announcement pill between the links and the actions, moved to the top of the sheet on small screens.

  • Pro

    Trial Banner Billing

    Upsell and retention

    A trial-ending banner for an app's shell: days left in the heading, a progress bar, what changes when the trial ends, an Add payment method action and a dismiss that remembers.

  • Pro

    A top bar for a developer tool whose long message stops at an ellipsis, with a More button that opens the whole text and a ghost close that folds the strip away.

  • Pro

    Reverse Split News List Hero

    Updates and timelines

    A reverse split hero on drafting lines for a team docs workspace: a greyscale product illustration beside an announcement pill, the headline, a ruled list of the latest updates as links, a Shine Button and a second action.