How can I use arrow keys to change slides in Webflow using key codes?

TL;DR
  • Assign a unique ID or class (e.g., main-slider) to the Webflow Slider.  
  • Add custom JavaScript before the </body> tag that listens for keydown events, checks for key codes 37 (left) and 39 (right), and triggers .w-slider-arrow-left or .w-slider-arrow-right accordingly.

You can use custom JavaScript with key codes to enable slide navigation using the left (←) and right (→) arrow keys in a Webflow Slider.

​

1. Identify the Key Codes

​

  • Left Arrow Key has a key code of 37.
  • Right Arrow Key has a key code of 39.

​

2. Target the Webflow Slider

​

  • In your Webflow project, give the Slider component a unique ID or class name (e.g., main-slider).
  • This is necessary to programmatically control it via JavaScript.

​

3. Add Custom Code to Control Slides

​

  • In Page Settings > Before </body> tag, add this within a <script> block (avoid including <script> here per guidelines, just refer to the location).

​

  • Recommended logic:
  • Detect keydown event.
  • Check if key code matches left (37) or right (39).
  • Use Webflow’s built-in jQuery slider controls: 
    • $('#main-slider').slick('slickNext') or 
    • use Webflow's built-in methods like .trigger('tap') on the native arrow buttons.

​

  • Use Webflow’s structure:
  • Select .w-slider-arrow-left and .w-slider-arrow-right inside your slider container.
  • Example logic:
    • For left key (37): $('#main-slider .w-slider-arrow-left').trigger('tap')
    • For right key (39): $('#main-slider .w-slider-arrow-right').trigger('tap')

​

4. Full Logic (JavaScript Overview)

​

  • In basic terms, the JS should:
  • Listen for keydown events
  • Match the key code
  • Trigger the corresponding slider arrow button (.w-slider-arrow-left or .w-slider-arrow-right)

​

5. Publish and Test

​

  • Publish your site to a staging or live domain.
  • Use your keyboard’s arrow keys to ensure slides move accordingly.

​

Summary

​

To enable arrow key slide navigation in Webflow, detect key codes 37 and 39, then trigger the native slider arrows (.w-slider-arrow-left and .w-slider-arrow-right) using custom JavaScript placed before the </body> tag.

Rate this answer

Other Webflow Questions