On this page
Complete header setup with navigation, search, and user actions.
ERB
Ruby
HTML
layout . build_header do | header |
header . build_left do | left |
left . build_icon_link ( "menu" , "#" , size: 24 )
left . build_dropdown ( skip_caret: true ) do | dropdown |
dropdown . build_button ( new_icon ( "layout-grid" ))
dropdown . build_menu do | menu |
menu . build_item ( "Dashboard" , "#" )
menu . build_item ( "Projects" , "#" )
menu . build_divider
menu . build_item ( "Settings" , "#" )
end
end
left . build_search_bar ( static_path: "search.json" )
end
header . build_right do | right |
right . build_text ( "Jane Doe" , class: "hidden lg:block" )
right . build_icon_link ( "info" , "#" )
right . build_icon_link ( "settings" , "#" )
right . build_dropdown ( align: "right" ) do | dropdown |
dropdown . build_button ( "Account" )
dropdown . build_menu do | menu |
menu . build_item ( "Profile" , "#" )
menu . build_item ( "Preferences" , "#" )
menu . build_divider
menu . build_item ( "Sign Out" , "#" )
end
end
end
end
<header class= "header" >
<div class= "header-left" >
<a class= "btn" href= "#" >
<svg xmlns= "http://www.w3.org/2000/svg" width= "24" height= "24" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><path d= "M4 5h16" ></path><path d= "M4 12h16" ></path><path d= "M4 19h16" ></path></svg>
</a>
<div class= "dropdown dropdown-down" data-controller= "dropdown" >
<button data-action= "click->dropdown#toggle" class= "btn" >
<svg xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><rect width= "7" height= "7" x= "3" y= "3" rx= "1" ></rect><rect width= "7" height= "7" x= "14" y= "3" rx= "1" ></rect><rect width= "7" height= "7" x= "14" y= "14" rx= "1" ></rect><rect width= "7" height= "7" x= "3" y= "14" rx= "1" ></rect></svg>
</button>
<div class= "dropdown-menu" data-dropdown-target= "menu" data-action= "click->dropdown#close" >
<a class= "dropdown-menu-item" href= "#" > Dashboard</a>
<a class= "dropdown-menu-item" href= "#" > Projects</a>
<hr class= "dropdown-divider" >
<a class= "dropdown-menu-item" href= "#" > Settings</a>
</div>
</div>
<div class= "header-search" data-controller= "search-bar" data-search-bar-static-path-value= "search.json" >
<span class= "block md:hidden" >
<button type= "button" class= "btn" data-action= "click->search-bar#toggleDropdown" title= "Search" >
<svg xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><path d= "m21 21-4.34-4.34" ></path><circle cx= "11" cy= "11" r= "8" ></circle></svg>
</button>
</span>
<div class= "header-search-bar hidden md:flex" >
<svg xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><path d= "m21 21-4.34-4.34" ></path><circle cx= "11" cy= "11" r= "8" ></circle></svg>
<input type= "text" placeholder= "Search" data-search-bar-target= "desktopInput" data-action= "input->search-bar#onInput focus->search-bar#onFocus" >
<span data-search-bar-target= "shortcutHint" class= "search-bar-shortcut-hint" > [Option+S]</span>
<button data-search-bar-target= "desktopClearButton" data-action= "click->search-bar#closeDropdown" class= "search-bar-close-btn hidden" title= "Close search results" >
<svg xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><path d= "M18 6 6 18" ></path><path d= "m6 6 12 12" ></path></svg>
</button>
</div>
<div data-search-bar-target= "dropdown" class= "search-bar-dropdown hidden" >
<div class= "flex items-center justify-between gap-3 md:hidden p-4" >
<div class= "header-search-bar flex flex-1" >
<input type= "text" placeholder= "Search" data-search-bar-target= "mobileInput" data-action= "input->search-bar#onInput focus->search-bar#onFocus" class= "search-bar-modal-input" >
<button data-search-bar-target= "mobileClearButton" data-action= "click->search-bar#clearSearch" class= "search-bar-close-btn" title= "Clear search results" >
<svg xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><path d= "M18 6 6 18" ></path><path d= "m6 6 12 12" ></path></svg>
</button>
</div>
<button data-action= "click->search-bar#closeDropdown" class= "btn" title= "Cancel search" > Cancel</button>
</div>
<div data-search-bar-target= "error" class= "search-bar-error hidden" > Error occurred while searching</div>
<div data-search-bar-target= "results" ></div>
<div data-search-bar-target= "emptyResults" class= "search-bar-no-results hidden" >
<span> No results found</span>
</div>
<div data-search-bar-target= "loading" class= "search-bar-loading hidden" >
<svg class= "spin" xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><path d= "M12 2v4" ></path><path d= "m16.2 7.8 2.9-2.9" ></path><path d= "M18 12h4" ></path><path d= "m16.2 16.2 2.9 2.9" ></path><path d= "M12 18v4" ></path><path d= "m4.9 19.1 2.9-2.9" ></path><path d= "M2 12h4" ></path><path d= "m4.9 4.9 2.9 2.9" ></path></svg>
Searching...
</div>
</div>
<template data-search-bar-target= "resultTemplate" >
<a class= "search-bar-result-item" data-result-url= "" data-result-title= "" data-result-description= "" >
<div class= "search-result-title" ></div>
<div class= "search-result-description" ></div>
</a>
</template>
</div>
</div>
<div class= "header-right" >
<span class= "header-text hidden lg:block" > Jane Doe</span>
<a class= "btn" href= "#" >
<svg xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><circle cx= "12" cy= "12" r= "10" ></circle><path d= "M12 16v-4" ></path><path d= "M12 8h.01" ></path></svg>
</a>
<a class= "btn" href= "#" >
<svg xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><path d= "M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915" ></path><circle cx= "12" cy= "12" r= "3" ></circle></svg>
</a>
<div class= "dropdown dropdown-right dropdown-down" data-controller= "dropdown" >
<button data-action= "click->dropdown#toggle" class= "btn" >
Account
<svg class= "dropdown-arrow" xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><path d= "m6 9 6 6 6-6" ></path></svg>
</button>
<div class= "dropdown-menu" data-dropdown-target= "menu" data-action= "click->dropdown#close" >
<a class= "dropdown-menu-item" href= "#" > Profile</a>
<a class= "dropdown-menu-item" href= "#" > Preferences</a>
<hr class= "dropdown-divider" >
<a class= "dropdown-menu-item" href= "#" > Sign Out</a>
</div>
</div>
</div>
</header>
The header is divided into left and right sections. Use build_left and build_right to position items.
ERB
Ruby
HTML
layout . build_header do | header |
header . build_left do | left |
left . build_text ( "Left side content" )
end
header . build_right do | right |
right . build_text ( "Right side content" )
end
end
<header class= "header" >
<div class= "header-left" >
<span class= "header-text" > Left side content</span>
</div>
<div class= "header-right" >
<span class= "header-text" > Right side content</span>
</div>
</header>
Add a search input with keyboard shortcut hints and AJAX results dropdown.
ERB
Ruby
HTML
layout . build_header do | header |
header . build_left do | left |
left . build_search_bar ( static_path: "/search.json" )
end
end
<header class= "header" >
<div class= "header-left" >
<div class= "header-search" data-controller= "search-bar" data-search-bar-static-path-value= "/search.json" >
<span class= "block md:hidden" >
<button type= "button" class= "btn" data-action= "click->search-bar#toggleDropdown" title= "Search" >
<svg xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><path d= "m21 21-4.34-4.34" ></path><circle cx= "11" cy= "11" r= "8" ></circle></svg>
</button>
</span>
<div class= "header-search-bar hidden md:flex" >
<svg xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><path d= "m21 21-4.34-4.34" ></path><circle cx= "11" cy= "11" r= "8" ></circle></svg>
<input type= "text" placeholder= "Search" data-search-bar-target= "desktopInput" data-action= "input->search-bar#onInput focus->search-bar#onFocus" >
<span data-search-bar-target= "shortcutHint" class= "search-bar-shortcut-hint" > [Option+S]</span>
<button data-search-bar-target= "desktopClearButton" data-action= "click->search-bar#closeDropdown" class= "search-bar-close-btn hidden" title= "Close search results" >
<svg xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><path d= "M18 6 6 18" ></path><path d= "m6 6 12 12" ></path></svg>
</button>
</div>
<div data-search-bar-target= "dropdown" class= "search-bar-dropdown hidden" >
<div class= "flex items-center justify-between gap-3 md:hidden p-4" >
<div class= "header-search-bar flex flex-1" >
<input type= "text" placeholder= "Search" data-search-bar-target= "mobileInput" data-action= "input->search-bar#onInput focus->search-bar#onFocus" class= "search-bar-modal-input" >
<button data-search-bar-target= "mobileClearButton" data-action= "click->search-bar#clearSearch" class= "search-bar-close-btn" title= "Clear search results" >
<svg xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><path d= "M18 6 6 18" ></path><path d= "m6 6 12 12" ></path></svg>
</button>
</div>
<button data-action= "click->search-bar#closeDropdown" class= "btn" title= "Cancel search" > Cancel</button>
</div>
<div data-search-bar-target= "error" class= "search-bar-error hidden" > Error occurred while searching</div>
<div data-search-bar-target= "results" ></div>
<div data-search-bar-target= "emptyResults" class= "search-bar-no-results hidden" >
<span> No results found</span>
</div>
<div data-search-bar-target= "loading" class= "search-bar-loading hidden" >
<svg class= "spin" xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><path d= "M12 2v4" ></path><path d= "m16.2 7.8 2.9-2.9" ></path><path d= "M18 12h4" ></path><path d= "m16.2 16.2 2.9 2.9" ></path><path d= "M12 18v4" ></path><path d= "m4.9 19.1 2.9-2.9" ></path><path d= "M2 12h4" ></path><path d= "m4.9 4.9 2.9 2.9" ></path></svg>
Searching...
</div>
</div>
<template data-search-bar-target= "resultTemplate" >
<a class= "search-bar-result-item" data-result-url= "" data-result-title= "" data-result-description= "" >
<div class= "search-result-title" ></div>
<div class= "search-result-description" ></div>
</a>
</template>
</div>
</div>
</header>
Add dropdown menus for navigation or user actions. Supports nested menu items and dividers.
ERB
Ruby
HTML
layout . build_header do | header |
header . build_left do | left |
left . build_dropdown ( skip_caret: true ) do | dropdown |
dropdown . build_button ( new_icon ( "layout-grid" ))
dropdown . build_menu do | menu |
menu . build_item ( "Dashboard" , "#" )
menu . build_item ( "Settings" , "#" )
menu . build_divider
menu . build_item ( "Logout" , "#" )
end
end
end
header . build_right do | right |
right . build_dropdown do | dropdown |
dropdown . build_button ( "Account" )
dropdown . build_menu do | menu |
menu . build_item ( "Profile" , "#" )
menu . build_item ( "Sign Out" , "#" )
end
end
end
end
<header class= "header" >
<div class= "header-left" >
<div class= "dropdown dropdown-down" data-controller= "dropdown" >
<button data-action= "click->dropdown#toggle" class= "btn" >
<svg xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><rect width= "7" height= "7" x= "3" y= "3" rx= "1" ></rect><rect width= "7" height= "7" x= "14" y= "3" rx= "1" ></rect><rect width= "7" height= "7" x= "14" y= "14" rx= "1" ></rect><rect width= "7" height= "7" x= "3" y= "14" rx= "1" ></rect></svg>
</button>
<div class= "dropdown-menu" data-dropdown-target= "menu" data-action= "click->dropdown#close" >
<a class= "dropdown-menu-item" href= "#" > Dashboard</a>
<a class= "dropdown-menu-item" href= "#" > Settings</a>
<hr class= "dropdown-divider" >
<a class= "dropdown-menu-item" href= "#" > Logout</a>
</div>
</div>
</div>
<div class= "header-right" >
<div class= "dropdown dropdown-down" data-controller= "dropdown" >
<button data-action= "click->dropdown#toggle" class= "btn" >
Account
<svg class= "dropdown-arrow" xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><path d= "m6 9 6 6 6-6" ></path></svg>
</button>
<div class= "dropdown-menu" data-dropdown-target= "menu" data-action= "click->dropdown#close" >
<a class= "dropdown-menu-item" href= "#" > Profile</a>
<a class= "dropdown-menu-item" href= "#" > Sign Out</a>
</div>
</div>
</div>
</header>
Display plain text in the header, useful for showing the current user's name or status.
ERB
Ruby
HTML
layout . build_header do | header |
header . build_left do | left |
left . build_text ( "Welcome, Jane" )
end
header . build_right do | right |
right . build_text ( "username" )
end
end
<header class= "header" >
<div class= "header-left" >
<span class= "header-text" > Welcome, Jane</span>
</div>
<div class= "header-right" >
<span class= "header-text" > username</span>
</div>
</header>
Add text-based navigation links that render as styled buttons.
ERB
Ruby
HTML
layout . build_header do | header |
header . build_left do | left |
left . build_text_link ( "Documentation" , "#" )
left . build_text_link ( "API" , "#" )
left . build_text_link ( "Pricing" , "#" )
end
end
<header class= "header" >
<div class= "header-left" >
<a class= "btn" href= "#" > Documentation</a>
<a class= "btn" href= "#" > API</a>
<a class= "btn" href= "#" > Pricing</a>
</div>
</header>
Add icon-only navigation links, perfect for compact actions like settings or notifications.
ERB
Ruby
HTML
layout . build_header do | header |
header . build_right do | right |
right . build_icon_link ( "info" , "#" )
right . build_icon_link ( "settings" , "#" )
right . build_icon_link ( "circle-question-mark" , "#" )
end
end
<header class= "header" >
<div class= "header-right" >
<a class= "btn" href= "#" >
<svg xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><circle cx= "12" cy= "12" r= "10" ></circle><path d= "M12 16v-4" ></path><path d= "M12 8h.01" ></path></svg>
</a>
<a class= "btn" href= "#" >
<svg xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><path d= "M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915" ></path><circle cx= "12" cy= "12" r= "3" ></circle></svg>
</a>
<a class= "btn" href= "#" >
<svg xmlns= "http://www.w3.org/2000/svg" width= "16" height= "16" viewbox= "0 0 24 24" fill= "none" stroke= "currentColor" stroke-width= "2" stroke-linecap= "round" stroke-linejoin= "round" ><circle cx= "12" cy= "12" r= "10" ></circle><path d= "M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3" ></path><path d= "M12 17h.01" ></path></svg>
</a>
</div>
</header>