Fix Your Overflows
by hikosan (15-May-2026)
I've been trying to read an article on my phone, and upon scrolling down, the page drifted to the right, pushing all the content to the left, beyond the screen. I tried to readjust and control my scrolling, but the result was the same. I tried to do this "zoom out" gesture (whatever it's called) with my fingers, but the webpage became so small I couldn't read the text. Let me tell you: this is a truly annoying experience. I am sitting here, wondering, "Why can't you simply fix your overflows?". Come on, it can't be that hard. Don't you browse your own webpage on phone and see that's not it? That there's an issue?
Now when I see the horizontal scroll bar appear on the bottom, I automatically try to see how small the page will get if I zoom out. Well, sometimes it's not that horrible, but it drives the perfectionist inside of me a little bit nuts when, for example, seeing the header getting a strong cutoff on the right. The web is so broken, and not because of the standards or the technology--no, it's because I came to the realization that people do not like CSS. People do not like to manually type out HTML tags with CSS rules, and then debug that using web browser's devtools. But it's not that complicated, bear with me! Because I am going to fix your overflows (*of random websites I stumbled upon as of today--the day of writing this article) and show how it's not that complicated and only takes a few minutes of your time.
But, before we begin, let's understand why the overflow happens: that's usually because one of the elements has an incorrect size (width value) that makes it ignore the parent element's size and push beyond it. So, say, you have a div element that has a size of width=200px, which has a child element that is of size width=300px--this will cause the so-called overflow. Other common causes are code blocks and negative margin values. This happens because of incorrect styling (wrong CSS rules). The good news is that there's a way to debug it using "Developer Tools" (which you can invoke by pressing F12 in web browser):
The most common reason for this is usually because there is an element somewhere that has a fixed width that does not change when the web browser's window gets resized. In CSS, there are few ways to declare the width of an element: width (fixed), max-width / min-width (dynamic). For example, look at the animation below that shows how the navigation bar does not fit within the header and stretches beyond:
If we look at the DOM, we will see how old-fashioned the HTML is: that navigation bar was implemented using a table, and each ul element has a fixed width defined in CSS as width: 120px. This website is clearly not mobile friendly, because hovering over each link in the navbar will show more links. This would require rewriting the navbar entirely, accounting for smaller screens.
This another example defines both min-width and max-width properties with the same value 80ch. That makes it essentially equivalent to defining the width property. And since it is being used on the body element, it prevents all the content within it to adapt to smaller screen resolutions. The good thing is that the fix here does not require rewriting any HTML.
First of all, let's remove the min-width property from the body element. This will allow for everything within the body element to adapt to its size (as long as they don't have fixed width). Then we will give it padding: 20px to add some spacing on the sides. The horizontal bar does not disappear, though. Another obvious thing that can cause this is the pre element which is usually used for code blocks. It has one at the bottom of the page, so it needs to have some style fixing. The pre element has a child element code which has a fixed width:
Obviously, you should fix it in the actual CSS file--anything you're doing in DevTools is debug-only / for viewing the changes in real-time, and updating the page will reset every change made. This fixes everything, the overflow is no more. But it might introduce a new problem: what if the code inside of the code block is actually long, and it doesn't break to the new line? There's actually a known best practice for such elements--the content should be contained within that element using a horizontal scrollbar. You can learn to do that (or steal mine). The last thing, your header will look messy, so you want to make sure that once the screen is small, you want to add this code:
@media only screen and (max-width:600px) { nav { flex-direction: column; gap: 14px; } }
Having learned the basics, and the most common causes of this annoying "bug", let's cure some patients.
NOTE: just to be safe, take this as an advice and not an actual solution.
OK, I am done with free labor. I hope this was enough for you to understand the problem and the possible ways to fix it!