Play an audio file after a click in Webflow

Tutorial
3 min
Published on Mar 20, 2023
Updated on
Webflow logo with a man humming and music icons
Use AI to summarize this article
Key points

In today's Webflow tutorial, we will learn how to play audio when clicking on a specific element on a page of our website using code.

Step 1: Host Your File Online

The first step of this tutorial is to find an online hosting service for your audio file (mp3, avi, etc.). You can use Dropbox (even the free version) to upload your audio to your space.

dropbox audio file

Step 2: Add Audio in Webflow

2.1 Add Code

Next, go to your Webflow project and specifically to the page where you want the audio to play upon clicking.

In the page settings, within the custom code "Inside <!-- fs-richtext-ignore --><head> tag", you will insert the following code:

<audio id ="audio" src="lien-audio"></audio>
audio source code webflow

2.2 Replace the Source with Your Audio Link

Instead of audio-link in the source, you will paste the link to your hosted file.

If you are using Dropbox, simply go to the file settings and click on "Copy Link".

copy link audio file dropbox

Additionally, for a Dropbox file, you will need to replace "?dl=0" at the end of the URL with "?dl=1".

dropbox audio link ?dl=0
dropbox audio link ?dl=1

Step 3: Add Code to Play Audio on Click

Once you have inserted the audio source, we will add a JavaScript code that will allow us to play our audio when clicking on a specific element in our project.

3.1 Insert New Code

Now, copy and paste the following code into the custom code "Inside <!-- fs-richtext-ignore --><head> tag" and customize it:

<script>
window.onload=function(){
  const audioElement = document.getElementById('audio');
  const playAudio = document.querySelector('.classe-element-cliquable');
  playAudio.addEventListener('click', function() {
    audioElement.play();
  });
}
</script>

3.2 Customize the Code

According to your project, you must replace '.clickable-element-class' with the name of the class of the element that will act as a trigger for the audio. In our example, it will be '.estimator_content-top-image'.

Webflow element class image

Next, you can rename the constants (audioElement and playAudio) if you wish, but remember to change the name every time it appears in the code (twice for the first constant and twice for the second constant).

In our example, we changed the name of the second constant (playAudio to hellodigidop).

code to play audio on element click in webflow

Step 4: Publish Your Webflow Project

Of course, the code does not execute directly in the designer, so you'll need to publish your project and test it on the live version to hear the audio when clicking your element.

There you go, you can now add some life to your website with custom audio files that will play upon clicking certain elements. If you want to stand out from your competitors, Digidop offers you a Webflow site that converts with a wow factor.

Thibaut Legrand
Thibaut Legrand
Cofounder at Vydera & Technical Solutions Architect

Suggested articles

Promotional graphic for Webflow Conf 2026 featuring Lucas Clairet as a finalist for the Developer of the Year award. His black-and-white portrait is set against a vibrant abstract background with blue, orange, green, and pink textures, creating a bold, modern visual identity. The vertical Webflow Conf ’26 branding appears on the left, while his name and the title “Finalist – Developer of the Year” are displayed in a black panel.
News
Webflow

Lucas Clairet named Finalist for Webflow Awards 2026 – Developer of the Year

Lucas Clairet named Finalist for Webflow Awards 2026 – Developer of the Year
Overview of Webflow AEO combining AI recommendations, analytics, prompt tracking, and SEO optimizations within a single interface.
Documentation
Webflow

Webflow AEO: Answer Engine Optimization built directly into Webflow

Webflow AEO: Answer Engine Optimization built directly into Webflow
Website redesign brief document titled "Brief" on a dark blue background
Documentation

Brief, specifications and RFP: scoping your website redesign and choosing the right agency

Brief, specifications and RFP: scoping your website redesign and choosing the right agency
Every great website  
starts with a conversation
Abstract composition of black and gold metallic ribbons with elegant light reflections and smooth gradients. A premium background conveying luxury, modernity, and innovation.