Search code examples
css

How to insert a line break before an element using CSS


I feel like I saw a way, using the CSS content property, to insert a line break tag before an element. Obviously this doesn't work:

#restart:before { content: '<br/>'; }

But how do you do this?


Solution

  • It's possible using the \A escape sequence in the psuedo-element generated content. Read more in the CSS2 spec.

    #restart:before { content: '\A'; }
    

    You may also need to add white-space:pre; to #restart.

    Note: \A denotes the hex value of a character, in this case 0x0A (dec 10) which is the linefeed character, designating the end of a line.