Search code examples
htmlstringsplit

String attribute values in multiple lines, HTML


Is it possible, in HTML to write something like:

<a href="bla bla bla bla\
        bla bla bla bla">....</a>

The idea is splitting a string attribute in different lines to improve readability.


Solution

  • Yes that's possible: https://stackoverflow.com/a/38874964/3135511 The secret is to use tab's instead of space As well as to use linebreaks

    <a href="
        bla 
        bla bla 
        bla bla bla 
        bla bla 
        bla
        ">....</a>
    Try out the code and hover over the .... And look for the link - it should read just like bla bla bla bla bla bla bla bla bla

    Background:

    • A space in a string will be escaped to %20 and so stay in, but white spaces as tab & line break will be discarded/filtered out.

      If you want them in a string write %09 for Tab and %0A%0D for some CR/LF windows line break. -> They are two bytes one Carrier Return char and some Line Feed char.