Use Response.Write to send text, a variable, or generated HTML to the browser from Classic ASP (VBScript). The example below displays Hello World.
Response.Write "Hello World"
When used in a standalone .asp file, place VBScript inside <% and %> delimiters. See the complete page example further below.
Response.Write expression
The expression may be a string literal, number, variable or combined expression. Response.Write writes to the HTTP response body; the browser then interprets the resulting text as HTML if the page is served as HTML. This method does not automatically add a newline or an HTML break.
| Expression | Purpose |
|---|---|
Response.Write "Hello" | Writes a literal string. |
Response.Write 25 | Writes a numeric value. |
Response.Write myName | Writes a variable. |
Response.Write "Hi " & myName | Joins text and a variable. |
Response.Write "<br>" | Writes an HTML line-break tag. |
VBScript string literals use double quotes. To include a double-quote character inside the string, write it twice (""). This example demonstrates the rule:
Response.Write "Raju told ""He is learning ASP from plus2net"" So you can also learn from here "
Output:
Raju told "He is learning ASP from plus2net" So you can also learn from here
This is VBScript string escaping, not HTML output encoding. See quotation marks and escaping in VBScript.
When creating HTML tags inside a VBScript string, double the quotes around an attribute value:
Response.Write "<a href=""/asp-tutorial/site_map.php"">ASP tutorials</a>"
The browser receives a normal <a href="/https/www.plus2net.com/asp-tutorial/site_map.php"> link. For fixed HTML that does not need to be constructed dynamically, writing HTML directly in the page is often simpler.
HTML tags produced by Response.Write are interpreted by the browser. Use a matching closing tag when you generate HTML. For example, <strong> and </strong> must appear together:
Response.Write "Use <strong>bold text</strong> to highlight a message."
Browser display: Use bold text to highlight a message.
For HTML markup basics, see the HTML tags tutorial. To show literal tag characters, use Server.HTMLEncode() instead of outputting raw HTML tags:
Response.Write Server.HTMLEncode("<strong>Hello</strong>")
Output:
<strong>Hello</strong>
Response.Write "First line<br>"
Response.Write "Second line<br>"
Response.Write "Third line"
Output:
First line
Second line
Third line
A <br> tag creates a visible line break in HTML. Inserting vbCrLf into HTML source alone usually does not create a visible line break in normal browser rendering. For multiline text entered by visitors, see convert text line breaks for HTML display.
Dim userName, total
userName = "Raju"
total = 25
Response.Write "Name: " & userName & "<br>"
Response.Write "Total: " & total
Output:
Name: Raju
Total: 25
Use the ampersand (&) to concatenate strings and values. See concatenating strings in VBScript.
Response.Write "Server date and time: " & Now()
The result changes when the page runs. It uses the server clock, not necessarily the visitor’s local time. See Date, Time and Now in Classic ASP.
When a value comes from a form, URL, database or other untrusted source, do not write it into HTML without context-appropriate encoding. For normal HTML text content, Server.HTMLEncode() converts characters such as < and & into harmless text.
Dim visitorName
visitorName = Request.QueryString("name")
Response.Write "Hello, " & Server.HTMLEncode(visitorName)
For a request like ?name=Raju, the browser displays Hello, Raju. Text resembling HTML markup is shown as text rather than executed as markup.
Server.HTMLEncode() is appropriate for HTML text nodes. HTML attribute values, JavaScript strings, CSS, and URLs have different safety requirements. Do not use Response.Write to insert untrusted text directly into a <script> element.Dim inputText
inputText = "<b>Example</b>"
Response.Write "Raw HTML: " & inputText & "<br>"
Response.Write "Encoded text: " & Server.HTMLEncode(inputText)
The first line creates bold markup; the second displays the literal characters <b>Example</b>. Use the second approach for user-generated content.
This example displays a submitted name only after the visitor uses the button. The value is read from Request.Form() and encoded before output.
<form action="" method="post">
<label for="visitorName">Your name</label>
<input id="visitorName" name="visitorName" type="text" required>
<button type="submit">Show greeting</button>
</form>
<%
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
Dim visitorName
visitorName = Trim(Request.Form("visitorName"))
If Len(visitorName) > 0 Then
Response.Write "<p>Hello, " & Server.HTMLEncode(visitorName) & "</p>"
Else
Response.Write "<p>Please enter your name.</p>"
End If
End If
%>
The browser-side required attribute improves usability, but the Len() check still validates the submitted value on the server. Add additional validation when storing or using user input.
When you need several similar items, combine Response.Write with a For...Next loop. Fixed HTML structure and loop-generated rows are kept separate here:
<ul>
<%
Dim i
For i = 1 To 5
Response.Write "<li>Item " & i & "</li>"
Next
%>
</ul>
Browser display:
<table class="table table-bordered">
<thead><tr><th>Number</th><th>Square</th></tr></thead>
<tbody>
<%
Dim i
For i = 1 To 3
Response.Write "<tr><td>" & i & "</td><td>" & (i * i) & "</td></tr>"
Next
%>
</tbody>
</table>
| Number | Square |
|---|---|
| 1 | 1 |
| 2 | 4 |
| 3 | 9 |
Classic ASP supports the shorter <%= expression %> syntax for displaying a value directly in markup. Both forms add content to the response:
<%
Dim city
city = "Hyderabad"
Response.Write "<p>City: " & Server.HTMLEncode(city) & "</p>"
%>
<p>City: <%= Server.HTMLEncode(city) %></p>
The two lines display the same city. The shorter form is convenient in HTML templates; Response.Write is useful inside VBScript statements and procedures. Neither form automatically encodes untrusted data.
Save the following example as response-write-example.asp on an IIS server with Classic ASP enabled. It includes the ASP language directive, HTML structure, a variable, and an encoded output example.
<%@ Language="VBScript" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Response.Write demo</title>
</head>
<body>
<h1>Response.Write example</h1>
<%
Dim message
message = "Welcome to plus2net.com"
Response.Write "<p>" & Server.HTMLEncode(message) & "</p>"
Response.Write "<p>Server date: " & Server.HTMLEncode(CStr(Date())) & "</p>"
%>
</body>
</html>
The displayed date depends on the server clock and regional settings. In a real application, keep presentation and complex business logic organized rather than building every HTML element with strings.
| Problem | Explanation or solution |
|---|---|
| HTML tags appear as plain text | Check whether they were encoded using Server.HTMLEncode(). Encoding is appropriate for displaying user text but not when intentionally constructing trusted markup. |
| Text is on one line | Response.Write does not add line breaks. Use <br> or paragraphs for visible HTML breaks. |
| Quotes produce a syntax error | Double quotation marks within VBScript string literals: "". |
| Output shows user-supplied HTML markup | Use Server.HTMLEncode() when writing the value into HTML text content. |
| Nothing displays in the browser | Verify the page is served as .asp by IIS, Classic ASP is enabled, and the code is inside <% ... %>. |
| Headers cannot be changed | Headers and redirects may need to be set before buffered output is flushed. See response buffering and Response.Flush(). |
No. It writes the supplied value. Add an HTML <br> element or use semantic paragraphs or list items to control visible layout.
No. Response.Write adds content to the response. Response.Flush() sends buffered content to the client when buffering is enabled.
Yes. It works inside If...Then...Else statements, For...Next loops, procedures, and other VBScript code blocks.
For details on ending request processing, see Response.End(). Use it intentionally because it stops processing the remaining ASP script.
It can generate HTML that contains scripts, but concatenating untrusted values into JavaScript creates security risks. Use context-appropriate encoding and avoid building scripts from visitor input.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.