` element. If you have a hoverable topbar, it will close itself on click by default, but this behavior can be prevented by setting `data-options="dropdown_autoclose: false"`. [See an example below](#clickable).
#### HTML
{{#markdown}}
```html
{{> examples_topbar_default}}
```
{{/markdown}}
***
### Positioning the Bar
The top bar is built with a single `nav` element with a class of `top-bar`. It will take on full-browser width by default. To make the top bar stay fixed as you scroll, wrap it in `div class="fixed"`. If you want your navigation to be set to your grid width, wrap it in `div class="contain-to-grid"`. You may use `fixed` and `contain-to-grid` together in the wrapping div (`div class="contain-to-grid fixed`).
Fixed Navigation
{{#markdown}}
```html
...
```
{{/markdown}}
Contain to Grid
{{#markdown}}
```html
...
```
{{/markdown}}
***
### Sticky Top Bar
You may also wrap your top bar in `div class="sticky"` and put it anywhere within your markup. When the navigation hits the top of the browser, it will act like the fixed top bar and stick to the top as users continue to scroll. **Note:** If you are using SCSS, you can control the default `sticky` class by adjusting the `$topbar-sticky-class` variable. **Make sure the JS variable for `sticky_class` matches whatever class you use in the variable.**
{{> examples_topbar_sticky}}
You can also add `sticky_on` to your `data-options` attribute to allow your sticky bar to work on `small`, `medium`, or `large` when the page loads. This works in conjunction with the sticky class wrapper to target sticky for small, medium, or large. It will be sticky on all screen sizes by default.
Additionally, you can pass in an array to specify sticky on multiple sizes. For example, `data-options="sticky_on: [small,large]"` will be sticky on small and large, but NOT medium.
{{#markdown}}
```html
...
```
{{/markdown}}
***
### Clickable Top Bar
You can now make the top bar clickable by adding a data-attribute to the nav element. Here's an example:
{{> examples_topbar_clickable}}
{{#markdown}}
```html
```
{{/markdown}}
***
### Mobile Parent Links
Foundation will show the parent link on mobile navigation. A helpful way for mobile users navigate your site. Don't want them? Simply change the settings in the topbar.js file.
{{> examples_topbar_mobile_parent_links}}
***
### Built-in Components
Several common elements have been supported by default, each one of these elements gets added to either the `ul.right` or `ul.left` unordered lists within your Top Bar navigation.
##### Search Bar
{{#markdown}}
```html
```
{{/markdown}}
##### Divider
Separate your buttons with dividers
{{#markdown}}
```html
```
{{/markdown}}
##### Button
Add buttons
{{#markdown}}
```html
Get Lucky
```
{{/markdown}}
##### Label
Separate sections of your dropdowns with labels
{{#markdown}}
```html
Dropdown Level 1 Label
```
{{/markdown}}
***
### Remove the Title
If you want a bar that doesn't include a title, just take out the content within the list item, like so:
{{#markdown}}
```html
```
{{/markdown}}
***
## Accessibility
The top bar is a complex component with a lot of different features. However, it's still fully keyboard and screen reader accessible. The main thing you need to add if upgrading from an older version of Foundation is the attribute `role="navigation"` to the top bar container. Additionally, if your page uses top bar and off-canvas navigation, add the attribute `aria-hidden="true"` to one of them—otherwise, the user's device will tab through (and possibly read) both of them before reaching any content.
***
### Available SCSS Variables
We do include SCSS variable to help you control some of the styles for the top bar. Overall the styles are written mobile first, so they are much easier to override than the previous iteration of the top bar.
{{> examples_topbar_variables}}
**Note:** `rem-calc();` is a function we wrote to convert `px` to `rem`. It is included in **_variables.scss**.
***
### Using the Javascript
Before you can use the top bar you'll want to verify that jQuery and `foundation.js` are available on your page. You can refer to the [Javascript documentation](../javascript.html) on setting that up.
Just add `foundation.topbar.js` AFTER the `foundation.js` file. Your markup should look something like this:
{{#markdown}}
```html
...
```
{{/markdown}}
Required Foundation Library: `foundation.topbar.js`
##### Optional Javascript Configuration
Top bar supports `data-options` configuration.
{{#markdown}}
```js
{
sticky_class : 'sticky',
custom_back_text: true, // Set this to false and it will pull the top level link name as the back text
back_text: 'Back', // Define what you want your custom back text to be if custom_back_text: true
is_hover: true,
mobile_show_parent_link: false, // will copy parent links into dropdowns for mobile navigation
scrolltop : true // jump to top when sticky nav menu toggle is clicked
}
```
{{/markdown}}
***
### Adding New Top-bar After Page Load
If you add new content after the page has been loaded, you will need to reinitialize the Foundation JavaScript by running the following:
{{#markdown}}
```javascript
$(document).foundation();
```
{{/markdown}}
Reflow will make Foundation check the DOM for any elements and re-apply any listeners to them.
{{#markdown}}
```javascript
$(document).foundation('topbar', 'reflow');
```
{{/markdown}}
***
### Sass Errors?
If the default "foundation" import was commented out, then make sure you import this file:
SCSS
```scss
@import "foundation/components/top-bar";
```