Open In App

How to create content area scrollable instead of the page using CSS ?

Last Updated : 14 Dec, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Making a particular content area scrollable is done by using CSS overflow property. There are different values in overflow property that are listed below. 

  • visible: The property indicates that it can be rendered outside the block box and it is not clipped.
  • hidden: This property indicates that the overflow is clipped. The rest of the content will be invisible.
  • auto: If overflow is clipped, then automatically a scroll-bar is added for the rest of the content.
  • scroll: This property indicates that the scroll-bar is added to see the rest of the content if it is clipped.
  • initial: This property sets to its default value.
  • inherit: This property inherits the property from its parent element.

We can disable page scrolling by setting body overflow property to hidden.

In both the examples, we will be using this property to disable the page scrolling.

Example 1: In this example, we use overflow: scroll property to make “div” vertically and horizontally scrollable.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
  
    <meta name="viewport" content=
        "width=device-width, initial-scale=1">
</head>
  
<style>
    body {
        /* disabling body scrolling */
        overflow: hidden;
        margin: auto;
        background: white;
        margin-top: 4%;
        text-align: center;
    }
      
    h1 {
        color: Green;
    }
      
    .scroll {
        /* enable div scrolling */
        overflow: scroll;
        height: 8%;
        background-color: aqua;
        border: 1px black solid;
        padding: 2%;
        width: 300px;
        margin: 0 auto;
        white-space: nowrap;
        font-size: large;
    }
</style>
  
<body>
    <h1>GeeksforGeeks</h1>
  
    <h2>
        Making content area scrollable 
        instead of the page
    </h2>
  
    <div class="scroll">
        It is a good platform to learn programming. 
        It is an educational website. Prepare for 
        the Recruitment drive of product based 
        companies like Microsoft, Amazon, Adobe etc 
        with a free online placement preparation 
        course. The course focuses on various MCQ
        & Coding question likely to be asked in the 
        interviews & make your upcoming placement 
        season efficient and successful. Also, any 
        geeks can help other geeks by writing 
        articles on the GeeksforGeeks, publishing 
        articles follow few steps that are<br
        Articles that need little modification or
        improvement from reviewers are published 
        first. To quickly get your articles reviewed,
        please refer existing articles, their 
        formatting style, coding style, and try to 
        make you are close to them. In case you are 
        a beginner, you may refer Guidelines to write
        an Article. It is a good platform to learn 
        programming. It is an educational website. 
        Prepare for the Recruitment drive of product 
        based companies like Microsoft, Amazon, Adobe 
        etc with<br> a free online placement preparation 
        course. The course focuses on various MCQ's & 
        Coding question likely to be asked in the 
        interviews & make your upcoming placement 
        season efficient and successful. Also, any 
        geeks can help other geeks by<br> writing 
        articles on the GeeksforGeeks, publishing 
        articles follow few steps that are Articles 
        that need little modification or improvement 
        from reviewers are published first. To quickly 
        get your articles reviewed, please refer 
        existing articles, their formatting style, 
        coding style, and try to make you are close 
        to them. In case you are a beginner, you may 
        refer Guidelines to write an Article.
    </div>
</body>
  
</html>


Output:

