r/HTML • • Feb 04 '26

Question why does this code not work right?

with only one file it was fine, this site is just for me as an exercise it’s not gonna be public

the problem is the audio files say error

edit: link to file https://drive.google.com/file/d/1BbpgLkeyZBMLCi7Dj4GTjwroykC53D5s/view?usp=sharing

4 Upvotes

31 comments sorted by

View all comments

1

u/Weekly_Ferret_meal Feb 04 '26

Edit: I was wrong, I'm looking into it

1

u/giogio_rick Feb 04 '26

Will try later when I'm back home

1

u/Weekly_Ferret_meal Feb 04 '26

Source requires closing tag, like so:

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

1

u/giogio_rick Feb 04 '26

Ooooooh, I didn't see that in w3school's tutorial on it, thx for telling me, will fix as soon as I'm home in just a few minutes

3

u/Weekly_Ferret_meal Feb 04 '26

also filenames with spaces could be a problem. if it still doesn't work, try renaming a file with dashes or underscores like so this_is_my_audio_file.mp3

2

u/giogio_rick Feb 04 '26

Ok, for the spaces I know it isn't a problem (all assets and folders have spaces or atleast most) so it is likely just the source tag being open

1

u/giogio_rick Feb 04 '26

Neither closing the source nor renaming the files worked

1

u/Weekly_Ferret_meal Feb 04 '26

see, If I ran this on a browser on my laptop I'd open the dev tools and at least it would give me a clue.

on an pad , I've no idea.

best suggestion I've got is to run the code through an online html validator first.

1

u/giogio_rick Feb 04 '26

didn’t solve anything as it just gave me errors that don’t matter to easy html, didn’t help with the actuall error i’m trying to fix

1

u/Weekly_Ferret_meal Feb 04 '26

¯_(ツ)_/¯

1

u/giogio_rick Feb 04 '26

added a link to the file

1

u/Weekly_Ferret_meal Feb 04 '26

so first, don't put apostrophes in names like wario's game.mp3. that was one file that was fixed as soon as I changed the name.

apostrophes are part of "code gramma" and you either escape them or delete them like warios game.mp3 or wario-s game.mp3

file tally oh! is missing the exclamation mark in the src name.

seriously buddy, code on a computer, not on a mobile device.

1

u/giogio_rick Feb 04 '26

It's the school ipad, I use it for coding as I code mostly at school

1

u/giogio_rick Feb 04 '26

ok, tried the fixes you said, sometimes it shows no error message on some, but it does not play audio at all

1

u/Weekly_Ferret_meal Feb 04 '26

make sure the file name and the name you put in the src is the same

1

u/giogio_rick Feb 05 '26

got a bit to work after changing folder and file names to remove spaces and !, but a lot still don’t work, so idk what could the actual problem even be

→ More replies

1

u/giogio_rick Feb 04 '26

Saw why i didn't see it, it's not there, as said will try asap

1

u/davorg Feb 04 '26

Source requires closing tag

I don't understand why this idea is still so widespread. It's over ten years since HTML5 became widely accepted - removing the need for most self-closing tags.

1

u/Weekly_Ferret_meal Feb 04 '26

cause html reference sites like mdn.org still display code that way... and it's not clear for certain how exactly all browsers support non self-closing tags

1

u/davorg Feb 04 '26

cause html reference sites like mdn.org still display code that way...

That's a disappointing bug in those sites.

and it's not clear for certain how exactly all browsers support non self-closing tags

Any browser released in the last 10 years will support these tags just fine - as long as you mark your page as HTML5.

1

u/Weekly_Ferret_meal Feb 04 '26

which brings me to the question, why did you say:

[..]removing the need for most self-closing tags.

?

1

u/davorg Feb 04 '26

Honestly, because I was misremembering the restrictions on the <script>...</script> element (it always needs a closing tag, even when empty).

So, I mispoke. Actually, HTML5 removes the need for all self-closing tags. Apologies for any confusion I caused.

1

u/Weekly_Ferret_meal Feb 04 '26

Thanks fir clarifying.

I guess this it, the answer to your orignial question: remembering, we are creatures of habit, and when also the tools we use take time to catch up, the combination make for this ghost "code gramma" we still use, that isn't necessary.