Line breaks in ASP--source code vs. HTML

Search

 by Remas Wojciechowski

There seems to be a good deal of confusion when it comes to using line breaks in ASP. This article tries to clarify the line-breaks problem.

HTML is CRLF insensitive

As a rule, line break is connoted with the CR-LF sequence--Carriage Return and Line Feed. However, web browsers simply ignore (in most cases) CRLF. Therefore, if you want to achieve a line break, you have to use the <br> tag.

Line breaks in the ASP code won't be visible in the resulting HTML page

If you execute the following code:

Response.Write("A line")
Response.Write("Another line")

it won't display in two lines in the browser, but rather as "A lineAnother line". The same applies to the source code. As already mentioned, you can use <br> to force a line break in HTML. If you want the line break to be visible in the source code, you'll want to use the vbCrLf constant.

Response.Write("A line<br>")
Response.Write("Another line")

will display two lines in the web browser

Response.Write("A line<br>" & vbCrLf)
Response.Write("Another line")

will additionaly result in two lines in the HTML source code.