<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Claire Parker-Jones</title>
    <description>The latest articles on Forem by Claire Parker-Jones (@clairecodes).</description>
    <link>https://forem.com/clairecodes</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F66493%2F7d3e0bab-9b12-4bfb-b930-daee8dfb0ac1.jpg</url>
      <title>Forem: Claire Parker-Jones</title>
      <link>https://forem.com/clairecodes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/clairecodes"/>
    <language>en</language>
    <item>
      <title>CSS Transitions for Multiple Properties on One Element</title>
      <dc:creator>Claire Parker-Jones</dc:creator>
      <pubDate>Wed, 27 May 2020 21:18:02 +0000</pubDate>
      <link>https://forem.com/clairecodes/css-transitions-for-multiple-properties-on-one-element-9o</link>
      <guid>https://forem.com/clairecodes/css-transitions-for-multiple-properties-on-one-element-9o</guid>
      <description>&lt;p&gt;This caught me out recently so I thought it was worth documenting in a blog post.&lt;/p&gt;

&lt;p&gt;How do you define a CSS transition for multiple properties on the same HTML element?&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/transition"&gt;CSS &lt;code&gt;transition&lt;/code&gt; property&lt;/a&gt; defines the effect between two different states of an element. &lt;code&gt;transition&lt;/code&gt; is a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties"&gt;shorthand property&lt;/a&gt;, which means it combines other CSS properties in single declaration. The resulting shorthand is simpler to read and write. Other common shorthand properties are &lt;code&gt;margin&lt;/code&gt;, &lt;code&gt;background&lt;/code&gt; and &lt;code&gt;font&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;An example of applying a transition to every transitionable state on an element is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.menu&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;all&lt;/span&gt; &lt;span class="m"&gt;1s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;transition&lt;/code&gt; property here includes definitions for &lt;code&gt;transition-property&lt;/code&gt;, &lt;code&gt;transition-duration&lt;/code&gt; and &lt;code&gt;transition-timing-function&lt;/code&gt;. (We could also add &lt;code&gt;transition-delay&lt;/code&gt;.) Using the shorthand saves us from writing out three separate declarations.&lt;/p&gt;

&lt;p&gt;The example above sets a transition for &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties"&gt;every animatable property&lt;/a&gt; on the element. You may need to be more specific, for example only transitioning the font color:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.menu&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="m"&gt;1s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;How do we extend this to transition both the font color and the margin, but with the same duration and timing function?&lt;/p&gt;

&lt;p&gt;Even if properties share certain values, they can't be combined in the transition shorthand. Instead, write out each property declaration in full and comma separate each one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.menu&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="m"&gt;1s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;margin&lt;/span&gt; &lt;span class="m"&gt;1s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;An alternative is to write single declarations instead of using the transition shorthand. The following code achieves the same effect as the previous example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.menu&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;transition-property&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;transition-duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;transition-timing-function&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ease-out&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I've created this &lt;a href="https://codepen.io/clairecodes/pen/YzybKyM?editors=1100"&gt;CodePen example illustrating both methods for adding transitions&lt;/a&gt; to an element where you can edit the code and experiment further.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/clairecodes/embed/YzybKyM?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>css</category>
      <category>transitions</category>
    </item>
    <item>
      <title>How to Reverse Ordered List Counters in HTML</title>
      <dc:creator>Claire Parker-Jones</dc:creator>
      <pubDate>Mon, 30 Mar 2020 20:56:35 +0000</pubDate>
      <link>https://forem.com/clairecodes/how-to-reverse-ordered-list-counters-in-html-3cnp</link>
      <guid>https://forem.com/clairecodes/how-to-reverse-ordered-list-counters-in-html-3cnp</guid>
      <description>&lt;p&gt;An &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol"&gt;ordered list in HTML&lt;/a&gt; uses ascending numbers to display list items, beginning at number 1. The code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;ol&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Don't Stop Me Now&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Under Pressure&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;We Are the Champions&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Bohemian Rhapsody&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ol&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;produces the following list:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Don't Stop Me Now&lt;/li&gt;
  &lt;li&gt;Under Pressure&lt;/li&gt;
  &lt;li&gt;We Are the Champions&lt;/li&gt;
  &lt;li&gt;Bohemian Rhapsody&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It's possible to reverse the order of the counters with only HTML - no CSS or JavaScript required!&lt;/p&gt;

&lt;p&gt;Add a HTML attribute called &lt;code&gt;reversed&lt;/code&gt; to the &lt;code&gt;&amp;lt;ol&amp;gt;&lt;/code&gt; tag.&lt;/p&gt;

&lt;p&gt;The same code as above, only now with the &lt;code&gt;reversed&lt;/code&gt; attribute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;ol&lt;/span&gt; &lt;span class="na"&gt;reversed&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Don't Stop Me Now&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Under Pressure&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;We Are the Champions&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Bohemian Rhapsody&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ol&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;produces a list with descending counters:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Don't Stop Me Now&lt;/li&gt;
  &lt;li&gt;Under Pressure&lt;/li&gt;
  &lt;li&gt;We Are the Champions&lt;/li&gt;
  &lt;li&gt;Bohemian Rhapsody&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note that this only reverses the sequence of the numbers, and not the position of the list items contained with the &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; tags.&lt;/p&gt;

&lt;p&gt;Where could you use this technique? The only situation I can think of is in a countdown, and perhaps this is why I'd never encountered this attribute before!&lt;/p&gt;

&lt;p&gt;The reverse attribute is supported in all modern browsers but has no support in IE. See the &lt;a href="https://caniuse.com/#search=ordered%20list%20reverse"&gt;caniuse table for the reverse attribute&lt;/a&gt; for more details.&lt;/p&gt;

&lt;p&gt;I've created a &lt;a href="https://codepen.io/clairecodes/pen/OJVaNGO"&gt;Codepen demo&lt;/a&gt; of the reverse attribute which you can play with below:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/clairecodes/embed/OJVaNGO?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>html</category>
    </item>
    <item>
      <title>Styling list bullets with emoji</title>
      <dc:creator>Claire Parker-Jones</dc:creator>
      <pubDate>Sat, 27 Apr 2019 08:51:40 +0000</pubDate>
      <link>https://forem.com/clairecodes/styling-list-bullets-with-emoji-1733</link>
      <guid>https://forem.com/clairecodes/styling-list-bullets-with-emoji-1733</guid>
      <description>&lt;p&gt;The available styles of bullet points for HTML unordered lists &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; are limited. Using CSS, they can be changed to something more exciting, like emoji! 🎉👯‍♂️✨&lt;/p&gt;

&lt;p&gt;In this post, I'll show you two methods to replace them: &lt;code&gt;@counter-style&lt;/code&gt;, which is concise and flexible (but your browser probably doesn’t support it), and the more tried-and-tested technique of using the &lt;code&gt;::before&lt;/code&gt; pseudo-element.&lt;/p&gt;