Example 2: In this example, use overflow:auto; to make “div” vertically and horizontally scrollable.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
  
    <meta name="viewport" content=
        "width=device-width, initial-scale=1">
  
    <style>
        body {
            /* disabling body scrolling */
            overflow: hidden;
            margin: auto;
            background: white;
            margin-top: 4%;
            text-align: center;
        }
          
        h1 {
            color: Green;
        }
          
        .scroll {
            /* enable div scrolling */
            overflow: auto;
            height: 8%;
            background-color: aqua;
            border: 1px black solid;
            padding: 2%;
            width: 300px;
            margin: 0 auto;
            white-space: nowrap;
            font-size: large;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
  
    <h2>
        Making content area scrollable 
        instead of the page
    </h2>
  
    <div class="scroll">
        It is a good platform to learn programming. 
        It is an educational website. Prepare for 
        the Recruitment drive of product based 
        companies like Microsoft, Amazon, Adobe etc 
        with a free online placement preparation 
        course. The course focuses on various MCQ
        & Coding question likely to be asked in the 
        interviews & make your upcoming placement 
        season efficient and successful. Also, any 
        geeks can help other geeks by writing 
        articles on the GeeksforGeeks, publishing 
        articles follow few steps that are<br
        Articles that need little modification or
        improvement from reviewers are published 
        first. To quickly get your articles reviewed,
        please refer existing articles, their 
        formatting style, coding style, and try to 
        make you are close to them. In case you are 
        a beginner, you may refer Guidelines to write
        an Article. It is a good platform to learn 
        programming. It is an educational website. 
        Prepare for the Recruitment drive of product 
        based companies like Microsoft, Amazon, Adobe 
        etc with<br> a free online placement preparation 
        course. The course focuses on various MCQ's & 
        Coding question likely to be asked in the 
        interviews & make your upcoming placement 
        season efficient and successful. Also, any 
        geeks can help other geeks by<br> writing 
        articles on the GeeksforGeeks, publishing 
        articles follow few steps that are Articles 
        that need little modification or improvement 
        from reviewers are published first. To quickly 
        get your articles reviewed, please refer 
        existing articles, their formatting style, 
        coding style, and try to make you are close 
        to them. In case you are a beginner, you may 
        refer Guidelines to write an Article.
    </div>
</body>
  
</html>


Output:

Note: You can enable only vertical scrolling by setting overflow-y to scroll and auto and overflow-x to hidden.

Similarly for horizontal scrolling, set overflow-x to scroll or auto and overflow-y to hidden.

Example 3: This example is used only for vertical scrolling of content area.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
  
    <meta name="viewport" content=
        "width=device-width, initial-scale=1">
  
    <style>
        body {
            overflow: hidden;
            margin: auto;
            background: white;
            margin-top: 4%;
            text-align: center;
        }
          
        h1 {
            color: Green;
        }
          
        .scroll {
            overflow-y: auto;
            overflow-x: hidden;
            height: 50%;
            background-color: aqua;
            border: 1px black solid;
            padding: 2%;
            width: 500px;
            margin: 0 auto;
            font-size: large;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
  
    <h2>
        Making content area scrollable 
        instead of the page
    </h2>
  
    <div class="scroll">
        It is a good platform to learn programming. 
        It is an educational website. Prepare for 
        the Recruitment drive of product based 
        companies like Microsoft, Amazon, Adobe etc 
        with a free online placement preparation 
        course. The course focuses on various MCQ
        & Coding question likely to be asked in the 
        interviews & make your upcoming placement 
        season efficient and successful. Also, any 
        geeks can help other geeks by writing 
        articles on the GeeksforGeeks, publishing 
        articles follow few steps that are<br
        Articles that need little modification or
        improvement from reviewers are published 
        first. To quickly get your articles reviewed,
        please refer existing articles, their 
        formatting style, coding style, and try to 
        make you are close to them. In case you are 
        a beginner, you may refer Guidelines to write
        an Article. It is a good platform to learn 
        programming. It is an educational website. 
        Prepare for the Recruitment drive of product 
        based companies like Microsoft, Amazon, Adobe 
        etc with<br> a free online placement preparation 
        course. The course focuses on various MCQ's & 
        Coding question likely to be asked in the 
        interviews & make your upcoming placement 
        season efficient and successful. Also, any 
        geeks can help other geeks by<br> writing 
        articles on the GeeksforGeeks, publishing 
        articles follow few steps that are Articles 
        that need little modification or improvement 
        from reviewers are published first. To quickly 
        get your articles reviewed, please refer 
        existing articles, their formatting style, 
        coding style, and try to make you are close 
        to them. In case you are a beginner, you may 
        refer Guidelines to write an Article.
    </div>
</body>
  
</html>


Output:



Similar Reads

How to make a div vertically scrollable without content using CSS ?
In this article, we will see how we can create a vertical scrollable section using CSS. HTML code is used to create the basic structure of the sections and CSS code is used to set the style, HTML Code: Create an HTML div element with the class container.Created three more nested div with class boxWrite some content inside each div with the class bo
2 min read
How to create Flex Box Container with Scrollable Content in Bootstrap 5?
Bootstrap is a framework that is suitable for mobile-friendly web development. It means the code and the template available on Bootstrap apply to various screen sizes. It is responsive for every screen size. A Flexbox container with scrollable content typically involves using the flex utility classes to create a flexible container and then applying
3 min read
How to create horizontal scrollable sections using CSS ?
In this article, we will see how we can create a horizontal scrollable section using CSS. We are going to make different sections and make them horizontally scrollable using CSS. HTML code is used to create the basic structure of the sections and CSS code is used to set the style. HTML Code: In this section, we will create a structure for our secti
3 min read
How to Create Scrollable Horizontal Menu using CSS ?
In this article, we are going to implement a Scrollable Horizontal Menu using CSS. Approach: Scrollable Horizontal Menu is used to scroll the horizontal navbar using CSS "overflow:auto" and "white-space: nowrap". These two attributes are used to scroll the horizontal menu. To implement the scrollable horizontal menu You have to add HTML.You have to
1 min read
Blaze UI Scrollable content Model
Blaze UI is a free open source UI Toolkit that provides a great structure for building websites quickly with a scalable and maintainable foundation. All components in Blaze UI are developed mobile-first and rely solely on native browser features, not a separate library or framework. It helps us to create a scalable and responsive website fast and e
3 min read
Express Returns Servers HTML Error Page Instead of res.json Error Message
ExpressJS is a backend web application framework built on top of NodeJS which helps us manage the server and routing. It has some powerful functionalities like middleware, templates, and debugging which help us to write efficient and faster code. It helps us extensively in building web applications. In this article, we will see why "Express returns
3 min read
Making a div vertically scrollable using CSS
Making a div vertically scrollable is easy by using the CSS overflow property. There are different values in the overflow property. We can use that property for getting a scroll bar on a web page. The below-mentioned examples are the ways to set a vertical scroll bar on a web page. Example 1: In this example, we have set the overflow-x: hidden; and
3 min read
Make a div horizontally scrollable using CSS
In this article, we will learn how to design a horizontally scrollable div using CSS, &amp; will see its implementation through the example. We can make a div horizontally scrollable by using the CSS overflow property. There are different values in the overflow property. These are the following ways to make a div horizontally scrollable using CSS:
4 min read
How to create Scrollable HTML Comment box ?
The purpose of this article is to create a scrollable comment box using HTML and CSS3 property. An HTML scrollbox is a box with expanding scroll bars when the contents of the box are too huge to fit. Approach: For the scope of this article, we will make a div element that displays the comments, and we will create a scrollable div element. We will c
2 min read
How to create a table with fixed header and scrollable body ?
The purpose of this article is to create a table with a fixed header and scrollable body. We can create such a table with either of the two approaches. By setting the position property to “sticky” and specifying "0" as a value of the top property for the &lt;th&gt; element.By setting the display to "block" for both &lt;thead&gt; and &lt;tbody&gt; e
2 min read