<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Michael Großklaus</title>
  <link href="https://www.mgrossklaus.de/feed.xml" rel="self" type="application/atom+xml" />
  <link href="https://www.mgrossklaus.de" rel="alternate" type="text/html"/>
  <author>
    <name>Michael Großklaus</name>
    <email>mail@mgrossklaus.de</email>
  </author>
  <updated>2024-08-12T00:00:00Z</updated>
  <id>https://www.mgrossklaus.de</id>

   
  <entry>
    <title>Patterns for Memory Efficient DOM Manipulation with Modern Vanilla JavaScript</title>
    <link href="https://www.mgrossklaus.de/notes/patterns-for-memory-efficient-dom-manipulation.html" />
    <updated>2024-08-12T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/patterns-for-memory-efficient-dom-manipulation.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;&lt;a href=&quot;https://frontendmasters.com/blog/patterns-for-memory-efficient-dom-manipulation/&quot;&gt;https://frontendmasters.com/blog/patterns-for-memory-efficient-dom-manipulation/&lt;/a&gt;&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>`storage` event for localStorage updates</title>
    <link href="https://www.mgrossklaus.de/notes/storage-event-for-localstorage-updates.html" />
    <updated>2024-07-16T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/storage-event-for-localstorage-updates.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;There is a &lt;code&gt;storage&lt;/code&gt; event that gets fired when the local storage for a site is updated:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Listen for local storage changes on our theme key. This lets&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// one tab to be notified if the theme is changed in another,&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// and update itself accordingly.&lt;/span&gt;
window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;storage&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;key &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;LOCAL_STORAGE_KEY_THEME&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token function&quot;&gt;setThemeFromLocalStorageOrMediaPreference&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://brandur.org/fragments/dark-mode-notes#theme-other-tabs&quot;&gt;https://brandur.org/fragments/dark-mode-notes#theme-other-tabs&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>Content hiding techniques</title>
    <link href="https://www.mgrossklaus.de/notes/content-hiding-techniques.html" />
    <updated>2024-06-13T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/content-hiding-techniques.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;&lt;a href=&quot;https://practical-accessibility.today/code/hiding-techniques/&quot;&gt;https://practical-accessibility.today/code/hiding-techniques/&lt;/a&gt; by &lt;a href=&quot;https://sarasoueidan.com/&quot;&gt;Sara Soueidan&lt;/a&gt;&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>WCAG simplified</title>
    <link href="https://www.mgrossklaus.de/notes/wcag-simplified.html" />
    <updated>2024-02-12T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/wcag-simplified.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;Build and test against WCAG consistently. Understand each success criterion&#39;s meaning and how to be accessible: &lt;a href=&quot;https://thisiswcag.com/&quot;&gt;https://thisiswcag.com&lt;/a&gt;&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>Native browser spinner for asynchronous operations</title>
    <link href="https://www.mgrossklaus.de/notes/native-browser-spinner-for-asynchronous-operations.html" />
    <updated>2023-07-17T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/native-browser-spinner-for-asynchronous-operations.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;showLoading&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;promise&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	navigation&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;navigate&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		event&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;intercept&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token literal-property property&quot;&gt;scroll&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;manual&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
			&lt;span class=&quot;token function-variable function&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; promise&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;once&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; navigation&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;navigate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;location&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;href&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;finished
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// show browser loading UI&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;showLoading&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Promise&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;r&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1500&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://notes.zander.wtf/notes/browser-loading-state/&quot;&gt;https://notes.zander.wtf/notes/browser-loading-state/&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>YAML indicators for multiline strings</title>
    <link href="https://www.mgrossklaus.de/notes/yaml-indicators-for-multiline-strings.html" />
    <updated>2023-02-24T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/yaml-indicators-for-multiline-strings.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;There are different indicators to define how multiline strings in YAML files behave.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Block style indicators&lt;/em&gt; describe how line breaks behave: With a &lt;code&gt;|&lt;/code&gt; (&lt;em&gt;literal&lt;/em&gt; style) they are kept as a line break.
With a &lt;code&gt;&amp;gt;&lt;/code&gt; (&lt;em&gt;folded&lt;/em&gt; style) they are converted to a space.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Block chomping indicators&lt;/em&gt; describe how line breaks at the end of the string behave: &lt;code&gt;+&lt;/code&gt; keeps all of them, &lt;code&gt;-&lt;/code&gt; removes them.
Without an indicator, one line break will be added to end of the string.&lt;/p&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://yaml-multiline.info&quot;&gt;https://yaml-multiline.info&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>Mobile First versus Shared First CSS</title>
    <link href="https://www.mgrossklaus.de/notes/2023-02-18-mobile-first-versus-shared-first-css/" />
    <updated>2023-02-18T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/2023-02-18-mobile-first-versus-shared-first-css/</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;In this post I want to give a short example why there is in my opinion a better way than using a &lt;em&gt;Mobile First&lt;/em&gt; approach when writing CSS. Please note that for simplification I will refer to &lt;em&gt;viewports&lt;/em&gt; as well as &lt;em&gt;media queries&lt;/em&gt;, but the same concept also applies to anything that can be controlled by media and container queries.&lt;/p&gt;
