Cross-site scripting happens when an application takes input from a user and writes it into a page without properly encoding it, so the browser interprets the input as code rather than text. When that code is JavaScript, the attacker's script runs in the victim's browser with the victim's session, which is why XSS leads to session theft, account actions performed as the victim, and defacement.
The two classic types are reflected XSS, where the payload is in a request and echoed straight back in the response (often via a crafted link), and stored XSS, where the payload is saved by the app (in a comment or profile) and served to everyone who views that content. Stored is more dangerous because it hits every viewer automatically.