&lt;p&gt;We will transform an unordered list with unstyled counters from this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft64utd1i8gn2xlvh226l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft64utd1i8gn2xlvh226l.png" alt="Unstyled list of six items" width="250" height="180"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0sriuyubgxle2x5i4c3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0sriuyubgxle2x5i4c3.png" alt="Cat, dog and unicorn emoji in cyclical pattern for six list counters" width="271" height="195"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: the following code examples are written in Sass to utilise nesting, in order to keep them short.&lt;/p&gt;

&lt;h2&gt;
  
  
  Method 1: &lt;code&gt;@counter-style&lt;/code&gt; at-rule
&lt;/h2&gt;

&lt;p&gt;CSS &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule"&gt;at-rules&lt;/a&gt; are statements that instruct CSS how to behave, for example &lt;code&gt;@import&lt;/code&gt;, &lt;code&gt;@font-face&lt;/code&gt; or &lt;code&gt;@media&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@counter-style"&gt;&lt;code&gt;@counter-style&lt;/code&gt; at-rule&lt;/a&gt; was proposed in order to provide more options and functionality to the existing set of bullet styles in HTML lists.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://drafts.csswg.org/css-counter-styles-3/"&gt;&lt;code&gt;@counter-style&lt;/code&gt; is a level 3 proposal&lt;/a&gt;, at Candidate Recommendation stage, which means that the spec is stable enough to be implemented by browsers. However, as of April 2019 it is only supported by Firefox (&lt;a href="https://caniuse.com/#feat=css-at-counter-style"&gt;caniuse stats for &lt;code&gt;@counter-style&lt;/code&gt;&lt;/a&gt;). Example output in this post is provided as a image, although the code for all examples is available in the CodePen at the bottom of the page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Counter-style rule example
&lt;/h3&gt;

&lt;p&gt;To use counter-style, write a rule then declare is as the value of the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-type"&gt;&lt;code&gt;list-style-type&lt;/code&gt; CSS property&lt;/a&gt; on a &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;ol&amp;gt;&lt;/code&gt; tag. The syntax for a counter-style rule has several optional descriptors, as listed on the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@counter-style#Syntax"&gt;MDN documentation page&lt;/a&gt;. MDN also provide an &lt;a href="https://mdn.github.io/css-examples/counter-style-demo/"&gt;interactive demo&lt;/a&gt; of different counter-style variants (best viewed in a supported browser like Firefox).&lt;/p&gt;

&lt;p&gt;In order to replace the bullet points with an emoji, we need to give options to the "system", "symbols" and "suffix" descriptors. Choose the "cyclic" system and provide the unicode code points for the desired emoji symbols. Note that you need to use the unicode code point to represent the emoji rather than just the character, e.g. "\1F431" instead of 🐱. Find a complete list &lt;a href="https://unicode.org/emoji/charts/full-emoji-list.html"&gt;on the unicode website&lt;/a&gt;. Setting "suffix" to " " means that no other characters like a period appear after the counter.&lt;/p&gt;

&lt;p&gt;The "symbols" descriptor can accept a space-separated set of symbols. Combined with the "cyclic" system option, this means that our final bullet points design will rotate through all provided symbols.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="k"&gt;@counter-style&lt;/span&gt; &lt;span class="nt"&gt;repeating-emoji&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;system&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cyclic&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="na"&gt;symbols&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"\1F431"&lt;/span&gt; &lt;span class="s2"&gt;"\1F436"&lt;/span&gt; &lt;span class="s2"&gt;"\1F984"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// unicode code point&lt;/span&gt;
  &lt;span class="na"&gt;suffix&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Add this class to the ul or ol element&lt;/span&gt;
&lt;span class="nc"&gt;.repeating-counter-rule&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;list-style-type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;repeating-emoji&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0sriuyubgxle2x5i4c3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0sriuyubgxle2x5i4c3.png" alt="Cat, dog and unicorn emoji in cyclical pattern for six list counters" width="271" height="195"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Method 2: &lt;code&gt;::before&lt;/code&gt; pseudo-element
&lt;/h2&gt;

&lt;p&gt;This method can be used replace the standard discs with images, and not just emoji. The downside is that it doesn't provide the flexibility of &lt;code&gt;@counter-style&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Begin by setting &lt;code&gt;list-style: none&lt;/code&gt; on the parent list element, &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;ol&amp;gt;&lt;/code&gt;, and then adjusting padding and margin for the list item elements &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt;. The icon used for the bullet point is added using the &lt;code&gt;::before&lt;/code&gt; pseudo-element.&lt;/p&gt;

&lt;p&gt;To replace the default discs with the same emoji, the following code could be used, where the &lt;code&gt;single-before&lt;/code&gt; class is added to the &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; element:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nc"&gt;.single-before&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;list-style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;padding-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;text-indent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-0&lt;/span&gt;&lt;span class="mi"&gt;.7rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="na"&gt;li&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;before&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"🐻 "&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7wnm6meif7fd0ytglpvs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7wnm6meif7fd0ytglpvs.png" alt="Bear emoji for list counters" width="206" height="178"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to replicate the repeating pattern of three emoji bullet points from the counter-style example above, we need to use the &lt;code&gt;:nth-child&lt;/code&gt; pseudo-class. For example, add the following &lt;code&gt;.repeating-before&lt;/code&gt; class to a &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nc"&gt;.repeating-before&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;list-style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;padding-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;text-indent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-0&lt;/span&gt;&lt;span class="mi"&gt;.7rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;3n&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nt"&gt;1&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;::before&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"🐱 "&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;3n&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nt"&gt;2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;::before&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"🐶 "&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;3n&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;::before&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"🦄 "&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz4so8dkeu5d7e4vrjx3n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz4so8dkeu5d7e4vrjx3n.png" alt="Cat, dog and unicorn emoji in cyclical pattern for six list counters" width="265" height="251"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Although initially straightforward, this method can become more complex depending on the pattern of emoji to be implemented. However, this technique has the benefit of being &lt;a href="https://caniuse.com/#feat=css-gencontent"&gt;well-supported across browsers&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;@counter-style&lt;/code&gt; at-rule provides a lot of flexibility when styling list counters, but its limited browser support makes it unsuitable for most production sites. Using pseudo-elements is reliable but cumbersome for more intricate layouts. However, if the style of list bullets is an optional design feature rather than a critical part of the page design, then consider combining &lt;code&gt;@counter-style&lt;/code&gt; with the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@supports"&gt;&lt;code&gt;@supports&lt;/code&gt; at-rule&lt;/a&gt; and provide an acceptable fallback design, perhaps using pseudo-elements.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;span id="codepen"&gt;Emoji Bullet Point CodePen Example&lt;/span&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/clairecodes/embed/moNmXp?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>tutorial</category>
      <category>emoji</category>
    </item>
    <item>
      <title>My Misconceptions about the Universal Selector in CSS</title>
      <dc:creator>Claire Parker-Jones</dc:creator>
      <pubDate>Sun, 21 Apr 2019 22:50:54 +0000</pubDate>
      <link>https://forem.com/clairecodes/my-misconceptions-about-the-universal-selector-in-css-4ngm</link>
      <guid>https://forem.com/clairecodes/my-misconceptions-about-the-universal-selector-in-css-4ngm</guid>
      <description>&lt;p&gt;The asterisk &lt;code&gt;*&lt;/code&gt; is known as the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors"&gt;universal selector&lt;/a&gt; in CSS. It matches all elements of any type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This example would change the colour of all the text on the page to red (as long as there wasn't a more specific rule applied to the  element).&lt;/p&gt;

