Proposal for Chrome and Content Modes in HTML
Published: 2021-07-21 22:02:52

---
title: Proposal for Chrome and Content Modes in HTML
published: true
date: 2021-07-14 21:18:00 UTC
tags: 
canonical_url: https://kevincox.ca/2021/07/14/chrome-and-content-modes-in-html/
---

<main><p><a href="https://kevincox.ca/2021/06/23/respect-user-fonts">I’ve talked before about respecting your user’s preferences in your web design</a>. I think that this site does <a href="https://kevincox.ca/2021/07/13/not-my-fault-if-this-is-ugly">a good job at taking the viewer’s preferences into account</a>, but it is far from perfect. The main problem is that there are infinite preferences a user may have, but the CSS spec can only convey hand-picked features to a site’s stylesheet.</p>
<p>I think that the web could provide a better reading experince with separate “Chrome” and “Content” modes that allow a site to be viewed based on the user’s preferences.</p>
<h2 id="existing-mechanisms"><a href="https://kevincox.ca/2021/07/14/chrome-and-content-modes-in-html/#existing-mechanisms">Existing Mechanisms</a></h2>
<h3 id="browser-stylesheets"><a href="https://kevincox.ca/2021/07/14/chrome-and-content-modes-in-html/#browser-stylesheets">Browser Stylesheets</a></h3>
<p>There is actually one existing mechanism that does convey enough information, the browser’s default stylesheet. These are the rules that the browser uses if you don’t provide any of your own. For example <a href="https://motherfuckingwebsite.com/">motherfuckingwebsite.com</a> relies solely on the browser’s built in stylesheets.</p>
<p>However, as explained so well by <a href="http://bettermotherfuckingwebsite.com/">bettermotherfuckingwebsite.com</a>, it isn’t particularly easy on the eyes. Why is that? Why can’t browsers ship pretty default stylesheets? The answer is quite simple, there is no way to opt out. If a browser shipped a stylesheet that used a black background sites would break. Thousands of sites that set <code>color: #333</code> for a dark grey text colour without changing the background colour would now have illegible dark grey text on a black background. The problem with the default stylesheet is that the design of sites depend on it. Anything more than minor tweaks will break layouts and styles across the web. This requirement to avoid breaking sites hamstrings the power of the default stylesheet, so it is not a suitable mechanism for providing a nice reading experience for users.</p>
<h3 id="reader-mode"><a href="https://kevincox.ca/2021/07/14/chrome-and-content-modes-in-html/#reader-mode">Reader Mode</a></h3>
<p>Firefox now offers <a href="https://support.mozilla.org/en-US/kb/firefox-reader-view-clutter-free-web-pages">Reader View</a> which attempts to display a page in a format optimized for reading. It is a nice feature and I use if fairly regularly, but it has a number of downsides.</p>
<ol>
<li>It requires the user to enable it for each site. I can’t ask for it to be enabled automatically on load.</li>
<li>It is heuristic based, I have no way to ensure that my site works properly (now or into the future).</li>
<li>It provides no mechanism for custom content. So I can’t embed highlighted code, or interactive widgets.</li>
</ol>
<p>Reader mode is a step forward, and will always be useful to provide dramatic improvements to some awful sites, but it doesn’t seem capable to provide a top-quality experience in many cases.</p>
<h2 id="my-proposal"><a href="https://kevincox.ca/2021/07/14/chrome-and-content-modes-in-html/#my-proposal">My Proposal</a></h2>
<p>I think the solution is to empower the default stylesheet. Much like Reader Mode can take full control of the content to display it in a readable way, we need to let the browser’s default stylesheet do the same. However in order to do that we need to overcome the shortcomings of the first two approaches. I think the key is making this “enhanced stylesheet” opt-in instead of opt-out so that styles can be changed without breaking existing sites. Furthermore it will be possible to opt-out specific sections of the page. This would allow embedded interactive content inside of a readable document.</p>
<p>To be concrete:</p>
<ol>
<li>Sites can mark elements as “content”. These elements are styled with an opinionated default stylesheet. The site author can still tweak the style with custom CSS, but they should be careful to avoid changes that may conflict with the browser style, any breakage would be “their fault”.</li>
<li>Sites can mark elements as “chrome”. These elements are excluded from the above styles. The default styles applied to this element and its children would either be the current browser default stylesheets or ideally a very consistent stylesheet. (For example white background, black text, no margins, padding or borders, no text decoration and similar. Semantic elements should still be selected but they would all have the same default styles.)</li>
</ol>
<p>CSS doesn’t have good support for “elements under <code>.content</code> but not under <code>.chrome</code>” in the way that would be needed to implement this. But I managed to make a mockup (ab)using CSS variables.</p>
<div><pre><code><span>&lt;style&gt;</span>
	<span>.content</span> <span>{</span>
		<span>/* Enable content rules. */</span>
		<span>--content-only</span><span>:</span> <span>;</span>

		<span>color</span><span>:</span> <span>var</span><span>(</span><span>--content-only</span><span>)</span> <span>blue</span><span>;</span>
	<span>}</span>

	<span>.content</span> <span>p</span> <span>{</span>
		<span>border</span><span>:</span> <span>var</span><span>(</span><span>--content-only</span><span>)</span> <span>1px</span> <span>solid</span> <span>black</span><span>;</span>
	<span>}</span>

	<span>.chrome</span> <span>{</span>
		<span>/* Disable content rules. */</span>
		<span>--content-only</span><span>:</span> <span>-invalid</span><span>;</span>

		<span>/* Reset inherited properties. */</span>
		<span>color</span><span>:</span> <span>initial</span><span>;</span>
	<span>}</span>
<span>&lt;/style&gt;</span>

<span>&lt;p&gt;</span>The root is chrome.<span>&lt;/p&gt;</span>

<span>&lt;article</span> <span>class=</span><span>content</span><span>&gt;</span>
	<span>&lt;p&gt;</span>This is content<span>&lt;/p&gt;</span>
	<span>&lt;div</span> <span>class=</span><span>chrome</span><span>&gt;</span>
		<span>&lt;p&gt;</span>Back to chrome<span>&lt;/p&gt;</span>

		<span>&lt;div</span> <span>class=</span><span>content</span><span>&gt;</span>
			<span>&lt;p&gt;</span>In content again<span>&lt;/p&gt;</span>
		<span>&lt;/div&gt;</span>
	<span>&lt;/div&gt;</span>
<span>&lt;/article&gt;</span>
</code></pre></div>
<p>This applies silly styles to demonstrate the point, but it is easy to imagine a beautiful set of styles for the content sections. If I had any design skills I would turn it into a simple CSS library for nice readable sites. (If you do this let me know.) But the full power wouldn’t be realized until it is part of the browser and controlable by the user.</p>
<p>The opt-in mechanism would need to be more unique than a <code>content</code> class. But the idea is simple and effective.</p>
<h2 id="summary"><a href="https://kevincox.ca/2021/07/14/chrome-and-content-modes-in-html/#summary">Summary</a></h2>
<p>There is a conflict on the web between documents, which are usually best viewed with the user’s preferences and “apps” which should still respect the user’s preferences where possible but often have complex styles that are sensitive to many browser tweaks. Separating these two use cases would provide the best of both worlds; readable content and easy, consistent chrome.</p>