duda
How To Add Audio to a Website

Kari Redfield • Apr 10, 2021

You’ve spent a lot of time mapping out a website for your small business customer. You’ve created a beautiful design with great photos, strategically deployed video — and you know what will make it better: the judicious use of sound. 


Sound can be an excellent way to stand out from the competition, help visitors remember information (you know all of those brand jingles in your head?), and build an emotional connection with a brand. Audio can even help with SEO rankings when used in the right way.


In short, audio, when used properly, can be an important component of a website experience. 

Here are several options for embedding audio on a website no matter which CMS platform or website builder you are using.

1. Audio hosting

An easy way to embed audio on a website is by using a sound hosting site, such as SoundCloud or Mixcloud. All you need to do is upload the file and receive an HTML embed code. Then copy and paste the embed code into the web page’s code or WYSIWYG site editor. This works for most CMS platforms and website builders.

2. Add an audio widget on Duda

Duda’s highly flexible website builder platform features numerous special tools that make it super easy to add audio to a website while retaining control over how it looks and functions. First, follow the steps above to add the audio file to a sound hosting site. Then, to add it to your web page, select the audio widget from the menu and add the link to the audio file.


With Duda, you can set the layout, play icon, and sizing options using the Design Editor.


To access the design editor:

  • Right-click the widget, and click Edit Design.
  • If you are using Mixcloud, you have layout, thumbnail display, light/dark color scheme, and sizing options.
  • If you are using SoundCloud, you have layout, play icon color, and sizing options.

3. Use HTML5

You can code audio into your website with the HTML5 <audio> element. When you code it in with the <audio> command and source attribute (src), the default is the browser’s audio default settings. Or you can define some elements of how the audio will play, such as telling it to autoplay or play muted so the user can choose to turn on sound.


Here’s an example from W3Schools:

 

<audio controls autoplay>

  <source src="horse.ogg" type="audio/ogg">

  <source src="horse.mp3" type="audio/mpeg">

Your browser does not support the audio element.

</audio>

Or muted:

 

<audio controls autoplay muted>

  <source src="horse.ogg" type="audio/ogg">

  <source src="horse.mp3" type="audio/mpeg">

Your browser does not support the audio element.

</audio>

The text between the audio tags will only show if the browser doesn’t support the HTML5 audio element.

4. Add JavaScript

If you’re going to code a file into a website instead of using the Duda widget, we recommend using JavaScript in addition to HTML5. JavaScript provides more control to ensure that the audio is integrated into the site and acts as intended. For instance, it allows you to display play, pause, mute, and other control buttons. Other examples: You can set the default to sound off and allow sound to come on with an easy-to-find controller (this is highly recommended because sound can be distracting), and your script can even be programmed to play certain sounds in response to the user’s actions, such as during a quiz.


Here’s an example for adding a play button and pause controller and script to HTML code:

 

<audio controls id="music">

<source src="mj.mp3" type="audio/mpeg">

Your browser does not support the audio element.

</audio>

 

<p>Click the buttons to play or pause the music.</p>

 

<button onclick="play()" type="button">Play </button>

<button onclick="pause()" type="button">Pause</button>

 

<script>

var myMusic= document.getElementById("music");

function play() {

myMusic.play();

}

 

function pause() {

myMusic.pause();

}

</script>


Embedding Audio on a Website

When you’re ready to take a website to the next level, add some sound elements to it. Duda makes embedding audio simple. And if you need even more control, you can use JavaScript.

WHEN TO ADD AUDIO TO A WEBSITE

Once you’ve understood how to add audio to a website, it’s incredibly important to know when to add audio to your site. There have been some horrific examples in the past, with audio often considered a bit of an afterthought proving more of a hindrance than a help.


However, audio can be hugely important in improving user experience these days, as long as you integrate it into your page at the right time. The best thing to do is consider the following:

Is it completely necessary?


First things first, do you need to add audio to a page? Consider if it is actually necessary and what effect it will have on your page. Does it boost the message or purpose you’re trying to achieve, and does it do so in the most effective manner?


You need to think about the search intent of the user and whether adding audio will add to that. For example, if someone is searching for a definition of what white labelling is, then they may just want a quick block of text to scan explaining. On the other hand, if someone is searching how
white labelling works, then a more in-depth piece of audio or video would match that intent more. A good way to understand this is by analysing the top performing pages on Google for a search term. If they are using audio, then there’s a good chance you should be too.



Consider the environment where people are browsing


Alongside the search intent, you should also consider where people are most likely to be browsing from, and on what device. Is your website more likely to be viewed in a quiet place such as an office, or is the page more likely to be viewed on the move via a mobile browser?


Understanding this can be another factor in when to use sound or not. By adding sound when it’s likely a browser is going to be somewhere quiet, may be more of an irritant for the user and others. Equally, if you believe that a browser will be using the audio in a busy space, for example an app in a food court, then you need to ensure that the sound will cut through the background noise in the environment. Understanding such context will help shape the audio you use and ultimately create a better user experience on your page.

Related Posts

Duda's widget picker overlaying a screen with HTML computer code
By Shawn Davis 21 Mar, 2024
Custom widgets empower your agency to create hyper-personalized, bespoke websites for clients—but only if you know how to code. Well, what if you didn’t have to?
Website animations
By Renana Dar 19 Mar, 2024
Website animations are one of the best ways to add interactivity and visual appeal to your client's website. This article provides a complete guide to website animations!
a picture of a woman with a quote on it
By Shawn Davis 11 Mar, 2024
Custom widgets give us the flexibility to offer immersive, branded experiences for our readers. Take a look at how we do it.
Show More
The word logo is written in pink on a black grid
By Renana Dar 28 Mar, 2024
Agency owners manage logo requests alongside website builds, navigating diverse types of logos. Learn to streamline design processes effectively with our comprehensive guide.
Duda for SaaS
By Shawn Davis 26 Mar, 2024
Small businesses are increasingly expecting specialized SaaS platforms to be one-stop-shops for all of their digital marketing needs — including websites.
Growth hacking for SMB SaaS
By Renana Dar 25 Mar, 2024
You have to get creative when selling to small and mid-sized businesses. That's where growth hacking comes in. Read the article for a complete list of growth hacks for SMB SaaS providers.
Show More

Latest Posts

Share by: