# Press "/" to Jump to the Search Box

> Lets visitors press the slash key on any page to put the cursor in the search box, a shortcut many people know from popular websites.

- Type: JavaScript
- Runs: Site-wide footer
- Category: [Search](https://wpide.com/library/category/search/)
- Tags: search, keyboard, accessibility
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/slash-key-focuses-search/

## Code

```javascript
document.addEventListener('keydown', function (event) {
    if (event.key !== '/' || event.ctrlKey || event.metaKey || event.altKey) {
        return;
    }

    var active = document.activeElement;

    if (active && (active.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(active.tagName))) {
        return;
    }

    var field = document.querySelector('input[type="search"], input[name="s"]');

    if (field) {
        event.preventDefault();
        field.focus();
        field.select();
    }
});
```

## Notes

The shortcut is ignored while the visitor is typing in a form field.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Press "/" to Jump to the Search Box" in its snippet library and add it in one click; or create a new JavaScript snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
