Skip to content
Related Articles

Related Articles

Improve Article

Fullscreen API using JavaScript

  • Last Updated : 14 Jul, 2021
Geek Week

The window supports the full-screen interface by using web API. We can activate or deactivate the full-screen mode of the screen. The fullscreen API provides methods to present a specific element in a full-screen mode.


  • The onclick event will trigger the activate() method which will be for activating the full screen.
  • The same will be applied for exiting from the full screen.
<button onclick="activate(document.documentElement);">
      Go To Full Screen
<button onclick="deactivate();">
      Leave Full Screen

Example: The following code uses the requestFullscreen() method. The same is done for exiting full screen by using exitFullscreen() method.


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0" />
    <h1 style="color: green">GeeksForGeeks</h1>
    <h2>Window fullscreen property</h2>
    <button onclick="activate(document.documentElement);">
        Go To Full Screen
    <button onclick="deactivate();">Leave FullScreen</button>
        // Function for full screen activation
        function activate(ele) {
            if (ele.requestFullscreen) {
        // Function for full screen activation
        function deactivate() {
            if (document.exitFullscreen) {


activate or deactivate full screen


  • You can apply it to any element in your website

  • It will help to execute the full screen.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it’s lowest price ever!

My Personal Notes arrow_drop_up
Recommended Articles
Page :