&lt;p&gt;I don't often use the universal selector, because I assumed that selecting &lt;em&gt;everything&lt;/em&gt; would be bad for page performance and difficult to override. After some research, I proved wrong some misconceptions I had about both the universal selector and my understanding of CSS.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;*&lt;/code&gt; has a specificity of 0
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Misconception 1: the universal selector has a high specificity.&lt;/strong&gt; ❌ Wrong! The specificity of &lt;code&gt;*&lt;/code&gt; is zero. In fact, quoting &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#Selector_Types"&gt;MDN's article on specificity&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Universal selector (*), combinators (+, &amp;gt;, ~, ' ', ||) and negation pseudo-class (:not()) have no effect on specificity.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Therefore, a rule that only uses the universal selector, like &lt;code&gt;* { color: red }&lt;/code&gt;, can be overridden by a single element, class or ID selector.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://specifishity.com/"&gt;Estelle Weyl's specifishity page&lt;/a&gt; is a great visual guide to understanding CSS specificity.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;*&lt;/code&gt; is inefficient in terms of performance
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Misconception 2: the universal selector performs badly compared to other selectors.&lt;/strong&gt; ✅ I was right about this one.&lt;/p&gt;

&lt;p&gt;When talking about CSS selector performance, Steve Souder's work is often quoted, particularly his book &lt;a href="http://shop.oreilly.com/product/9780596522315.do"&gt;Even Faster Websites&lt;/a&gt; and popular &lt;a href="http://www.stevesouders.com/blog/2009/03/10/performance-impact-of-css-selectors/"&gt;blog post about CSS selector performance&lt;/a&gt; both from 2009. He has a handy &lt;a href="http://stevesouders.com/efws/css-selectors/csscreate.php"&gt;CSS test creator&lt;/a&gt; on his website for measuring the performance of CSS selectors. The universal selector is one of the worst performers, alongside attribute selectors (like &lt;code&gt;[href="#"]&lt;/code&gt;) and pseudo-classes and pseudo-elements (like &lt;code&gt;:hover&lt;/code&gt;). IDs and classes are the best for speedy performance. (Harry Roberts summarises the results in a list in this post about &lt;a href="https://csswizardry.com/2011/09/writing-efficient-css-selectors/"&gt;efficient CSS selectors from 2011&lt;/a&gt;.)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;However&lt;/em&gt;, these results are for when you use a single selector alone, and not in combination with any others. You can still write  inefficient CSS selectors without &lt;code&gt;*&lt;/code&gt;. Using lots of child or descendent selectors is one way to achieve this, e.g. &lt;code&gt;div &amp;gt; ul li &amp;gt; a { color: red; }&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  CSS selectors are read from right to left by the browser ⬅
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Misconception 3: browsers process CSS selectors from left to right, in the same order that I would read them.&lt;/strong&gt; ❌ I was wrong about this which surprised me!&lt;/p&gt;

&lt;p&gt;One of these rules runs faster than the other:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* A */&lt;/span&gt;
&lt;span class="nf"&gt;#id&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;*.&lt;/span&gt;

&lt;span class="c"&gt;/* B */&lt;/span&gt;
&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;#id&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The browser checks the rightmost selector first before moving left. Therefore, selector B is quicker, since the matching elements are narrowed down to those matching the ID, instead of every element in the document like in A.&lt;/p&gt;

&lt;p&gt;Therefore, when writing selectors, it's best to put something performant like a class or ID at the end.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS Selector Performance matters
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Misconception 4: it's important to focus on CSS selector efficiency for page performance.&lt;/strong&gt; ❌ As I &lt;a href="https://meiert.com/en/blog/performance-of-css-selectors-2/"&gt;read&lt;/a&gt; &lt;a href="https://www.sitepoint.com/optimizing-css-id-selectors-and-other-myths/"&gt;more&lt;/a&gt; and &lt;a href="https://www.telerik.com/blogs/css-tip-star-selector-not-that-bad"&gt;more&lt;/a&gt; about this subject, the overriding opinion was that selector performance isn't something to worry about. Steve Souder even said as much in the first paragraph of the aforementioned &lt;a href="http://www.stevesouders.com/blog/2009/03/10/performance-impact-of-css-selectors/"&gt;blog on CSS selector performance&lt;/a&gt;. This was written 10 years ago, and since then our browsers have become much more powerful.&lt;/p&gt;

&lt;p&gt;However, I still wouldn't recommend writing very overqualified selectors, e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"text"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="nc"&gt;.foo&lt;/span&gt; &lt;span class="nf"&gt;#bar&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Not because of performance (although this will be inefficient) but because it implies that your DOM is structured badly, and CSS written like this will be hard to maintain and override. Instead, write selectors that match on ideally one class.&lt;/p&gt;

&lt;h2&gt;
  
  
  Would I use &lt;code&gt;*&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;The universal selector isn't one that I reach for often, but it can be useful. It's common to see browser-reset type selectors like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nd"&gt;:before&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nd"&gt;:after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The universal selector can also be useful to select all children of an element, or in cases where you don't have direct control over the structure of the page, e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.class&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now I understand how it works more, I wouldn't be afraid to use &lt;code&gt;*&lt;/code&gt;, particularly just for page performance concerns. In a world of weighty hero image PNGs, bloated JavaScript bundles and sluggish API calls, there are more strategic parts of a website to optimise for bigger performance gains.&lt;/p&gt;

&lt;p&gt;Instead, if I did need to use the universal selector, I would evaluate the reason: could this CSS be written in a clearer more maintainable way? Or could the page structure could be refactored to make it easier to target the required elements?&lt;/p&gt;

