
Homayoun MohammadiModern websites are not only about beautiful UI and animations security matters too. One of the most...
Modern websites are not only about beautiful UI and animations security matters too.
One of the most common browser-based attacks is called Clickjacking.
Even frontend developers should understand it because this attack targets the UI itself.
Clickjacking is a type of attack where a malicious website tricks users into clicking something they cannot see.
Usually, the attacker places your website inside an invisible <iframe> and overlays fake buttons or content on top of it.
The user thinks they are clicking one thing…
but they are actually clicking buttons on your real website underneath.
Imagine this:
A user visits a fake website with a “Play Video” button.
But behind that button, your banking website is loaded invisibly inside an iframe.
When the user clicks “Play Video” they might actually:
without realizing it.
Clickjacking can:
In some advanced cases, attackers can even capture keyboard input or sensitive interactions.

Modern browsers provide built-in defenses.
This HTTP header controls whether your website can be embedded inside an iframe.
X-Frame-Options: DENY
X-Frame-Options: SAMEORIGIN
This is the most common option.
Today, most developers prefer using CSP.
Content-Security-Policy: frame-ancestors 'self';
This tells the browser:
“Only allow this website to be framed by itself.”
You can also allow specific domains:
Content-Security-Policy: frame-ancestors 'self' https://example.com;
Older browsers handled clickjacking differently.
Some legacy protections used JavaScript frame-busting techniques like this:
<script>
if (self !== top) {
top.location = self.location;
}
</script>
But modern security headers are much more reliable.
For modern applications:
Content-Security-Policy
frame-ancestors
Frontend security is not only the backend developer’s responsibility.
Even UI decisions can become security vulnerabilities.
Understanding attacks like Clickjacking helps developers build safer and more trustworthy web applications.