
\documentclass[12pt]{article}
\usepackage[T2A,OT1]{fontenc}
\usepackage[default]{cantarell}
\usepackage[a4paper, top=20mm, bottom=20mm, left=20mm, right=20mm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[russian, english]{babel}
\usepackage{tabu}
\usepackage{hyperref}
\usepackage{parskip}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage[normalem]{ulem}
\usepackage{float}
\floatstyle{boxed}
\restylefloat{figure}
\usepackage{setspace}
\onehalfspacing
\author{Artyom Bologov \href{mailto:easy-fixes@aartaka.me}{(email)}}
\date{\today}
\title{Easy (Horizontal Scrollbar) Fixes for Your Blog CSS}
\makeatletter
\def\endenv{\expandafter\end\expandafter{\@currenvir}}
\makeatother
\begin{document}
\maketitle

\includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{./assets/easy-fixes.png}

So it often happens that I find some blog post.
A fun one.
A freaky one.
A profound one.
A critical (in the sense of Critical Science, not everyday criticism!)

And then I see my arch nemesis: The Horizontal Scrollbar.
Creeping in when no one sees, on smallest screen widths.
(I have an iPhone SE and a small 13-inch laptop with x2 UI scaling.)
Making the website interaction much less pretty than it might’ve been.

So I took up a torch and decided to write this up for y’all.
None of us can’t know everything about making blog posts more accessible to small viewports.
So let’s share the knowledge.
Here are four of my life-hacks for small viewport adaptation, matching the three most problematic HTML elements:

\section*{Preformatted (<pre>) Block Scrolling} \label{pre}

We programmers list a lot of code snippets in our blog posts.
And, living in a post-VT100 era, we don’t usually care about line length.
Which is totally fine.
But it often results in long code blocks overflowing the viewport and causing horizontal scrollbars:

\begin{figure}[h!]\begin{verbatim}
0001011000000111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110100001011000000111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111010000101100000011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110100001011000000111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011100111010000010
\end{verbatim}\caption{The name of my favorite Kpop singer (hint: she’s a certified freak, ten days a week 🎵)}\end{figure}

Yeah, Binary Lambda Calculus be like that sometimes.
Believe me, I can’t read it myself, especially with this scrollbar!

\paragraph{Fix it!} \begin{quote}
The fix is easy:

\begin{figure}[h!]\begin{verbatim}
pre {
    overflow-x: auto;
}
\end{verbatim}\caption{Fix to overflowing pre-formatted blocks}\end{figure}

This \verb|overflow-x| value means:

\begin{itemize}\item if the code block overflows (horizontally, thus the \verb|x|,) let’s add a scrollbar to it (and not the surrounding page!)
\item and if it doesn’t overflow, then just proceed as regular
\end{itemize}

Check out the fixed code block above 👆
\end{quote}

\section*{Images (<img>) and Their Width} \label{img}

I was unable to contact htmx website maintainers, but oh are they guilty of that.
The images on htmx blog are not properly sized and “escape” the viewport regularly.
Something like:
</p>

\includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{./assets/easy-fixes-img.png}

\paragraph{Fix it!} \begin{quote}
HTML images are scaled to their original width and height by default.
So huge images are likely to overflow and cause dreadful scrollbars.
This is solvable by capping image width to the size of its container:

\begin{figure}[h!]\begin{verbatim}
img {
    max-width: 100%;
    height: auto;
}
\end{verbatim}\caption{Fix to images occupying too much horizontal space}\end{figure}

This is usually enough as a baseline.
Add your fancy image placement on top in peace!

Check out the fixed image above 👆
\end{quote}

Bonus point: this seems to be a problem for videos too.
So watch your \verb|max-width| there too!

\section*{Tables (<table>), a World in Themselves} \label{table}

\href{https://www.spacejam.com/1996}{Ever visited the Space Jam website}?
Neither did I.
But we still live with its legacy.
No, not the space operas or whatever.
\emph{Tables as markup}.

Tables were abused for markup on the early Internet.
And we still have to deal with the suspicion that table layouting is Turing-complete.
Or at least pray the next table doesn’t destroy the page.

\begin{quote}
Sorry, typesetting this table in formats other than HTML is pure pain.
I’ll get back to it someday.
Maybe.
\end{quote}

\paragraph{Fix it!} \begin{quote}
There’s no single-property fix to tables stretching too far.
But one solution (that always works in webdev, right?) is to wrap the table into a \verb|<div>|!

\begin{figure}[h!]\begin{verbatim}
<div class=scrollable>
<table>
...
</table>
</div>
\end{verbatim}\caption{Wrapping a table into a scrollable div}\end{figure}

And apply \verb|overflow-x| to it:

\begin{figure}[h!]\begin{verbatim}
.scrollable {
    overflow-x: auto;
}
\end{verbatim}\caption{Special class for scrollable containers}\end{figure}

I mean, this \verb|.scrollable| can be reused in more places, so it’s a net positive?

Check out the fixed table above 👆
\end{quote}

\section*{Word Breaking (use !)} \label{wbr}

In case you care about accessibility and do large device-adapted fonts.

\begin{figure}[h!]\begin{verbatim}
font-size: large;
font-size: max(1em, 16px, 1rem);
\end{verbatim}\caption{CSS properties for more accessible fonts}\end{figure}

You might inadvertently destroy the viewport with your vocabulary.
Well, if yours is fancy and includes German compound words.
(\href{https://learn-german-easily.com/longest-german-word id=fix-wbr}{Neunmilliardeneinhundertzweiundneunzigmillionensechshunderteinunddreißigtausendsiebenhundertsiebzigfache} 👻)

The problem with long no-delimiter words: they are not broken by default in HTML.
So using longer words can overflow the viewport and cause the miserable horizontal scrollbar.

\paragraph{Fix it!} \begin{quote}
The solution is more involved than a CSS property, unfortunately: use \verb|| HTML tag.
Put it in the middle of the offending word to allow the browser to line-break it.
(Use your linguistic judgement on where to meaningfully break the line.)
Your mobile users will thank you for that.

Another option is using a \verb|\&shy;| (soft hyphen) entity, but that has less coercive power.
And using (structured and semantic) tags is preferable over using Unicode if you’re in a browser land.

I mean, there’s a CSS solution too, but it’s not pretty to language semantics:

\begin{figure}[h!]\begin{verbatim}
p {
    word-break: break-word;
    overflow-wrap: anywhere;
}
\end{verbatim}\caption{I don’t recommend this CSS solution, but who am I to judge you if it removes the horizontal scrollbar?}\end{figure}
\end{quote}

These are four problems I’m hoping you viscerally felt with me just now.
And the solutions I personally use and suggest to fellow bloggers.
Hopefully we’ll come out of it with less tolerance to horizontal scrollbars.
Test your website on smaller screens and tread carefully 🩷


\par\noindent\rule{\textwidth}{0.4pt}
\href{https://creativecommons.org/licenses/by/4.0}{CC-BY 4.0} 2022-2026 by Artyom Bologov (aartaka,)
\href{https://codeberg.org/aartaka/pages/commit/a91befa}{with one commit remixing Claude-generated code}.
Any and all opinions listed here are my own and not representative of my employers; future, past and present.
\end{document}