&lt;p&gt;Do you use the universal selector often or do you avoid it?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Header image by Jeremy Thomas on Unsplash.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Ignoring Prettier</title>
      <dc:creator>Claire Parker-Jones</dc:creator>
      <pubDate>Sun, 14 Apr 2019 19:21:20 +0000</pubDate>
      <link>https://forem.com/clairecodes/ignoring-prettier-3pd1</link>
      <guid>https://forem.com/clairecodes/ignoring-prettier-3pd1</guid>
      <description>&lt;p&gt;&lt;a href="https://prettier.io/"&gt;Prettier&lt;/a&gt; is an "opinionated code formatter". &lt;a href="https://prettier.io/docs/en/index.html"&gt;Quoting the docs&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It removes all original styling and ensures that all outputted code conforms to a consistent style.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It's commonly used in JavaScript projects, and also offers plugins that support other languages. Prettier can be run through its CLI, or even automatically through your code editor each time you hit save.&lt;/p&gt;

&lt;p&gt;Allowing Prettier to be responsible for how your code is formatted is a huge timesaver, especially when working in teams where code reviews can turn into passive-aggressive discussions about indentation and line-length. Instead, you can focus on what your code does rather than what it looks like.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to make Prettier ignore your code
&lt;/h2&gt;

&lt;p&gt;However, there's always an edge-case: that one time you don't agree with how Prettier lays out your code. Is it possible to turn Prettier off in some cases?&lt;/p&gt;

&lt;p&gt;Yes there is! There's an &lt;a href="https://prettier.io/docs/en/ignore.html"&gt;entire page of documentation that explains how&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Prettier can be turned off in several different ways. You can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ignore single lines in a file&lt;/li&gt;
&lt;li&gt;ignore several lines in a file&lt;/li&gt;
&lt;li&gt;ignore whole files

