Documentation
Feedback
Guides

Header

The Header app is responsible for displaying a navigation bar fixed on a store's page upper side. Other blocks that are important for user navigation are found in the Header, for example the store's logo, the minicart, user login and search bar.

{"base64":"  ","img":{"width":2854,"height":1578,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":1340793,"url":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/vtex-store-header-0.png"}}

Configuration

  1. Add the store-header app to your theme's dependencies in manifest.json:

_10
dependencies: {
_10
"vtex.store-header": "2.x"
_10
}

Now, you are able to use all blocks exported by the store-header app. Check out the full list below:

Block nameDescription
header-layout.desktop
{"base64":"  ","img":{"width":69,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","length":923,"url":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/vtex-store-header-1.png"}}
Defines the Header layout for desktop device through header-row blocks.
header-layout.mobileDefines the Header layout for mobile device through header-row blocks.
header-row
{"base64":"  ","img":{"width":69,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","length":923,"url":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/vtex-store-header-2.png"}}
Create Header lines according to your store needs.
header-borderAdds a 1px margin to a Header row.
header-force-centerCentralizes its children blocks in a Header row.
header-spacerAdds spacing between blocks throughout a Header row.
  1. Declare the two header-layout blocks, allowing you to define how the Header should be displayed for both mobile and desktop:

_10
{
_10
"header": {
_10
"blocks": [
_10
"header-layout.desktop",
_10
"header-layout.mobile"
_10
]
_10
},

The Header does not need to be declared in a specific template of your theme, once the app is defined as default store interface element in the interfaces.json file. This means that Store Framework will reproduce the configurations defined in the file you just created for all store templates behind the scenes. If you want to apply different configurations to each store template, check the advanced configurations section below.

  1. Configure both header-layout.desktop and header-layout.mobile, declaring header-row to create Header lines according to your store needs.

_15
{
_15
"header": {
_15
"blocks": [
_15
"header-layout.desktop",
_15
"header-layout.mobile"
_15
]
_15
},
_15
"header-layout.desktop": {
_15
"children": [
_15
"header-row#1-desktop",
_15
"header-row#2-desktop",
_15
"header-row#3-desktop",
_15
"header-row#4-desktop"
_15
]
_15
},

In the example above, we configured 4 different levels for header-layout.desktop. It will thus be possible to replicate the Header displayed above sheltering the telemarketing functionalities (when activated), a notification, links to pages and every other blocks, such as Logo, Menu, etc. Remember that the number of header-rows should meet your business needs, determining how many Header lines you want to apply to your store.

  1. Configure each of the header-rows , applying props and declaring the desired store blocks for each line. To correctly structure your Header, you should check the app documentation for each of the desired blocks. The most commonly used are Logo, Minicart and Menu. In the example below, we will configure the header-row#1-desktop as Telemarketing:

_10
"header-row#1-desktop": {
_10
"children": [
_10
"telemarketing"
_10
],
_10
"props": {
_10
"fullWidth": true
_10
}
_10
},

  • header-row props:
Prop nameTypeDescriptionDefault value
zIndexNumberCSS property that controls the vertical stacking order of elements for overlapping.0
stickyBooleanWhether the Header margin should be fixed on the layout (true) or not (false)false
fullWidthBooleanWhether the Header should take the full width of the screen or nottrue
invertedBooleanWhether the row will use the base color (false) or the inverted base color (true) as defined in styles.json.false

Repeat step 4 for any other header-rows you may have in the header-layout.desktop. Remember to declare the desired blocks for each row, as we declared the Telemarketing block for the header-row#1-desktop, and properly configure all blocks using props. Once it is all finished, redo steps 3 and 4 to define your header-layout.mobile as well.

Three blocks can be added as header-row's children in order to customize your Header row layout: header-border, header-force-center and header-spacer.

  • header-border:

When declared, the header-border block adds a 1px margin to your store's Header.


_14
"header-row#2-desktop": {
_14
"children": [
_14
"header-border",
_14
"notification.bar#home"
_14
],
_14
"props": {
_14
"fullWidth": "true"
_14
}
_14
},
_14
"notification.bar#home": {
_14
"props": {
_14
"content": "SELECTED ITEMS ON SALE! CHECK IT OUT!"
_14
}
_14
},

Prop nameTypeDescriptionDefault value
stickyBooleanWhether the Header margin should be fixed in the layout or notfalse
  • header-force-center

When passed on, the header-force-center centralizes its children blocks in a Header row, for example:


_24
"header-row#4-desktop": {
_24
"props": {
_24
"blockClass": "main-header",
_24
"horizontalAlign": "center",
_24
"verticalAlign": "center",
_24
"preventHorizontalStretch": true,
_24
"preventVerticalStretch": true,
_24
"fullWidth": true
_24
},
_24
"children": ["header-force-center"]
_24
},
_24
"header-force-center": {
_24
"children":[
_24
"logo#desktop"
_24
]
_24
},
_24
"logo#desktop": {
_24
"props": {
_24
"title": "Logo",
_24
"href": "/",
_24
"url": "https://storecomponents.vteximg.com.br/arquivos/store-theme-logo.png",
_24
"width": "180"
_24
}
_24
},

{"base64":"  ","img":{"width":2850,"height":1576,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":1413481,"url":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/vtex-store-header-3.png"}}

  • header-spacer:

The header-spacer is tasked with adding spacing between blocks throughout the Header rows. For example:


_11
"header-row#3-desktop": {
_11
"children": [
_11
"vtex.menu@2.x:menu#websites",
_11
"header-spacer",
_11
"vtex.menu@2.x:menu#institutional"
_11
],
_11
"props": {
_11
"blockClass": "menu-link",
_11
"inverted": "true"
_11
}
_11
},

In practice, it will make all blocks declared before it position themselves to the left on the screen, whereas blocks that are declared after will be positioned to the right. Considering that the Menus were properly declared and configured in the theme code, we would have the following:

{"base64":"  ","img":{"width":2854,"height":1578,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":1341286,"url":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/vtex-store-header-4.png"}}

Advanced configuration

Automatic behind the scenes Header reproduction in every store template is only possible because it is defined as default store interface elements in the interfaces.json file from Store Theme.

This definition in interfaces.json enables Store Framework to identify the Header block declared just once in a blocks.jsonc file and reproduce it as default for all other templates.

To overwrite this automatic duplication in interfaces.json and use new configurations in different templates, refer to the step-by-step of the following recipe: Customizing the Header and Footer.

Customization

In order to apply CSS customizations in these and other blocks, follow the instructions given in the recipe on Using CSS Handles for store customization.

CSS Handles
container
leanMode
topMenuContainer
topMenuLogo
topMenuSearchBar
topMenuIcons
topMenuCollapsible
forceCenter
forceCenterInnerContainer
headerBorder
headerSpacer
headerStickyRow
headerRowContentContainer
Contributors
1
Photo of the contributor
+ 1 contributors
Was this helpful?
Yes
No
Suggest Edits (GitHub)
Contributors
1
Photo of the contributor
+ 1 contributors
On this page