How to fix CSS underflow & overflow ?
Last Updated :
02 Aug, 2022
In this article, we’ll see how to manage the overflow issue in CSS. This type of issue generally arises when the content exceeds the container size or when the dimension(i.e. width and height) of the container is fixed. Here, the content can be text or an image and the container can be a <div> tag or another HTML tag that contains the text or image. For instance, the below image illustrates the fixed length of the container size for which the content is overflowing from the container.

Overflow of the text
The problem of an overflow of the content when the size of the container is fixed can be accomplished with the help of the below 2 methods:
- By making container size modifiable
- By applying overflow-related properties provided by CSS
We will explore both these approaches in detail & understand them through the illustrations.
By making container size modifiable: This task can be accomplished with the help of the CSS min-height property which sets the minimum height of the container. The minimum height will only be applicable if the content is within or small in size in comparison to the minimum height. Otherwise, the min-height property has no effect, if the content exceeds the minimum height.
Example 1: This example describes controlling the content overflow with the help of the CSS min-height property.
HTML
<!DOCTYPE html>
< html >
< head >
< title >
Fixing the text overflow in CSS
</ title >
< style >
* {
margin: 0;
padding: 0;
}
.container {
width: 250px;
min-height: 200px;
border: 4px solid rgb(7, 240, 96);
color: rgb(31, 231, 31);
}
h1 {
color: green;
}
</ style >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< h3 >
Fixing the text overflow in CSS
</ h3 >< br />
< div class = "container" >
< p >
In this article, we'll see how to manage the
overflow issue in CSS. This type of problem
arrives when the content of the container
exceeds the container size, the container
contents will overflow. Here the content can
be text or image and the container can be a
div tag or some other HTML tag. This overflow
problem arrives only when the dimension of the
container is fixed. min-height properties set
the minimum height of the container and whenever
the content of the container required more space
then the height of the container also increases
with the size of the content.
</ p >
</ div >
</ body >
</ html >
|
Output:
By implementing CSS overflow-related properties: The overflowing of the content can be controlled & managed by implementing the required overflow property in CSS, which tells whether to clip the content or, to add scroll bars, or simply hide the extra content that is overflowed. To do this, CSS provides some properties, which are described below:
overflow: This CSS property handles the overflow problem in both vertical as well as horizontal without change in the dimension of the container. The overflow property has 4 values:
- hidden: It hides all the contents which overflow from the container.

changes after applying overflow: hidden
- scroll: it adds the scroll bar so the user can see all the content by scrolling.

overflow: scroll
- auto: It adds the scroll bar as needed for vertical or horizontal.

overflow: auto
- visible: visible is the default value of the overflow. so no change occurs after applying this property value.

overflow: visible
overflow-y: It is used to handle overflows of the content vertically. It also has 4 properties similar to overflow:
- visible: No change occurs after applying this property value.

overflow-y: visible
- hidden: It hides content that extends more than the container size vertically. But if the content overflows in the horizontal direction and you don’t define overflow-x, that creates a scroll bar in the horizontal direction.

overflow-y: hidden
- scroll: It adds a scroll bar vertically so the user can see the entire content by scrolling. But if you don’t define overflow-x and the content is overflowing horizontally, that creates a scroll bar in the horizontal direction.

overflow-y: scroll
- auto: It adds the slider if the content needs more space vertically.

overflow-y: auto
overflow-x: It is used to handle overflows of the content horizontally. Mostly it is used when we use the image in a container of fixed width and the width of the image exceeds the width of the container. Because the text is always laid out in the vertical direction when it excessed the width of the container. It also has 4 properties similar to overflow:
- hidden: It hides content that extends more than the container size horizontally.

overflow-x: hidden
- scroll: It adds a scroll bar horizontally so the user can see the entire content by scrolling.

overflow-x: scroll
- auto: It adds the slider if the content needs more space horizontally.

overflow-x: auto
- visible: No change occurs after applying this property value.