&lt;h2&gt;Mobile First&lt;/h2&gt;
&lt;p&gt;When Responsive Web Design and media queries became a thing, it was considered best practice to follow a &lt;em&gt;Mobile First&lt;/em&gt; approach when writing CSS for a website. Besides being aligned with the conceptual &lt;em&gt;Mobile First&lt;/em&gt; approach (where you — in simple terms — first make sure that your &lt;em&gt;content&lt;/em&gt; and its structure works on small devices), this also had the advantage to support browsers that did not yet support media queries. For those you got the mobile view.&lt;/p&gt;
&lt;p&gt;An example for that would be something like this simple page layout:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;aside&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;aside&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; flex&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;flex-direction&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; column&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;gap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1rem&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;/* medium */&lt;/span&gt;
&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;min-width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 40em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token selector&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token property&quot;&gt;gap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2rem&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;/* large */&lt;/span&gt;
&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;min-width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 60em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token selector&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token property&quot;&gt;flex-direction&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; row&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token property&quot;&gt;gap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 3rem&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token selector&quot;&gt;main&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token property&quot;&gt;flex&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 3&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token selector&quot;&gt;aside&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token property&quot;&gt;flex&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this case we first use &lt;code&gt;flex&lt;/code&gt; with columns, so that the &lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;aside&amp;gt;&lt;/code&gt; elements are below each other. This could be done without defining any CSS at all as they are both block elements, which would be rendered in a column anyway. But using &lt;code&gt;flex&lt;/code&gt; allows us to use &lt;code&gt;gap&lt;/code&gt; which is unfortunately not (yet) supported on block elements.&lt;/p&gt;
&lt;p&gt;In the first media query we increase this &lt;code&gt;gap&lt;/code&gt; for medium viewports.&lt;/p&gt;
&lt;p&gt;In the second media query we then set &lt;code&gt;flex-direction&lt;/code&gt; to its initial value &lt;code&gt;row&lt;/code&gt; , so the &lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;aside&amp;gt;&lt;/code&gt; elements are horizontally aligned. We also redeclare the &lt;code&gt;gap&lt;/code&gt;. Additionally we set &lt;code&gt;flex&lt;/code&gt; values for our two elements, so that &lt;code&gt;main&lt;/code&gt; takes more space than &lt;code&gt;aside&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If you look at the media query for medium viewports, you also notice that the media query only uses &lt;code&gt;min-width&lt;/code&gt;, so it is basically open ended and has no limit in terms of width. As you can see all we do in there is defining the &lt;code&gt;gap&lt;/code&gt; (for medium viewports), which we then overwrite again in the next media query (for large viewports).&lt;/p&gt;
&lt;p&gt;Besides the fact that it is not necessary anymore to go for a &lt;em&gt;Mobile First&lt;/em&gt; approach when it comes to CSS since media queries have been supported in all major browsers for a long time now, this approach also comes with two downsides:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Error prone:&lt;/strong&gt; If we want to add or change CSS for small or medium viewports, this CSS would bleed up, i.e. affecting larger viewports. This means we might introduce a bug, if we do not undo our changes for larger viewports. So, writing CSS code this way is very error-prone because changes might have unintended side-effects.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Difficult to inspect:&lt;/strong&gt; Inspecting why something behaves a certain way becomes more difficult. You end up with properties being overwritten, sometimes even multiple times. This can be seen when looking at the devtools where you would have lots of striked through properties. This is a screenshot of the devtools for large viewports:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://www.mgrossklaus.de/notes/2023-02-18-mobile-first-versus-shared-first-css/devtools-mobile-first.png&quot; alt=&quot;Screenshot of Safari devtools showing multiple striked through CSS declarations&quot; /&gt;
This is of course a short example, but imagine how this quickly escalates in an actual, more complex website. Seeing lots of overwritten properties like this is usually a good indicator that the CSS is prone to errors and might be worth a refactoring.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Shared First&lt;/h2&gt;
&lt;p&gt;So, how can we change our CSS to avoid these issues? What works really well for me is an approach that I would call, for lack of a better name, &lt;em&gt;Shared First&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;In this approach you only define CSS outside of media queries which should be &lt;strong&gt;shared by viewport sizes&lt;/strong&gt; and everything that should only be applied for certain viewport sizes goes into a media query that matches only that viewport size:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; flex&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;/* small + medium */&lt;/span&gt;
&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;max-width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 59.96875em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token selector&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token property&quot;&gt;flex-direction&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; column&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;/* small */&lt;/span&gt;
&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;max-width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 39.96875em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token selector&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token property&quot;&gt;gap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1rem&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;/* medium */&lt;/span&gt;
&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;min-width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 40em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;max-width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 59.96875em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token selector&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token property&quot;&gt;gap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2rem&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;/* large */&lt;/span&gt;
&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;min-width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 60em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token selector&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token property&quot;&gt;gap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 3rem&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token selector&quot;&gt;main&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token property&quot;&gt;flex&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 3&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token selector&quot;&gt;aside&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token property&quot;&gt;flex&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let&#39;s break this down:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Outside of all media queries, we first define everything, that is shared: in our case, all we do is turning &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; into a &lt;code&gt;flex&lt;/code&gt; element as this is the only thing that is shared throughout all viewport sizes.&lt;/li&gt;
&lt;li&gt;The first media queries covers small and medium viewports. In there all we define is that for these sizes we want to use a column layout. This makes sure that we later do not have to revert this.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;gap&lt;/code&gt; is then defined in each media query: We explicitely define it once for small, once for medium and once for large viewports. This allows us to change the values without accidentally affecting other viewport sizes.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Admittedly, these are a few more lines than in the &lt;em&gt;Mobile First&lt;/em&gt; approach, but shorter code does not always mean better code. Instead shorter code might be harder to understand and more difficult to maintain.&lt;/p&gt;
&lt;h3&gt;Why does this work better?&lt;/h3&gt;
&lt;p&gt;First of all, by declaring CSS only for the resolutions we actually need it, we avoid side effects.
Let&#39;s say on small viewports we now want to change the font size, we can do that by adding it to the media query for small viewports without any side effects. In the &lt;em&gt;Mobile First&lt;/em&gt; approach this would have caused a regression if we did not revert that definition for larger viewports.&lt;/p&gt;
&lt;p&gt;Second of all, inspecting this is much easier. This is how devtools would look for our &lt;em&gt;Shared First&lt;/em&gt; example for large viewports:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://www.mgrossklaus.de/notes/2023-02-18-mobile-first-versus-shared-first-css/devtools-shared-first.png&quot; alt=&quot;Screenshot of Safari devtools showing only to CSS declarations, none of them are striked throught&quot; /&gt;
Much cleaner, isn&#39;t it?&lt;/p&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;Using a &lt;em&gt;Mobile First&lt;/em&gt; approach when writing CSS is error prone and often leads to unintended side effects. It is also more difficult to investigate what is happening in the CSS.
This can be avoided using a &lt;em&gt;Shared First&lt;/em&gt; approach where only the CSS, that should be applied for all viewport sizes, is defined outside of media queries. The CSS, that should only be applied for certain viewport sizes, will go into media queries that are defined to match only those exact viewport sizes.&lt;/p&gt;
&lt;h2&gt;Disclaimer&lt;/h2&gt;
&lt;p&gt;I know that there might be shorter and easier ways to write this layout example using custom properties, but this is simply an example to illustrate the issues and benefits.&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>Implementing a theme toggle with HTML and CSS only (almost)</title>
    <link href="https://www.mgrossklaus.de/notes/implementing-a-theme-toggle-with-html-and-css-only-almost.html" />
    <updated>2023-02-04T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/implementing-a-theme-toggle-with-html-and-css-only-almost.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;Implementing a light and dark theme based on the user&#39;s OS settings has become quite popular.