&lt;ul&gt;
&lt;li&gt;specific one-off files (e.g. &lt;code&gt;my-template.html&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;entire file-types (e.g. &lt;code&gt;*.html&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Depending on the issue, it may be solved by changing the configuration for Prettier instead of just ignoring sections of code. Preferences for trailing commas or double quotes can be changed via &lt;a href="https://prettier.io/docs/en/options.html"&gt;CLI and API options&lt;/a&gt;. However, Prettier purposely ships with minimal customisable options, since the rationale behind the package is to remove many of the discussions and choices around code style.&lt;/p&gt;

&lt;h2&gt;
  
  
  Should you use prettier ignore options?
&lt;/h2&gt;

&lt;p&gt;One of the central reasons for using Prettier is to surrender any decisions on code style to it. After making the initial config decisions for semicolons, trailing commas, etc, Prettier handles everything else related to code formatting, even if you don't like the way the tool formats a couple of lines.&lt;/p&gt;

&lt;p&gt;If you do setup Prettier to ignore a section of code in order to circumvent a particular formatting style, don't forget that you lose &lt;em&gt;all&lt;/em&gt; of Prettier's powers on that code. There's no way to selectively tell Prettier to ignore the indentation for your nested ternary statements in this function, but still enforce the bracket spacing as per the rest of the file.&lt;/p&gt;

&lt;p&gt;If you really want Prettier to ignore a line of code, I suggest leaving a comment in your code explaining why. For example, in the code below, Prettier will remove the brackets by default:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Reason: more readable with brackets&lt;/span&gt;
&lt;span class="c1"&gt;// prettier-ignore&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;totalThings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;widgets&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fizzbobs&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It might not pass code review with the rest of your team, but at least you've given a reason!&lt;/p&gt;

&lt;p&gt;Do you have any cases where you use &lt;code&gt;prettier-ignore&lt;/code&gt;? Or do you go with the flow and let Prettier decide?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Header image by Markus Spiske on Unsplash.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>prettier</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Why my Hugo Archetypes didn't work</title>
      <dc:creator>Claire Parker-Jones</dc:creator>
      <pubDate>Mon, 01 Apr 2019 13:12:27 +0000</pubDate>
      <link>https://forem.com/clairecodes/why-my-hugo-archetypes-didn-t-work-2nb5</link>
      <guid>https://forem.com/clairecodes/why-my-hugo-archetypes-didn-t-work-2nb5</guid>
      <description>&lt;p&gt;A short story about Hugo template files and Markdown file extensions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Brief overview of archetypes in Hugo
&lt;/h2&gt;

&lt;p&gt;The current version of my &lt;a href="https://www.clairecodes.com/"&gt;personal blog&lt;/a&gt; is built with &lt;a href="https://gohugo.io"&gt;Hugo&lt;/a&gt;, a static site generator. Hugo has the concept of &lt;a href="https://gohugo.io/content-management/archetypes/"&gt;archetypes&lt;/a&gt;, which are template files used to create new content types with the &lt;code&gt;hugo new&lt;/code&gt; command. It saves you having to copy and paste customised &lt;a href="https://gohugo.io/content-management/front-matter/"&gt;front matter&lt;/a&gt; (the YAML, TOML or JSON data at the top of the file) or other custom content every time you create a new post.&lt;/p&gt;

&lt;p&gt;Each content type in your Hugo site can have its own archetype template. For example, on my site I create standard blog posts and also custom diary style posts, as content types &lt;code&gt;blog&lt;/code&gt; and &lt;code&gt;dev-diary&lt;/code&gt;. When I type the command &lt;code&gt;hugo new dev-diary/example-post.md&lt;/code&gt; I want the file created to have different YAML fields than one created with &lt;code&gt;hugo new blog/example-post.md&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The previous version of my blog was built with Jekyll, and I built my own &lt;a href="https://github.com/claireparker/generator-clekyll"&gt;Yeoman generator&lt;/a&gt; in order to achieve the same result as Hugo's archetypes feature (plus it was a fun side-project). Archetypes have been a lot simpler to work with than a hand-made Yeoman generator, except for this one problem I was having.&lt;/p&gt;

&lt;h2&gt;
  
  
  The issue
&lt;/h2&gt;

&lt;p&gt;I dutifully followed the instructions to create an archetype file from &lt;a href="https://gohugo.io/content-management/archetypes/"&gt;Hugo’s docs&lt;/a&gt; and added it in the archetypes directory of my site, so it looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;archetypes
├── default.md
└── blog.md
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I used the command &lt;code&gt;hugo new blog/post.markdown&lt;/code&gt; but my new "blog" archetype wasn't being used. Instead, the new post used the "default" archetype. I was intermittently having success with it using different filenames but couldn’t work out why. I thought using the "-kind" flag helped but it turned out to be a red herring. I abandoned custom archetypes for a time, although still checked my broken attempts into my &lt;a href="https://github.com/claireparker/hugo-blog/tree/master/archetypes"&gt;blog site repo&lt;/a&gt; (because why not?).&lt;/p&gt;

&lt;h2&gt;
  
  
  The facepalm moment 💡
&lt;/h2&gt;

&lt;p&gt;I recently renamed one of my content types (&lt;code&gt;interesting&lt;/code&gt; to &lt;code&gt;dev-diary&lt;/code&gt;) and changed the format of my filenames and magically my archetypes began working! But why?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The markdown file extension of my new content file wasn’t matching the extension of the archetype 🤦‍♀️&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By using the command &lt;code&gt;hugo new blog/post.markdown&lt;/code&gt;, the blog archetype wasn't being invoked correctly, because it had a different file extension to the template file, i.e. &lt;code&gt;archetypes/blog.md&lt;/code&gt;. The mismatch between ".markdown" and ".md" extensions caused the archetypes to fail.&lt;/p&gt;

&lt;p&gt;Instead I needed to use &lt;code&gt;hugo new blog/post.md&lt;/code&gt; and match the markdown file suffixes.&lt;/p&gt;

&lt;p&gt;Both ".markdown" and ".md" are valid extensions for &lt;a href="https://en.wikipedia.org/wiki/Markdown"&gt;Markdown files&lt;/a&gt; and I use them interchangeably. Perhaps the ".markdown" extension isn't intended to work with archetypes as a conscious design choice from the Hugo team, but this definitely stumped me for a while!&lt;/p&gt;

</description>
      <category>hugo</category>
      <category>debugging</category>
      <category>markdown</category>
    </item>
    <item>
      <title>Using email newsletters to stay up-to-date with frontend development</title>
      <dc:creator>Claire Parker-Jones</dc:creator>
      <pubDate>Tue, 26 Mar 2019 14:57:54 +0000</pubDate>
      <link>https://forem.com/clairecodes/using-email-newsletters-to-stay-up-to-date-with-frontend-development-319c</link>
      <guid>https://forem.com/clairecodes/using-email-newsletters-to-stay-up-to-date-with-frontend-development-319c</guid>
      <description>&lt;p&gt;Modern frontend web development can be a vast and overwhelming subject at times.  New frameworks and best-practices come and go in quick succession. Keeping up with the latest trends, libraries and version updates can be exhausting and time-consuming. How can you stay ahead of the curve?&lt;/p&gt;

&lt;p&gt;The most successful method for me is to subscribe to weekly round-up emails about development.&lt;/p&gt;

&lt;p&gt;I receive several newsletters once a week, which contain topical links related to their subject, e.g. CSS, JavaScript or web accessibility. There are links to blog posts, GitHub repos, conference talk videos, code demos, etc. These weekly newsletters contain a digestible portion of information that helps me stay well-informed on the current state web development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Current subscriptions
&lt;/h2&gt;

&lt;p&gt;As of March 2019, I subscribe to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://react.statuscode.com/"&gt;React Status&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://javascriptweekly.com/"&gt;JavaScript Weekly&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://a11yweekly.com/"&gt;A11y Weekly&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://css-weekly.com/"&gt;CSS Weekly&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mobiledevweekly.com/"&gt;Mobile Dev Weekly&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://frontendfoc.us/"&gt;Frontend Focus&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.oreilly.com/web-platform/newsletter.html"&gt;O'Reilly Web Newsletter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nodeweekly.com/"&gt;Node Weekly&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.womenwhocode.com/"&gt;Women Who Code&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that many of these are published by Cooper Press, who run &lt;a href="https://cooperpress.com/publications/#newsletters"&gt;even more newsletters&lt;/a&gt; #notsponsored.&lt;/p&gt;

&lt;p&gt;My subscriptions have varied over the years depending on my current job or favourite technologies at the time. Not every email or subject area is directly relevant to my coding day-job responsibilities, but together this selection gives me a good overview of the areas I'm interested in as a frontend developer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why newsletters?
&lt;/h2&gt;

&lt;p&gt;Newsletters provide me with a curated list of relevant information that I can consume at my own pace. A round-up email like this contains approximately 10 to 30 links. Just like I wouldn't open every Google search result, I don't click through every link, but instead skim-read the email and choose a few choice items to open. This way I get a good overview of what's happening that week, while learning about subjects that interest me in more detail. I normally do this on my laptop rather than my phone, which makes reading code snippets or exploring GitHub repos easier. It also means I can have several tabs open at a time with articles I want to read later!&lt;/p&gt;

&lt;p&gt;Since I subscribe to a lot of mailing lists, their emails can pile up quickly in my inbox. It's important to make time to open them each week, but understand I don't have time to read about everything. Even using newsletters, the quantity of info can still be overwhelming, so it's important to learn to skim-read and not feel guilty about skipping some posts or deleting older emails to keep my inbox relatively empty.&lt;/p&gt;

&lt;p&gt;If you don't already, I definitely recommend subscribing to a couple of weekly newsletters related to your current tech stack, to see if this format helps you. You might find Twitter or listening to podcasts works better for you, but round-up emails like this are another useful option in the never-ending quest to keep up-to-date with web development trends.&lt;/p&gt;

&lt;p&gt;Let me know your own favourite dev-related mailing lists! 📨&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>productivity</category>
      <category>frontend</category>
    </item>
    <item>
      <title>The difference between dependencies and devDependencies in a JavaScript project</title>
      <dc:creator>Claire Parker-Jones</dc:creator>
      <pubDate>Wed, 13 Mar 2019 09:12:07 +0000</pubDate>
      <link>https://forem.com/clairecodes/the-difference-between-dependencies-and-devdependencies-in-a-javascript-project-22f2</link>
      <guid>https://forem.com/clairecodes/the-difference-between-dependencies-and-devdependencies-in-a-javascript-project-22f2</guid>
      <description>&lt;p&gt;When you use &lt;a href="https://www.npmjs.com/"&gt;npm&lt;/a&gt; to install a package to your project with the command &lt;code&gt;npm install &amp;lt;package-name&amp;gt;&lt;/code&gt;, the name and version of the package appears in the project's package.json file under the “dependencies” key. For example, &lt;code&gt;npm install react&lt;/code&gt; will look write something like this to the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dependencies&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;^16.8.4&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The code for the package will be installed in the project's local "node_modules" folder.&lt;/p&gt;

&lt;p&gt;(Note: with older versions of npm, the &lt;code&gt;--save&lt;/code&gt; or &lt;code&gt;-S&lt;/code&gt; flag was required in order to write the package to the "package.json". The latest version of npm at time of writing is 6.9.0).&lt;/p&gt;

&lt;p&gt;The list of packages in "package.json" is used by npm when your app is installed from scratch. Alongside the "package-lock.json" file, it ensures that the packages used in your app are a consistent version.&lt;/p&gt;

&lt;p&gt;It's also possible to add packages under the "devDependencies" key in "package.json". Instead, add the &lt;code&gt;--save-dev&lt;/code&gt; or shorter equivalent &lt;code&gt;-D&lt;/code&gt; flag when installing, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; jest
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  What is the difference between devDependencies and dependencies?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  dependencies
&lt;/h3&gt;

&lt;p&gt;"dependencies" are packages required to run the application in a production-ready environment. Without these packages, your app won't work. A couple of general examples are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;frameworks&lt;/strong&gt;: React, AngularJS, Vue.js&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;utility libraries&lt;/strong&gt;: lodash, Ramda, date-fns, polished&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  devDependencies
&lt;/h3&gt;

&lt;p&gt;"devDependencies" are required to develop and build your app, but are not needed to run the final version that customers will use. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;testing libraries&lt;/strong&gt;: Jest, Mocha, Jasmine&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;linters&lt;/strong&gt;: ESLint, Prettier&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;transpilers&lt;/strong&gt;: webpack, Babel (since production-ready code is already transpiled and minified)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you run &lt;code&gt;npm install&lt;/code&gt; in the root of a project with a "package.json" file, &lt;strong&gt;all packages&lt;/strong&gt; in both dependencies and devDependencies are installed. This is because you're working with the source code, so probably need the code in every package to develop it. However, if you only want to install the packages listed under the dependencies key, then use the &lt;code&gt;—-production&lt;/code&gt; flag, like &lt;code&gt;npm install --production&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In conclusion, when deciding where a package should sit in the "package.json" file, ask yourself whether the package is required for the app to work in the final, production-ready version. If it's not, add it to the devDependencies object, otherwise, it belongs in dependencies.&lt;/p&gt;

&lt;p&gt;Do you have any other examples? Let me know!&lt;/p&gt;

&lt;p&gt;For more information, see the &lt;a href="https://docs.npmjs.com/cli/install"&gt;official npm documentation page for the npm install command&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Equivalent Yarn commands
&lt;/h2&gt;

&lt;p&gt;If you use &lt;a href="https://yarnpkg.com/"&gt;yarn&lt;/a&gt; as your package manager instead of npm, the equivalent commands mentioned in this post are:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;npm&lt;/th&gt;
&lt;th&gt;yarn&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;npm install&lt;/td&gt;
&lt;td&gt;yarn install&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;npm install react&lt;/td&gt;
&lt;td&gt;yarn add react&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;npm i --save-dev react&lt;/td&gt;
&lt;td&gt;yarn add --dev react&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;npm i -D react&lt;/td&gt;
&lt;td&gt;yarn add -D react&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to prevent pasting into input fields</title>
      <dc:creator>Claire Parker-Jones</dc:creator>
      <pubDate>Wed, 30 Jan 2019 22:00:34 +0000</pubDate>
      <link>https://forem.com/clairecodes/how-to-prevent-pasting-into-input-fields-nn</link>
      <guid>https://forem.com/clairecodes/how-to-prevent-pasting-into-input-fields-nn</guid>
      <description>&lt;p&gt;&lt;strong&gt;Edit 01/02/19:&lt;/strong&gt; I was frustrated by yet another web form that wouldn’t let me paste my password into the Confirm Password field, wondered how it was done and decided to write about it. My intention with this post was to remain unbiased about whether you should or should not do this, and to encourage you to make your own decision. However, I also strongly encourage you to &lt;strong&gt;read the discussion below this post, as it clearly shows how unwanted and unnecessary this feature is&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Thank you to the Dev community members for all of your comments and feedback and for making this site such a positive part of the internet!&lt;/p&gt;




&lt;p&gt;In some forms, the “Confirm email address” or “Confirm password” fields don't allow users to paste text into them. The idea is to make users type their email or password twice to help catch any typos they might have made in those important "Email" and "Password" values.&lt;/p&gt;

&lt;p&gt;How is this functionality achieved? How can you stop your users from pasting content into a HTML input field?&lt;/p&gt;

&lt;p&gt;We can use JavaScript to target an input field’s &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Events/paste"&gt;paste event&lt;/a&gt; and change how it works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"no-paste"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pasteBox&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;no-paste&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;pasteBox&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onpaste&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code cancels the default behaviour of the paste event (i.e. pasting the contents of the clipboard into the input element). When the user tries to paste content into the field, using either a keyboard shortcut or &lt;a href="https://en.wikipedia.org/wiki/Context_menu"&gt;context menu&lt;/a&gt;, nothing will happen.&lt;/p&gt;

&lt;p&gt;Try it out in the CodePen example below:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/claireparker/embed/XOmwqy?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;There are also events for the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Events/cut"&gt;cut&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Events/copy"&gt;copy&lt;/a&gt; action.&lt;/p&gt;

&lt;p&gt;There is good support for the paste event in modern browsers. These events are part of the &lt;a href="https://www.w3.org/TR/clipboard-apis/#the-paste-action"&gt;Clipboard API&lt;/a&gt;. The Clipboard API also includes accessing the contents of the clipboard, which has varying levels of support. See the &lt;a href="https://caniuse.com/#feat=clipboard"&gt;caniuse table for the Clipboard API&lt;/a&gt; for more information.&lt;/p&gt;

&lt;h2&gt;
  
  
  Should you disable the paste function?
&lt;/h2&gt;

&lt;p&gt;Now you know how to change the expected behaviour of the paste event in your webpage, the question is whether you should. The answers to this &lt;a href="https://stackoverflow.com/questions/1226574/disable-pasting-text-into-html-form/1226721"&gt;StackOverflow question about the paste event&lt;/a&gt; discourage developers from tampering with default browser behaviour. The posters argue against changing expected browser behaviour because it will confuse users. Additionally, if the user decides to copy and paste data into a form field at the risk of it containing typos, then we should allow them to do this.&lt;/p&gt;

&lt;p&gt;Each website is different, so there is no definitive answer. It's a good idea to consider questions like this when building your site in order to provide the best experience for your users.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>html</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to Create a Polka Dot Background with CSS</title>
      <dc:creator>Claire Parker-Jones</dc:creator>
      <pubDate>Mon, 14 Jan 2019 21:59:47 +0000</pubDate>
      <link>https://forem.com/clairecodes/how-to-create-a-polka-dot-background-with-css-23m0</link>
      <guid>https://forem.com/clairecodes/how-to-create-a-polka-dot-background-with-css-23m0</guid>
      <description>&lt;h2&gt;
  
  
  &lt;a href="https://en.wiktionary.org/wiki/tl;dr" rel="noopener noreferrer"&gt;TL;DR&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;This post explains how to produce this design using CSS:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff1zocr5g0qc9lg4p18q5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff1zocr5g0qc9lg4p18q5.png" alt="Final polka dot effect"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It can be created with only a single HTML tag and these background-related CSS properties:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;radial-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;#212121&lt;/span&gt; &lt;span class="m"&gt;20%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;transparent&lt;/span&gt; &lt;span class="m"&gt;20%&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="n"&gt;radial-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;#fafafa&lt;/span&gt; &lt;span class="m"&gt;20%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;transparent&lt;/span&gt; &lt;span class="m"&gt;20%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#e53935&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Below is an explanation of how this works, or you can experiment with the code directly in &lt;a href="https://codepen.io/claireparker/pen/oMmPPZ" rel="noopener noreferrer"&gt;this CodePen example&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/claireparker/embed/oMmPPZ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1 - make a circle
&lt;/h2&gt;

&lt;p&gt;Let’s begin by using CSS to display a single circle.&lt;/p&gt;

&lt;p&gt;Use a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/radial-gradient" rel="noopener noreferrer"&gt;radial-gradient&lt;/a&gt; as a background-image to create a circle shape. Give the gradient with two colors with identical color-stop values. The color-stops create the sharp border between the two colors, instead of a faded gradient effect. A color-stop can be a percentage between 0% and 100%, where 0 is the centre of the gradient and 100% is the edge.&lt;/p&gt;

&lt;p&gt;Give the container element equal height and width to make the circle display nicely. If the element isn’t a square then the circle will appear warped.&lt;/p&gt;

&lt;p&gt;At this stage, the CSS will look like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;radial-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;#212121&lt;/span&gt; &lt;span class="m"&gt;20%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;#e53935&lt;/span&gt; &lt;span class="m"&gt;20%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz625w15l6n7l5zgzbync.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz625w15l6n7l5zgzbync.png" alt="Single CSS circle"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: I'm using the body tag to apply the styles to because it's the simplest tag to demonstrate the effect in a new webpage. This may not be suitable for your use-case, so replace &lt;code&gt;body&lt;/code&gt; as necessary with another CSS selector - just don't forget to give it a height and width.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 - make the circle repeat
&lt;/h2&gt;

&lt;p&gt;Position the circle image in the top left of the background with the &lt;code&gt;background-position: 0 0&lt;/code&gt; property. The two values represent the x and y coordinates in pixels. We can omit the &lt;code&gt;px&lt;/code&gt; value, because in CSS, 0 pixels (or ems, or %, etc) is the same as saying 0.&lt;/p&gt;

&lt;p&gt;Give the image a set size of 100px by 100px with the &lt;code&gt;background-size&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;Set the height and width of the body container larger than the background-size so that we can see the repeating effect of our image. The CSS will now look like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;radial-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;#212121&lt;/span&gt; &lt;span class="m"&gt;20%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;#e53935&lt;/span&gt; &lt;span class="m"&gt;20%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;background-position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl6tfjpgz33w0ii45i9m8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl6tfjpgz33w0ii45i9m8.png" alt="Repeating circles"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point you might ask, why is the image repeating? We haven't set any properties explicitly in the CSS to do this.&lt;/p&gt;

&lt;p&gt;There's another background-related property called &lt;code&gt;background-repeat&lt;/code&gt;. The default value for this property set by the browser is &lt;code&gt;repeat&lt;/code&gt;, which makes the background-image automatically repeat along both the x and y axes without us having to set it.  Since the containing element (the body tag) is now larger than the 100px by 100px circle background-image, the circle is duplicated in the remaining space.&lt;/p&gt;

&lt;p&gt;If we wanted the circles to stop repeating, we could change the value to &lt;code&gt;background-repeat: no-repeat&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3 - add a diagonal row
&lt;/h2&gt;

&lt;p&gt;Add a second radial gradient to the &lt;code&gt;background-image&lt;/code&gt; property by separating them with commas. I've given the second gradient a different colour for the circle to make it stand out.&lt;/p&gt;

&lt;p&gt;Change the second color of each gradient to &lt;code&gt;transparent&lt;/code&gt;, and set the &lt;code&gt;background-color&lt;/code&gt; of the element explicitly. This is in order to see the new row of dots - otherwise it would be hidden behind the first one.&lt;/p&gt;

&lt;p&gt;Now we have two gradients, we can give them each different &lt;code&gt;background-position&lt;/code&gt; values, again separated by commas. By giving the new row values that are half of the background size (50px), we create the diagonal spacing effect. The final CSS will look like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;radial-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;#212121&lt;/span&gt; &lt;span class="m"&gt;20%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;transparent&lt;/span&gt; &lt;span class="m"&gt;20%&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
     &lt;span class="n"&gt;radial-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;#fafafa&lt;/span&gt; &lt;span class="m"&gt;20%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;transparent&lt;/span&gt; &lt;span class="m"&gt;20%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#e53935&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Final result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff1zocr5g0qc9lg4p18q5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff1zocr5g0qc9lg4p18q5.png" alt="Final polka dot effect"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Voilà, polka dots in CSS. You could change the size of the circles, the colors, or even add another row at a different position to create more complex effects.&lt;/p&gt;

&lt;h3&gt;
  
  
  A note on &lt;code&gt;background&lt;/code&gt; and shorthand
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;background&lt;/code&gt; CSS property is shorthand for multiple &lt;code&gt;background-&lt;/code&gt; prefixed properties. You may have used other CSS shorthands, such as font, margin or border. In this example, I've used individual properties such as &lt;code&gt;background-image&lt;/code&gt; and &lt;code&gt;background-color&lt;/code&gt; instead of the shorthand. This is because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;it's easier to see what's happening in the individual properties instead of trying to work out what each value means in &lt;code&gt;background&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;when using shorthand, it's easy to accidentally overwrite other properties and cause bugs, since you don't explicitly declare properties (for this reason I always use &lt;code&gt;background-color&lt;/code&gt; instead of &lt;code&gt;background&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;when setting multiple backgrounds it's easier and not always possible to do so with the shorthand&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sometimes a shorthand can be useful, like &lt;code&gt;margin: 10px 30px 20px 5px&lt;/code&gt;, but with less-common ones like &lt;code&gt;font&lt;/code&gt; and &lt;code&gt;background&lt;/code&gt;, I recommend using individual properties so that you can be sure of what's happening in your code.&lt;/p&gt;

</description>
      <category>css</category>
    </item>
    <item>
      <title>Making the Alt Key Work in iTerm2</title>
      <dc:creator>Claire Parker-Jones</dc:creator>
      <pubDate>Mon, 15 Oct 2018 21:13:26 +0000</pubDate>
      <link>https://forem.com/clairecodes/making-the-alt-key-work-in-iterm2-1aa9</link>
      <guid>https://forem.com/clairecodes/making-the-alt-key-work-in-iterm2-1aa9</guid>
      <description>&lt;p&gt;&lt;a href="https://www.iterm2.com/" rel="noopener noreferrer"&gt;iTerm2&lt;/a&gt; is a replacement for the default Terminal application on MacOS. It has many more handy &lt;a href="https://www.iterm2.com/features.html" rel="noopener noreferrer"&gt;features&lt;/a&gt; than Terminal, is free to download and is also &lt;a href="https://github.com/gnachman/iTerm2" rel="noopener noreferrer"&gt;open source&lt;/a&gt; 🎉.&lt;/p&gt;

&lt;p&gt;However, on initial install, you can’t use the Option or Alt key (the one that looks like this: &lt;code&gt;⌥&lt;/code&gt;) as you would in other applications: it's not possible skip or jump over words by pressing Alt and the left or right keys. Instead you see sequences like &lt;code&gt;[D&lt;/code&gt; or &lt;code&gt;[C&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftkbpkuup6p5dio26j5xj.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftkbpkuup6p5dio26j5xj.gif" alt="Broken alt key displaying escape sequences"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This can be changed by tweaking a couple of settings, which I'll explain below.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note:&lt;/em&gt; I refer to the &lt;a href="https://en.wikipedia.org/wiki/Alt_key" rel="noopener noreferrer"&gt;"Alt"&lt;/a&gt; key throughout this post, as this is the text written on the key of my old 2013 MacBook Pro keyboard, but this is normally called the "Option" key in MacOS.&lt;/p&gt;




&lt;p&gt;Open the "Preferences" menu: either find it in the "iTerm2" dropdown menu along the top of the screen or press the Command and comma keys. ⌘ + ,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fseodz7qakqg2ac3k5dd5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fseodz7qakqg2ac3k5dd5.png" alt="iTerm2 general preferences menu"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choose the "Profiles" menu.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8pg72mea4048j8sstyzk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8pg72mea4048j8sstyzk.png" alt="iTerm2 profiles menu"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select the "Keys" tab.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjkmwtcsy8jssftz2tcnu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjkmwtcsy8jssftz2tcnu.png" alt="iTerm2 keys tab"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Within the "Key Mappings" pane, find the mapping for the Alt and left keys, which will look like this: &lt;code&gt;⌥←&lt;/code&gt;. Double click it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2t1tira1omccj9oas24a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2t1tira1omccj9oas24a.png" alt="iTerm2 keys tab with Alt Mappings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Change the action from "Send Hex Code" to "Send Escape Sequence" (you might have to scroll a bit to find this).&lt;/p&gt;

&lt;p&gt;In the "Esc +" field, type lowercase "b" and click "OK".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flkswgxprwt88dhgc7cir.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flkswgxprwt88dhgc7cir.png" alt="iTerm2 Alt left mapping"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open the same context menu for Alt plus right &lt;code&gt;⌥→&lt;/code&gt; and again change the action to "Send Escape Sequence".&lt;/p&gt;

&lt;p&gt;This time, in the "Esc +" field, type lowercase "f". Click "OK".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkdwnz0d6asla2patdqn6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkdwnz0d6asla2patdqn6.png" alt="iTerm2 Alt right mapping"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Close the Preferences menu. The changes take effect immediately. When you press ⌥ + → or ←, the cursor will jump over entire words as it does on other applications. You can now navigate the command line with more precision and speed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9vqmsqoub479c6x7d8gs.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9vqmsqoub479c6x7d8gs.gif" alt="Working alt key moving between words"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus shortcuts
&lt;/h2&gt;

&lt;p&gt;Control + e will move the cursor to the end of the line.&lt;/p&gt;

&lt;p&gt;Control + a will move the cursor to the beginning of the line.&lt;/p&gt;

</description>
      <category>terminal</category>
      <category>iterm2</category>
    </item>
    <item>
      <title>Quickly Switching Between Two Branches in Git</title>
      <dc:creator>Claire Parker-Jones</dc:creator>
      <pubDate>Fri, 08 Jun 2018 12:51:19 +0000</pubDate>
      <link>https://forem.com/clairecodes/quickly-switching-between-two-branches-in-git-37k0</link>
      <guid>https://forem.com/clairecodes/quickly-switching-between-two-branches-in-git-37k0</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;git checkout -&lt;/code&gt; checks out the last branch you were working on.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Do you find yourself needing to switch between the same two branches in git again and again? There's a shortcut for that in the terminal!&lt;/p&gt;

&lt;p&gt;Instead of typing out the branch name manually each time, substitute the name with the hyphen character &lt;code&gt;-&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxk3brwwz44pjly0sk6r3.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxk3brwwz44pjly0sk6r3.gif" alt="Gif demonstrating how to use the  raw `git checkout -` endraw  shortcut" width="1024" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: In the gif, I'm using the Bash shell in iTerm2 on a Mac.&lt;/p&gt;

&lt;p&gt;If you can't see the gif, here's a text representation, where the line with the dollar &lt;code&gt;$&lt;/code&gt; represents the command prompt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;~test-directory] | first-really-long-branch-name &lt;span class="nv"&gt;$ &lt;/span&gt;git checkout second-super-long-branch-name
Switched to branch &lt;span class="s1"&gt;'second-super-long-branch-name'&lt;/span&gt;

&lt;span class="o"&gt;[&lt;/span&gt;~/test-directory] | second-super-long-branch-name &lt;span class="nv"&gt;$ &lt;/span&gt;git checkout -
Switched to branch &lt;span class="s1"&gt;'first-really-long-branch-name'&lt;/span&gt;

&lt;span class="o"&gt;[&lt;/span&gt;~/test-directory] | first-really-long-branch-name &lt;span class="nv"&gt;$ &lt;/span&gt;git checkout -
Switched to branch &lt;span class="s1"&gt;'second-super-long-branch-name'&lt;/span&gt;

&lt;span class="o"&gt;[&lt;/span&gt;~/test-directory] | second-super-long-branch-name &lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This shortcut can save keystrokes when toggling between two branches.&lt;/p&gt;

&lt;p&gt;It can be helpful when you're working on branches with long names, or your branches have similar names, making autocomplete not as helpful as it could be (e.g. &lt;code&gt;feature-1123&lt;/code&gt;, &lt;code&gt;feature-1124&lt;/code&gt;).&lt;/p&gt;




&lt;h3&gt;
  
  
  P.S.
&lt;/h3&gt;

&lt;p&gt;Speaking of autocomplete in git, &lt;a href="https://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks" rel="noopener noreferrer"&gt;here's how to install it for the Bash shell&lt;/a&gt;, if you don't already have it set up. This provides the ability to type a couple of characters and press tab to autocomplete the rest of the command (or see all possibilities if there's more than one match).&lt;/p&gt;




&lt;h3&gt;
  
  
  P.P.S.
&lt;/h3&gt;

&lt;p&gt;The same trick can be used to navigate between two directories in the terminal. Try typing &lt;code&gt;cd -&lt;/code&gt; at the command prompt and the current directory will change to the one you were in last:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;~/test-directory] | master &lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /a/long/subdirectory/path

&lt;span class="o"&gt;[&lt;/span&gt;~/test-directory/a/long/subdirectory/path] | master &lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; -

&lt;span class="o"&gt;[&lt;/span&gt;~/test-directory] | master &lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>terminal</category>
      <category>git</category>
    </item>
  </channel>
</rss>
