Cross Site Scripting (XSS) allows malicious users to insert client-side scripts into web pages by exploiting vulnerabilities. There are three main types of XSS attacks: non-persistent XSS only affects the current user, while persistent XSS saves the malicious script to databases and can target multiple users. DOM-based XSS modifies the DOM environment rather than HTTP responses. XSS can be used to steal cookies, hijack sessions, modify page content, and redirect users. Developers can prevent XSS by validating, sanitizing, and escaping all untrusted user input to the application.