But often users just want their OS to be dark, while they prefer reading a website with a light background, for example.
It is therefore considered good practice to offer a theme toggle, that allows the user to change the theme of the website
regardless of their OS theme.&lt;/p&gt;
&lt;p&gt;To implement that, we would usually have some HTML like the following:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;form&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;fieldset&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;legend&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Color scheme&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;legend&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;input&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;radio&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;auto&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme-auto&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;checked&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;label&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme-auto&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;auto&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;label&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;input&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;radio&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;light&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme-light&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;label&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme-light&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;light&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;label&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;input&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;radio&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;dark&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme-dark&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;label&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme-dark&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;dark&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;label&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;fieldset&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;form&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Using JavaScript we would then listen to the &lt;code&gt;change&lt;/code&gt; event of those inputs and add a class to the &lt;code&gt;html&lt;/code&gt; or &lt;code&gt;body&lt;/code&gt; node.
Based on that class, we would style the page accordingly:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.theme-dark&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	…
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Using the &lt;code&gt;:has()&lt;/code&gt; pseudo-class, we can be implement this theme toggle without JavaScript. Instead of using a class, we can do this:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;html:has([name=&quot;theme&quot;][value=&quot;dark&quot;]:checked)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	…
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To make sure that the user does not have to change the theme on every page visit, we should of course still use some JavaScript:&lt;/p&gt;
&lt;p&gt;We save the selection in the &lt;code&gt;localStorage&lt;/code&gt;, but then — instead of adding a theme class — we simply set the &lt;code&gt;checked&lt;/code&gt; attribute
of the correct input in the theme toggle.
Ideally we do this in an inline script (as opposed to some asynchronously fetched script) to avoid any possible layout flickering.&lt;/p&gt;
&lt;h2&gt;Complete example&lt;/h2&gt;
&lt;h3&gt;HTML&lt;/h3&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;form&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;fieldset&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;ThemeToggle&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;legend&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;ThemeToggle-title&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Color scheme&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;legend&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;input&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;radio&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;auto&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme-auto&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;checked&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;label&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme-auto&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;auto&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;label&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;input&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;radio&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;light&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme-light&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;label&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme-light&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;light&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;label&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;input&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;radio&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;dark&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme-dark&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;label&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;theme-dark&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;dark&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;label&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;fieldset&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;form&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;span class=&quot;token language-javascript&quot;&gt;
	&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;renderTheme&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;theme&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;auto&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;light&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;dark&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;includes&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;theme&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

		&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; checkedInput &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;theme-&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;theme&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

		&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;checkedInput&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			checkedInput&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;checked &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token function&quot;&gt;renderTheme&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;localStorage&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;theme&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;CSS&lt;/h3&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	… &lt;span class=&quot;token comment&quot;&gt;/* styling for light theme */&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;html:has([name=&quot;theme&quot;][value=&quot;light&quot;]:checked)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	… &lt;span class=&quot;token comment&quot;&gt;/* styling for light theme */&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;prefers-color-scheme&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; dark&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token selector&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		… &lt;span class=&quot;token comment&quot;&gt;/* styling for dark theme */&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;html:has([name=&quot;theme&quot;][value=&quot;dark&quot;]:checked)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	… &lt;span class=&quot;token comment&quot;&gt;/* styling for dark theme */&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;JavaScript&lt;/h3&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelectorAll&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;.ThemeToggle input&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	input&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;change&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; onThemeChange&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;onThemeChange&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; target &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; value &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; target&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;token function&quot;&gt;renderTheme&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token function&quot;&gt;saveTheme&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;saveTheme&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;theme&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;theme &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;auto&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		localStorage&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;removeItem&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;theme&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		localStorage&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setItem&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;theme&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; theme&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Browser support&lt;/h2&gt;