overflow-x: visible
For content underflow, there is no such definition is available in CSS that we can implement. Generally, the problem of this kind happens because of small mistakes.
Example 2: This example describes managing the overflowed content using the overflow property in CSS.
HTML
<!DOCTYPE html>
< html lang = "en" >
< head >
< title >
Fixing the text overflow using overflow Property
</ title >
< style >
* {
margin: 0;
padding: 0;
}
.container {
width: 350px;
height: 200px;
border: 4px solid red;
overflow: auto;
/* hidden , auto , scroll , visible */
}
h1 {
color: green;
}
</ style >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< h3 >
Fixing the text overflow using overflow Property
</ h3 >
< div class = "container" >
< p >
In this article, we'll see how to manage the
overflow issue in CSS. This type of problem
arrives when the content of the container
exceeds the container size, the container
contents will overflow. Here the content can
be text or image and the container can be a
div tag or some other HTML tag. This overflow
problem arrives only when the dimension of the
container is fixed. min-height properties set
the minimum height of the container and whenever
the content of the container required more space then
the height of the container also increases with the
size of the content.
</ p >
</ div >
</ body >
</ html >
|
Output:

Similar Reads
How to Avoid CSS text-overflow to Ellipsis?
The CSS text-overflow: ellipsis property is used to truncate text and display an ellipsis at the end of the text when it overflows its container. However, there may be cases where you want to avoid using this property. Fortunately, there are several approaches you can take to achieve this. Table of
5 min read
How to Remove Underline from Links in CSS?
The text-decoration property is used to remove the underline from links in CSS. You can use the below syntax on anchor element to remove underline from link. Syntax a { text-decoration: none;}It is very basic to remove underline from link with text-decoration property. The none value removes the und
1 min read
How to Prevent Text from Overflowing in CSS?
Text overflow happens when an HTML element's content goes beyond the limits of its container. This could break the layout or hide content, which would result in an unpleasant user experience. Using overflow properties, changing the container width, and managing word wrapping and breaking are some of
4 min read
How to use text overflow property in CSS ?
In this article, we will see how to set text overflow property in CSS. The text-overflow property is used to specify that some text has overflown and hidden from view from the user. The text-overflow property only affects content that is overflowing a block container element. Syntax: text-overflow:
2 min read
How to use text-overflow in a table cell ?
In this article, we will see how to use text-overflow in a table cell. A text-overflow property in CSS is used to specify that some text has overflown and hidden from view. Approach: The white-space property must be set to "nowrap" and the overflow property must be set to "hidden". The overflowing c
2 min read
How to Underline Text using CSS?
To underline a text using CSS, the CSS text-decoration property is used with the value set to underline. Using text-decorationWe use the text-decoration CSS property to underline a text using CSS. The text that is to be underlined is inserted in a <p> tag and the property is applied. Syntax te
1 min read
CSS overflow Property
The CSS overflow property is used to set the overflow behavior of an element. It is the shorthand property of overflow-x and overflow-y properties. This property is used to control the large content. Syntax: overflow: visible | hidden | clip | scroll | auto;Property Values: visible: The content is n
2 min read
Tailwind CSS Overflow
This overflow is for controlling how an element content is handled that is too large for the container. It tells whether to clip content or add scroll bars. This class accepts more than one value in Tailwind CSS. It is the alternative to the CSS Overflow property. There is a separate property in CSS
7 min read
How CSS clearfix property useful ?
In this article, we will see what is clearfix CSS property and how it is useful, along with understanding the different ways of implementing it through the examples. Assigning a number of CSS properties to a parent element that will wrap its floating children is a common technique in CSS float-based
3 min read
How to change the underline color in CSS?
In this article, we are going to learn how to change the underline color in CSS, To change the underline color in CSS, use the text-decoration-color property. Set it to the desired color value. Styling is implemented in HTML text to make it catchy and attractive. The text can be made italic, underli
1 min read