CDLee CDLee - 3 months ago 18
HTML Question

Is there a way to write a really long HTML attribute value in more than one line?

Trying to keep my HTML readable. Often my HTML attribute has a really long URL for it's value


<img src=""
data-alt-src="" />

While these aren't too long, sometimes the URL can be much more extensive. These long lines look terrible in my editor (using WebStorm). It doesn't work if I cut the long URL into multiple lines. I use "+" to concatinate strings in Java or other programming languages, but I have no idea what to do in HTML.

I feel like this is a stupid question, but I had no luck searching for a simple answer. Could you guys help me out?

Thank you!


Actually the code should still work even if you cut the line in half. HTML will view the entire bit of code as one line until it hits the line break, the ">". If your editor is giving you an error on the broken line try running it and if it doesn't work still then there might be another issue. Just make sure that you don't put a space in between it. So for example

<img src="

voter-registration-day-reminder-5701453076234240-hp2x.gif" />

Would work but

<img src="

  /us-voter-registration-day-reminder-5701453076234240-hp2x.gif" />

Would not.