&lt;p&gt;At the time of writing this (04.02.2023), &lt;code&gt;:has()&lt;/code&gt; is supported by all major browsers except for Firefox.&lt;/p&gt;
&lt;p&gt;To make sure this also works in Firefox, you can simply combine this approach with the
class-based approach mentioned earlier — and throw it away as soon as Firefox turns green! :)
(&lt;a href=&quot;https://caniuse.com/css-has&quot;&gt;:has() on caniuse.com&lt;/a&gt;).&lt;/p&gt;
&lt;h3&gt;Important&lt;/h3&gt;
&lt;p&gt;Just be aware that you cannot combine both selectors as &lt;code&gt;:has()&lt;/code&gt; is invalid in Firefox. This means that
the following snippet would not work at all in Firefox:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.theme-dark,
html:has([name=&quot;theme&quot;][value=&quot;dark&quot;]:checked)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	… &lt;span class=&quot;token comment&quot;&gt;/* styling for dark theme */&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Instead you have to use the selectors separately:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.theme-dark&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	… &lt;span class=&quot;token comment&quot;&gt;/* styling for dark theme */&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;html:has([name=&quot;theme&quot;][value=&quot;dark&quot;]:checked)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	… &lt;span class=&quot;token comment&quot;&gt;/* styling for dark theme */&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Optimizing CSS for theme toggles&lt;/h2&gt;
&lt;p&gt;Since it can be a bit cumbersome to write CSS for theme toggles as you would have to duplicate some code in your CSS,
&lt;a href=&quot;https://www.fynn.be/&quot;&gt;Fynn&lt;/a&gt; wrote down a nice approach using custom properties, which I highly recommend:
&lt;a href=&quot;https://fynn.be/blog/css-custom-property-toggles-themes/&quot;&gt;CSS Custom Property toggles for themes&lt;/a&gt;.&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>My workflow for storing notes as Markdown files</title>
    <link href="https://www.mgrossklaus.de/notes/2022-12-20-my-workflow-for-storing-notes-as-markdown-files/" />
    <updated>2022-12-20T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/2022-12-20-my-workflow-for-storing-notes-as-markdown-files/</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;I have a lot of private notes regarding all kinds of topics: web development, my hobbies, finances, things to buy, work-related tasks, and so on. These notes are probably the most important things I have digitally (besides thousands of pictures) and up until recently they were stored in a PostgreSQL database. This had always been a compromise though. What I actually wanted was to store them in Markdown files on my computer.&lt;/p&gt;
&lt;p&gt;I just love Markdown for multiple reasons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Its simplicity when it comes to writing down any kind of information.&lt;/li&gt;
&lt;li&gt;It can easily be converted to HTML.&lt;/li&gt;
&lt;li&gt;It can be stored anywhere (and especially locally on my computer).&lt;/li&gt;
&lt;li&gt;It is an open standard which is supported by many tools.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The reason I want them to be stored on my computer is independence: I don&#39;t want to rely on some 3rd party infrastructure for something such important.&lt;/p&gt;
&lt;h2&gt;Using Obsidian for working with my notes&lt;/h2&gt;
&lt;p&gt;What I was missing until now was a tool for macOS that makes it easy to create and read my notes — until I stumbled upon &lt;a href=&quot;https://obsidian.md/&quot;&gt;Obsidian&lt;/a&gt;. While I am not super fond of its UI (it looks a little bit too techy for me), it did almost everything out of the box the way I wanted it to. Unfortunately it is not open source, but it has a very big amount of community plugins. The small things that were not possible with Obsidian&#39;s core plugins, were easy to do with their community plugins: for example keeping the file name in sync with the first heading in a Markdown file (&lt;a href=&quot;https://github.com/dvcrn/obsidian-filename-heading-sync&quot;&gt;Filename Heading Sync&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://www.mgrossklaus.de/notes/2022-12-20-my-workflow-for-storing-notes-as-markdown-files/obsidian.png&quot; alt=&quot;Screenshot of my notes in the Obsidian app&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;Using private and public notes together&lt;/h2&gt;
&lt;p&gt;Using Obsidian for my private notes would have already been enough for me, but then I thought it would be nice to use it for the notes on this website as well, since they are also written in Markdown. And while Obisidian supports multiple vaults (which is their name for a directory containing Markdown files), I wanted to avoid that as this opens multiple windows — which I don&#39;t like at all.&lt;/p&gt;
&lt;p&gt;What I did instead was to move my private notes into &lt;a href=&quot;https://github.com/mgrsskls/mgrossklaus.de/&quot;&gt;the repository of this website&lt;/a&gt; (which is built with &lt;a href=&quot;https://https//www.11ty.dev&quot;&gt;Eleventy&lt;/a&gt;), configure Eleventy so that it only uses my public notes and add the directory with the private notes to the &lt;code&gt;.gitignore&lt;/code&gt;, so I don&#39;t publish them on GitHub.&lt;br /&gt;
It does not matter at all to me where on my disk the private notes are stored as Obisidian abstracts that away and opens the vault automatically when restarting the app.&lt;/p&gt;
&lt;p&gt;Now I have one application that gives me all my notes, private and public, and a codebase that allows me to publish only the public ones.&lt;/p&gt;
&lt;h2&gt;Publishing public notes&lt;/h2&gt;
&lt;p&gt;The way I usually publish notes on this website is through GitHub directly: The GitHub Web UI allows you to create files and commit them in one go. This is super convenient as I don&#39;t have to open my editor, create a file, commit and then push it. Instead I bookmarked the URL for creating a new file in the correct directory (&lt;em&gt;https://github.com/mgrsskls/mgrossklaus.de/new/main/notes/webdev&lt;/em&gt; in my case), which brings me directly to GitHub&#39;s file editor. And as most of the notes I write are Markdown files without any additional files (images for example), using the GitHub Web UI is totally sufficient in most cases.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://www.mgrossklaus.de/notes/2022-12-20-my-workflow-for-storing-notes-as-markdown-files/github.png&quot; alt=&quot;Screenshot of the GitHub Web UI when creating a new note&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;Pulling notes from the repository&lt;/h2&gt;
&lt;p&gt;Of course the notes that I published via the GitHub Web UI would not be on my computer without pulling them into my local repository. As doing that how you would usually pull changes would be quite annoying, I created a small app that does that for me: In macOS&#39; Automator app, I created an &amp;quot;Application&amp;quot;, chose &amp;quot;Run shell script&amp;quot; and in there I simply use &lt;code&gt;cd&lt;/code&gt; to go into the directory of the repository and then run &lt;code&gt;git pull&lt;/code&gt;. I can then use &lt;a href=&quot;https://www.alfredapp.com/&quot;&gt;Alfred&lt;/a&gt; to quickly run the program, which happens completely in the background, so no windows open or anything like that.
This is of course does not handle any errors in case pulling fails for example, but in my case I don&#39;t really need that.&lt;/p&gt;
&lt;h2&gt;Syncing with an iOS app&lt;/h2&gt;
&lt;p&gt;One thing that would be nice to have is being able to maintain those notes on my phone as well. Obsidian offers encrypted synchronisation for that, but as the code is not open source, I don&#39;t want to rely on that. There are multiple community plugins that allow you to do that (using services like Dropbox or a CouchDB for example), so I might look into that at some point (probably using a self hosted database).&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>change event for media queries</title>
    <link href="https://www.mgrossklaus.de/notes/change-event-for-media-queries.html" />
    <updated>2022-12-20T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/change-event-for-media-queries.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;There is a &lt;code&gt;change&lt;/code&gt; event that can be used to listen to media query changes:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; mediaQuery &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;matchMedia&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;…&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

mediaQuery&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;change&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  …
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>translate attribute</title>
    <link href="https://www.mgrossklaus.de/notes/translate-attribute.html" />
    <updated>2022-12-18T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/translate-attribute.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;There is a &lt;code&gt;translate&lt;/code&gt; attribute telling browsers not to translate the content if using &lt;code&gt;&amp;quot;no&amp;quot;&lt;/code&gt;:
&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/translate&quot;&gt;https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/translate&lt;/a&gt;&lt;/p&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://twitter.com/spellacy/status/1604193752431661056&quot;&gt;https://twitter.com/spellacy/status/1604193752431661056&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>Detecting capslock with JavaScript</title>
    <link href="https://www.mgrossklaus.de/notes/detecting-caps-lock-with-javascript.html" />
    <updated>2022-12-12T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/detecting-caps-lock-with-javascript.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;keydown&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; detectCapsLock&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;keyup&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; detectCapsLock&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;detectCapsLock&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getModifierState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;CapsLock&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// caps lock is on&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// caps lock is off&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://iamkate.com/code/caps-lock/&quot;&gt;https://iamkate.com/code/caps-lock/&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>Fluid type and size calculator</title>
    <link href="https://www.mgrossklaus.de/notes/fluid-type-and-size-calculator.html" />
    <updated>2022-11-18T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/fluid-type-and-size-calculator.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;&lt;a href=&quot;https://utopia.fyi/&quot;&gt;https://utopia.fyi&lt;/a&gt;&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>Web Share API</title>
    <link href="https://www.mgrossklaus.de/notes/web-share-api.html" />
    <updated>2022-11-15T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/web-share-api.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;There is an API to trigger the native sharing function of the OS:
&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Web_Share_API&quot;&gt;https://developer.mozilla.org/en-US/docs/Web/API/Web_Share_API&lt;/a&gt;&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>Accessibility testing guide</title>
    <link href="https://www.mgrossklaus.de/notes/accessibility-testing-guide.html" />
    <updated>2022-11-11T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/accessibility-testing-guide.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;&lt;a href=&quot;https://github.com/alphagov/wcag-primer/wiki&quot;&gt;https://github.com/alphagov/wcag-primer/wiki&lt;/a&gt;
&amp;quot;outlines some approaches for testing websites and applications against the Web Content Accessibility Guidelines (WCAG) 2.1 AA Level&amp;quot;.&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>Modals are not dialogs</title>
    <link href="https://www.mgrossklaus.de/notes/modals-are-not-dialogs.html" />
    <updated>2022-11-09T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/modals-are-not-dialogs.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;Modals are not another noun for dialogs, but an adjective describing certain types of dialogs:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Basically, when a modal component is open, it is the only thing that is &lt;em&gt;not&lt;/em&gt; inert.
Only the modal content can be interacted rest with, &lt;em&gt;the rest of the page&lt;/em&gt; or application is made inert.
Inert content is content that users cannot interact with. It is only really there visually,
but you cannot Tab to it, click it, scroll it or access the content via assistive technologies.&lt;/p&gt;
&lt;p&gt;— &lt;cite&gt;Hidde de Vries&lt;/cite&gt;&lt;/p&gt;
&lt;/blockquote&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://hidde.blog/dialog-modal-popover-differences/&quot;&gt;https://hidde.blog/dialog-modal-popover-differences/&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>Making the subtree of a hidden element visible</title>
    <link href="https://www.mgrossklaus.de/notes/making-the-subtree-of-a-hidden-element-visible.html" />
    <updated>2022-11-07T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/making-the-subtree-of-a-hidden-element-visible.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;If an element is hidden via &lt;code&gt;visibility: hidden&lt;/code&gt;, its subtree can be made visible by using &lt;code&gt;visibility: visible&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;parent&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;visibility&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; hidden&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;child&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;visibility&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; visible&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://www.scottohara.me/blog/2022/11/07/responsive-accessibility.html&quot;&gt;https://www.scottohara.me/blog/2022/11/07/responsive-accessibility.html&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>Gradient border</title>
    <link href="https://www.mgrossklaus.de/notes/gradient-border.html" />
    <updated>2022-11-07T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/gradient-border.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;&lt;strong&gt;Without rounded corners:&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;border&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; solid 0.25rem&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token property&quot;&gt;border-image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;linear-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;to bottom right&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; darkmagenta&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; aquamarine&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;With rounded corners:&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;border&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; solid 0.25rem transparent&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;linear-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;white&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; white&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; padding-box&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 
  &lt;span class=&quot;token function&quot;&gt;linear-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;to bottom right&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; darkmagenta&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; aquamarine&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; border-box&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Drawback: You need to set a solid color as background, so it cannot be transparent.&lt;/p&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://twitter.com/argyleink/status/1589657198766231552&quot;&gt;https://twitter.com/argyleink/status/1589657198766231552&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>Accessible color combinations</title>
    <link href="https://www.mgrossklaus.de/notes/accessible-color-combinations.html" />
    <updated>2022-10-28T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/accessible-color-combinations.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;&lt;a href=&quot;https://randoma11y.com/&quot;&gt;https://randoma11y.com&lt;/a&gt; creates random accessible color combinations.&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>Better error messages</title>
    <link href="https://www.mgrossklaus.de/notes/2022-10-18-better-error-messages/" />
    <updated>2022-10-18T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/2022-10-18-better-error-messages/</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;&lt;img src=&quot;https://www.mgrossklaus.de/notes/2022-10-18-better-error-messages/better-error-message.png&quot; alt=&quot;Example of a good error message showing the different parts of it&quot; /&gt;&lt;/p&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://wix-ux.com/when-life-gives-you-lemons-write-better-error-messages-46c5223e1a2f&quot;&gt;https://wix-ux.com/when-life-gives-you-lemons-write-better-error-messages-46c5223e1a2f&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>Minimal social markup</title>
    <link href="https://www.mgrossklaus.de/notes/minimal-social-markup.html" />
    <updated>2022-07-22T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/minimal-social-markup.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;meta&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;twitter:card&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;summary_large_image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;meta&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;property&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;og:title&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;This is a test title&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;meta&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;property&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;og:description&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;description&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;This is a test description.&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;meta&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;property&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;og:image&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://hell.meiert.org/core/png/test.png&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://meiert.com/en/blog/minimal-social-markup/&quot;&gt;https://meiert.com/en/blog/minimal-social-markup/&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>Lite youtube embed</title>
    <link href="https://www.mgrossklaus.de/notes/lite-youtube-embed.html" />
    <updated>2022-03-09T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/lite-youtube-embed.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;Youtube embeds are not very performant, so here is a web component with focus on performance:
&lt;a href=&quot;https://github.com/paulirish/lite-youtube-embed&quot;&gt;https://github.com/paulirish/lite-youtube-embed&lt;/a&gt;&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>Accessibility outline bookmarklet</title>
    <link href="https://www.mgrossklaus.de/notes/accessibility-outline-bookmarklet.html" />
    <updated>2022-02-08T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/accessibility-outline-bookmarklet.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;Quickly analyze landmarks, headings and links of a website:
&lt;a href=&quot;https://xi.github.io/a11y-outline/&quot;&gt;https://xi.github.io/a11y-outline/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;My favourite bookmarklet.&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>SVGs in high contrast mode</title>
    <link href="https://www.mgrossklaus.de/notes/svgs-in-high-contrast-mode.html" />
    <updated>2022-02-06T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/svgs-in-high-contrast-mode.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;forced-colors&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; active&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;svg&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; CanvasText&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token selector&quot;&gt;a svg&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; LinkText&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>Dynamic search results for screen readers</title>
    <link href="https://www.mgrossklaus.de/notes/dynamic-search-results-for-screen-readers.html" />
    <updated>2022-02-06T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/dynamic-search-results-for-screen-readers.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;This to consider for screen readers when implementing dynamic search results:
&lt;a href=&quot;https://www.scottohara.me/blog/2022/02/05/dynamic-results.html&quot;&gt;https://www.scottohara.me/blog/2022/02/05/dynamic-results.html&lt;/a&gt;&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>Order in the head</title>
    <link href="https://www.mgrossklaus.de/notes/order-in-the-head.html" />
    <updated>2021-09-22T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/order-in-the-head.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;meta&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;title&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
preconnect
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
CSS with @imports
sync JS
sync CSS
preload
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;defer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
prefetch / prerender
everything else (SEO, icons, open graph)&lt;/code&gt;&lt;/pre&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://twitter.com/smashingmag/status/1440697011985018881&quot;&gt;https://twitter.com/smashingmag/status/1440697011985018881&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>Remove blank space from SVGs</title>
    <link href="https://www.mgrossklaus.de/notes/remove-blank-space-from-svgs.html" />
    <updated>2021-04-23T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/remove-blank-space-from-svgs.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;SVG Crop: &lt;a href=&quot;https://svgcrop.com/&quot;&gt;https://svgcrop.com&lt;/a&gt;&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>An alt decision tree</title>
    <link href="https://www.mgrossklaus.de/notes/an-alt-decision-tree.html" />
    <updated>2021-04-16T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/an-alt-decision-tree.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;A few questions to help you decide if an image should have an &lt;code&gt;alt&lt;/code&gt; value or not:
&lt;a href=&quot;https://www.w3.org/WAI/tutorials/images/decision-tree/&quot;&gt;https://www.w3.org/WAI/tutorials/images/decision-tree/&lt;/a&gt;&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>inputmode attribute</title>
    <link href="https://www.mgrossklaus.de/notes/inputmode-attribute.html" />
    <updated>2021-03-18T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/inputmode-attribute.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;The inputmode attribute allows to define the type of keyboard which is shown when focusing an input.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Values:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;none&lt;/li&gt;
&lt;li&gt;text&lt;/li&gt;
&lt;li&gt;decimal&lt;/li&gt;
&lt;li&gt;numeric&lt;/li&gt;
&lt;li&gt;tel&lt;/li&gt;
&lt;li&gt;search&lt;/li&gt;
&lt;li&gt;email&lt;/li&gt;
&lt;li&gt;url&lt;/li&gt;
&lt;/ul&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode&quot;&gt;https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>Numbers with same width</title>
    <link href="https://www.mgrossklaus.de/notes/numbers-with-same-width.html" />
    <updated>2021-03-01T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/numbers-with-same-width.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;With the following CSS we can make sure that numbers are all rendered using the same width (similar to monospaced fonts):&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;font-variant-numeric&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; tabular-nums&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This can be helpful for example for tables or when displaying prices below each other.&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>JavaScript loading priorities in Chrome</title>
    <link href="https://www.mgrossklaus.de/notes/javascript-loading-priorities-in-chrome.html" />
    <updated>2021-03-01T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/javascript-loading-priorities-in-chrome.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;Table about loading priorities of render blocking, async, defer, prefetched etc scripts in Chrome:
&lt;a href=&quot;https://addyosmani.com/blog/script-priorities/&quot;&gt;https://addyosmani.com/blog/script-priorities/&lt;/a&gt;&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>enterkeyhint attribute</title>
    <link href="https://www.mgrossklaus.de/notes/enterkeyhint-attribute.html" />
    <updated>2021-03-01T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/enterkeyhint-attribute.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;The &lt;code&gt;enterkeyhint&lt;/code&gt; content attribute is an attribute that specifies what action label (or icon) to present for the enter key on virtual keyboards.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Values:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;enter&lt;/li&gt;
&lt;li&gt;done&lt;/li&gt;
&lt;li&gt;go&lt;/li&gt;
&lt;li&gt;next&lt;/li&gt;
&lt;li&gt;previous&lt;/li&gt;
&lt;li&gt;search&lt;/li&gt;
&lt;li&gt;send&lt;/li&gt;
&lt;/ul&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-enterkeyhint-attribute&quot;&gt;https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-enterkeyhint-attribute&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>Animation principles</title>
    <link href="https://www.mgrossklaus.de/notes/animation-principles.html" />
    <updated>2021-03-01T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/animation-principles.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;The following principles are valid for all kinds of animations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Appearing: ease-out, longer animation&lt;/li&gt;
&lt;li&gt;Disappearing: ease-in, shorter animation&lt;/li&gt;
&lt;li&gt;Moving: ease-in-out&lt;/li&gt;
&lt;li&gt;Long distance / big screen: longer animation&lt;/li&gt;
&lt;li&gt;Short distance / small screen: shorter animation&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When fading in list items, that means multiple items:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;overlapping, not one after, not at the same time&lt;/li&gt;
&lt;li&gt;vertical: top to bottom&lt;/li&gt;
&lt;li&gt;grid: top left to bottom right&lt;/li&gt;
&lt;/ul&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://uxdesign.cc/the-ultimate-guide-to-proper-use-of-animation-in-ux-10bd98614fa9&quot;&gt;https://uxdesign.cc/the-ultimate-guide-to-proper-use-of-animation-in-ux-10bd98614fa9&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>Language-specific quotation marks</title>
    <link href="https://www.mgrossklaus.de/notes/language-specific-quotation-marks.html" />
    <updated>2021-02-28T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/language-specific-quotation-marks.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;blockquote::before&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; open-quote&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;blockquote::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; close-quote&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://www.stefanjudis.com/today-i-learned/how-to-use-language-dependent-quotes-in-css/&quot;&gt;https://www.stefanjudis.com/today-i-learned/how-to-use-language-dependent-quotes-in-css/&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>Print in landscape</title>
    <link href="https://www.mgrossklaus.de/notes/print-in-landscape.html" />
    <updated>2021-02-16T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/print-in-landscape.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; print&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@page&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; landscape&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At the time of the tweet, it worked in blink only.&lt;/p&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://twitter.com/mmatuzo/status/1361698055385399304&quot;&gt;https://twitter.com/mmatuzo/status/1361698055385399304&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>Accessibility checklist</title>
    <link href="https://www.mgrossklaus.de/notes/accessibility-checklist.html" />
    <updated>2021-02-08T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/accessibility-checklist.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;&lt;a href=&quot;https://www.magentaa11y.com/web/&quot;&gt;https://www.magentaa11y.com/web/&lt;/a&gt; lets you create a comprehensive testing guide for all elements on your page.&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>Minimal favicon markup</title>
    <link href="https://www.mgrossklaus.de/notes/minimal-favicon-markup.html" />
    <updated>2020-12-25T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/minimal-favicon-markup.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;link&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;icon&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;/favicon.ico&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;any&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- 32×32 --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;link&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;icon&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;/icon.svg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;image/svg+xml&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;link&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;apple-touch-icon&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;/apple-touch-icon.png&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- 180×180 --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;link&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;manifest&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;/manifest.webmanifest&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-json&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// manifest.webmanifest&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;&quot;icons&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&quot;src&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/icon-192.png&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;image/png&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&quot;sizes&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;192x192&quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&quot;src&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/icon-512.png&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;image/png&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&quot;sizes&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;512x512&quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://evilmartians.com/chronicles/how-to-favicon-in-2021-six-files-that-fit-most-needs&quot;&gt;https://evilmartians.com/chronicles/how-to-favicon-in-2021-six-files-that-fit-most-needs&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>CSS Grid tiles</title>
    <link href="https://www.mgrossklaus.de/notes/css-grid-tiles.html" />
    <updated>2020-12-22T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/css-grid-tiles.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;I can never remember this snippet:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; grid&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token property&quot;&gt;grid-template-columns&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;repeat&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;auto-fit&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;minmax&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;100%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 20rem&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 1fr&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will create equally sized columns, where &lt;code&gt;20rem&lt;/code&gt; is the minimum width of the columns.
When they would become smaller than this, the last entry in a row moves to the next row.&lt;/p&gt;
&lt;p&gt;We use &lt;code&gt;min(100%, 20rem)&lt;/code&gt; to avoid overflow when the container is smaller than &lt;code&gt;20rem&lt;/code&gt;.&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>Utility class for hiding elements visually</title>
    <link href="https://www.mgrossklaus.de/notes/visually-hidden-utility.html" />
    <updated>2020-12-15T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/visually-hidden-utility.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;Hiding elements visually, but keeping them for screen readers:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.u-hiddenVisually&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -1px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;white-space&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; nowrap&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;clip-path&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;inset&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;100%&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;clip&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0 0 0 0&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;overflow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; hidden&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;My by far most used utility class.&lt;/p&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://allyjs.io/tutorials/hiding-elements.html#2017-edition-of-visuallyhidden&quot;&gt;https://allyjs.io/tutorials/hiding-elements.html#2017-edition-of-visuallyhidden&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>URL encoder for SVG</title>
    <link href="https://www.mgrossklaus.de/notes/url-encoder-for-svg.html" />
    <updated>2020-12-15T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/url-encoder-for-svg.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;If you want to use an inline SVG in a CSS file: &lt;a href=&quot;https://yoksel.github.io/url-encoder/&quot;&gt;https://yoksel.github.io/url-encoder/&lt;/a&gt;&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>System fonts</title>
    <link href="https://www.mgrossklaus.de/notes/system-fonts.html" />
    <updated>2020-12-15T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/system-fonts.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;font-family&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -apple-system&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; BlinkMacSystemFont&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Segoe UI&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Roboto&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Helvetica&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  Arial&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; sans-serif&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;font&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1rem/1.2 BlinkMacSystemFont&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; -apple-system&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Segoe UI&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Roboto&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Helvetica&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  Arial&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; sans-serif&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The shorthand version cannot start with &lt;code&gt;-apple-system&lt;/code&gt;!&lt;/p&gt;

      
        &lt;p&gt;Source: &lt;a href=&quot;https://booking.design/implementing-system-fonts-on-booking-com-a-lesson-learned-bdc984df627f&quot;&gt;https://booking.design/implementing-system-fonts-on-booking-com-a-lesson-learned-bdc984df627f&lt;/a&gt;&lt;/p&gt;
      
    </content>
  </entry>
   
  <entry>
    <title>Google Fonts Downloader</title>
    <link href="https://www.mgrossklaus.de/notes/google-fonts-downloader.html" />
    <updated>2020-12-15T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/google-fonts-downloader.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;Google Fonts can and should be served locally instead of from google. This tool can be used to download the font files: &lt;a href=&quot;https://google-webfonts-helper.herokuapp.com/fonts&quot;&gt;https://google-webfonts-helper.herokuapp.com/fonts&lt;/a&gt;&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>Reducing the file size of open source fonts</title>
    <link href="https://www.mgrossklaus.de/notes/reducing-the-size-of-open-source-fonts.html" />
    <updated>2020-01-12T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/reducing-the-size-of-open-source-fonts.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;I was recently working on the relaunch of my website and wanted to include the open source font &lt;a href=&quot;https://rsms.me/inter/&quot;&gt;Inter&lt;/a&gt;. Unfortunately, even the &lt;em&gt;woff2&lt;/em&gt; versions of each different font style were at least 100kb large. As I wanted to use three font styles, this was, of course, way too much.&lt;/p&gt;
&lt;p&gt;Fortunately, I knew that it is possible to reduce the file size by only using certain characters. After a quick search I stumbled upon &lt;a href=&quot;https://fontforge.org/&quot;&gt;FontForge&lt;/a&gt;, which allows you to edit all sorts of things in open source fonts (I honestly do not have a clue what most of them are).
I opened the font files and saw that all kinds of characters (romanian, greek, kyrillic and other letters, characters for spacings, mathematical characters and so on) were included. Since my website does not have any user generated content, I knew pretty well what kind of characters I would need. Especially for bold and italic font styles, the amount of necessary characters is very limited. That way I was able to remove most of the characters and decrease the total size of all font files &lt;strong&gt;from 314kb to 39kb&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The steps to do that are the following:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Open a font file via &lt;em&gt;File&lt;/em&gt; → &lt;em&gt;Open&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Go to &lt;em&gt;Element&lt;/em&gt; → &lt;em&gt;Font Info&lt;/em&gt; (opens a new window) → &lt;em&gt;Unicode Ranges&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Select an entry in the list&lt;/li&gt;
&lt;li&gt;In the other window deselect the characters you want to keep and remove the selected characters via &lt;em&gt;Encoding&lt;/em&gt; → &lt;em&gt;Detach &amp;amp; Remove Glyhphs…&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Repeat that for every entry in the &lt;em&gt;Unicode Ranges&lt;/em&gt; list&lt;/li&gt;
&lt;li&gt;Create a new font file via &lt;em&gt;File&lt;/em&gt; → &lt;em&gt;Generate Fonts…&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Admittedly, the UX could be a bit better and depending on your font files, this can be quite time-consuming. Nevertheless, it is fairly easy with &lt;em&gt;FontForge&lt;/em&gt; to remove characters from a font file and the results are definitely worth it.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note:&lt;/em&gt; At the time of writing this, the security restrictions on macOS Catalina do not allow you to open font files from your &amp;quot;Downloads&amp;quot;, &amp;quot;Documents&amp;quot; and &amp;quot;Desktop&amp;quot; folders. Move the font files in any other folder if &lt;em&gt;FontForge&lt;/em&gt; says &amp;quot;Unauthorized / Operation not permitted&amp;quot;. See also &lt;a href=&quot;https://github.com/fontforge/fontforge/issues/4082&quot;&gt;this issue&lt;/a&gt; on GitHub.&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>How to organize components</title>
    <link href="https://www.mgrossklaus.de/notes/how-to-organize-components.html" />
    <updated>2019-08-21T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/how-to-organize-components.html</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;Probably the most popular way of organizing your components is &lt;a href=&quot;http://bradfrost.com/blog/post/atomic-web-design/&quot;&gt;Atomic Design&lt;/a&gt; which was introduced by Brad Frost. I recently talked to a client of mine who said that they were succesfully using this methodology in all their projects and that it works really well for them. We had a short discussion about it as I was using it for a little bit as well, but was realizing pretty quickly that it would just not work for me. One reason for that is the following example: let&#39;s say you have two atoms; a button and an icon. If a button could also have an icon included, you would include an atom in another atom. While you could of course do that, it simply feels wrong to me (there are also no atoms in atoms in the nature, are there?).&lt;br /&gt;
That is just one example for why I came up with my own way of organizing my components.&lt;/p&gt;
&lt;p&gt;Of course, this is an ongoing process and every project is different, but I basically follow these rules:&lt;/p&gt;
&lt;h2&gt;Which directories should I use?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;templates&lt;/b&gt;&lt;br /&gt;The actual page templates.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;content&lt;/b&gt;&lt;br /&gt;Content components, which can be picked by the editors to fill pages with content.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;components&lt;/b&gt;&lt;br /&gt;All the remaining components that should not be used directly by editors (usually something like icons, buttons, etc.).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;When should I create a new component?&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;b&gt;When using code in multiple components.&lt;/b&gt;&lt;br /&gt;As soon as you use the same code (or slight variations of it) multiple times, make a component out of it.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;When rendering entries of a collection.&lt;/b&gt;&lt;br /&gt;If you render a collection, put the code for the entries (e.g. a teaser in a teaser list) in a separate component.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;When your component becomes too complex.&lt;/b&gt;&lt;br /&gt;This is a rather vague rule, but as soon as you have the feeling that your component becomes too complex, move logical parts into their own component.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;While the first rule is essential to avoid code duplication, the second and third rule are basically only for reducing the complexity of a component. In that case, I would call the components &amp;quot;sub components&amp;quot;.&lt;/p&gt;
&lt;h2&gt;Where should I put my sub components?&lt;/h2&gt;
&lt;p&gt;&lt;b&gt;In a directory in its parent component.&lt;/b&gt; As you are not using these components anywhere else, you can &amp;quot;scope&amp;quot; them by putting them in a sub directory of the actual component. This couples them tightly together and you can find all the code where you expect it.&lt;/p&gt;
&lt;h2&gt;What about components that are only used for templates?&lt;/h2&gt;
&lt;p&gt;Components, that are used by multiple templates and only by templates (e.g. header, footer, navigation), live in a subdirectory called &lt;code&gt;_includes/&lt;/code&gt; in the &lt;code&gt;templates/&lt;/code&gt; directory. I prefix the name of this directory with &lt;code&gt;_&lt;/code&gt; to show that it is some sort of a helper directory and not a template.&lt;/p&gt;
&lt;h2&gt;Example&lt;/h2&gt;
&lt;p&gt;The structure for an example project could look like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;├── components
│   ├── button
│   ├── icon
│   ├── image
│   ├── input
│   └── video
│
├── content
│   ├── cta
│   ├── gallery
│   │   ├── thumbnails
│   │   │   └── thumbnail
│   │   └── view
│   ├── rte
│   └── teaser-list
│       └── teaser
│
└── templates
    ├── _includes
    │   ├── footer
    │   ├── header
    │   └── navigation
    ├── homepage
    ├── standard
    └── checkout
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Again, this is nothing static and can be adapted for every project. Especially having a directory called &lt;code&gt;content&lt;/code&gt; with components that can be picked by editors, makes of course only sense when there is actually a CMS behind the scenes.&lt;/p&gt;
&lt;p&gt;If you are looking for a component library that plays well together with what I described in this post, feel free to check out &lt;a href=&quot;https://www.miyagi.dev/&quot;&gt;miyagi&lt;/a&gt;. It is a small node module that can be used to develop your components in isolation, no matter how you organize them.&lt;/p&gt;

      
    </content>
  </entry>
   
  <entry>
    <title>It does not always need to be the hippest code</title>
    <link href="https://www.mgrossklaus.de/notes/2019-08-12-it-does-not-always-need-to-be-the-hippest-code/" />
    <updated>2019-08-12T00:00:00Z</updated>
    <id>https://www.mgrossklaus.de/notes/2019-08-12-it-does-not-always-need-to-be-the-hippest-code/</id>
    <content
      xml:lang="en"
      type="html"
    >
      &lt;p&gt;One reason frontend development never becomes boring is the fact that the available technologies evolve rapidly. Browser vendors publish new features every few weeks, which makes it hard to stay up-to-date. At the same time it also makes development much easier as as a lot of functionality gets introduced by the new browser versions.&lt;/p&gt;
&lt;p&gt;When working on a project, it is now completely normal for me to implement its layout or features with Flexbox – or in some (still rare) cases with CSS Grid. Both make implementing most layouts much easier.&lt;/p&gt;
&lt;p&gt;The last project I worked on seemed to be such a case. One main element of it was a teaser list, which was supposed to look roughly like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://www.mgrossklaus.de/notes/2019-08-12-it-does-not-always-need-to-be-the-hippest-code/01.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The important part here was that the vertical space between the teasers was the same as the horizontal space.&lt;/p&gt;
&lt;p&gt;A colleague of mine started implementing it using CSS Grid, splitting it up in 12 columns, repeating rows, spanning content over multiple columns etc.. It worked well and using CSS Grid seemed like an obvious choice, but unfortunately we realized that the Internet Explorer (yes, we still had to support it) didn&#39;t support some of the CSS Grid features that were used. When my colleague went on holidays, I took over and tried to adapt the Grid solution, so that the IE would support it and we didn&#39;t have to throw away all the code. I realized though that it just wouldn&#39;t work, so I changed the code to use Flexbox which was actually not a big change. The main principle was the same: I just had to use some other attributes, doing minor tweaks and was done pretty quickly.&lt;/p&gt;
&lt;p&gt;Later on I realized that the horizontal space between the teasers was not correct yet. In my solution, the small teasers (2, 3, 5 and 6) were always aligned to the bottom of the big teasers (1 and 4). I had then pulled up teaser 2 and 5 with negative margins to put them in the right position. It looked perfect, but only due to some bad dummy data and other coincidences, making all the text boxes have the same height. Of course their height needed to be flexible though. So, with more realistic data it looked somewhat like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://www.mgrossklaus.de/notes/2019-08-12-it-does-not-always-need-to-be-the-hippest-code/02.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;As you can see here, the space between teaser 1 and 2 became too big because the text box in teaser 1 pushed down everything.&lt;/p&gt;
&lt;p&gt;My next idea was to take the text boxes of teaser 1 and 4 out of the flow, using &lt;code&gt;position: absolute&lt;/code&gt; to align it at the bottom of the big image and then pulling it down by a fixed value. That way all small teasers would align to the bottom of the big images and I could pull down the teaser 3 and 6 by the same value I pulled down the text boxes of teaser 1 and 4.&lt;br /&gt;
The designer was fine with this solution, but the variable height of the text boxes in teaser 1 and 4 was a problem again as they could theoratically become higher and higher. Especially on smaller viewports, the text box becomes too high quickly as it is narrower and expands to the top:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://www.mgrossklaus.de/notes/2019-08-12-it-does-not-always-need-to-be-the-hippest-code/03.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;I thought about it quite a bit and was sure that there is no way to implement this layout with flexbox.&lt;br /&gt;
Since there must be a way though, I was then trying to find another way to take the text boxes out of the elements flow – until &lt;code&gt;float&lt;/code&gt; came into my mind.&lt;br /&gt;
Having it used for many years for almost every layout I implemented, I had now almost completely forgotten it. Trying around a little bit, it took just a few minutes to actually have the complete solution. The steps for that roughly were:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Float the text boxes of teaser 1 to the right. That way the text box doesn&#39;t have any impact on the height of its containing teaser and the following teaser is automatically aligned to the bottom of the image (technically correct: to the bottom of the teaser).&lt;/li&gt;
&lt;li&gt;Now set &lt;code&gt;float: left&lt;/code&gt; on teaser 2 and &lt;code&gt;float: right&lt;/code&gt; on teaser 3. That way teaser 3 is placed next to the teaser 2. But most importantly, it aligns to the bottom of the text box in teaser 1. That is because a floated element still reserves space (unlike elements with &lt;code&gt;position: absolute&lt;/code&gt;), it just doesn&#39;t influence its containers height.&lt;/li&gt;
&lt;li&gt;Now I could do the same with the teasers 4, 5 and 6, but inverted.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That was it. A modern looking layout with quite oldschool code, completely supported in all browsers without any polyfills or vendor prefixes.&lt;/p&gt;
&lt;p&gt;You can find a basic implementation here:&lt;/p&gt;
&lt;p class=&quot;codepen&quot; data-height=&quot;540&quot; data-theme-id=&quot;light&quot; data-default-tab=&quot;&quot; data-user=&quot;mgrsskls&quot; data-slug-hash=&quot;9b1fcbee8879f6f6b6717e8255c286b0&quot; data-preview=&quot;true&quot; style=&quot;height: 265px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;&quot; data-pen-title=&quot;float layout&quot;&gt;
  &lt;span&gt;See the Pen &lt;a href=&quot;https://codepen.io/mgrsskls/pen/9b1fcbee8879f6f6b6717e8255c286b0/&quot;&gt;
  float layout&lt;/a&gt; by Michael Groklaus (&lt;a href=&quot;https://codepen.io/mgrsskls&quot;&gt;@mgrsskls&lt;/a&gt;)
  on &lt;a href=&quot;https://codepen.io/&quot;&gt;CodePen&lt;/a&gt;.&lt;/span&gt;
&lt;/p&gt;
&lt;script async=&quot;async&quot; src=&quot;https://static.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;
&lt;p&gt;Implementing this made me realize that there are so many things happening in the frontend world, that we almost forget about some of the most basic features. It is important to be aware of new developments as they can make a developers life much easier. But while new technologies often still need tooling around them, knowing the basics is crucial to write accessible, simple and widely supported code.&lt;/p&gt;

      
    </content>
  </entry>
  
</feed>
