<?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>DEV Community: Joel Santana</title>
    <description>The latest articles on DEV Community by Joel Santana (@joelsantz).</description>
    <link>https://dev.to/joelsantz</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%2F218042%2Fdcb77b98-983c-4ce2-9019-2763d503cc70.JPG</url>
      <title>DEV Community: Joel Santana</title>
      <link>https://dev.to/joelsantz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/joelsantz"/>
    <language>en</language>
    <item>
      <title>Do You Don’t Understand [em] Unit In CSS3 Yet? 😅 — Basic Explain</title>
      <dc:creator>Joel Santana</dc:creator>
      <pubDate>Tue, 27 Aug 2019 03:49:30 +0000</pubDate>
      <link>https://dev.to/joelsantz/do-you-don-t-understand-em-unit-in-css3-yet-basic-explain-2en3</link>
      <guid>https://dev.to/joelsantz/do-you-don-t-understand-em-unit-in-css3-yet-basic-explain-2en3</guid>
      <description>&lt;p&gt;Maybe you’re think right now: oh, this is a basic post for begginers web developers , and you’re right! but if we see it from another way, there are a lot of people like; graphic designers, ux/ui designers, “full stack developers” and even front-end developers! that doesn’t have an idea of how it works or how to use em unit in CSS3, if you are part of this people or not, don’t worry, I try to help you with this simple post.&lt;/p&gt;

&lt;h1&gt;
  
  
  First, you need to know — Absolute and Relative lenghts units 👀
&lt;/h1&gt;

&lt;p&gt;I’m sure that you know what is a unit in CSS3, the most popular is &lt;strong&gt;px&lt;/strong&gt;, we use this unit for declarate the lenght in fonts, container, images, borders, margines, and etc. &lt;strong&gt;Pexels&lt;/strong&gt; is a &lt;strong&gt;absolute&lt;/strong&gt; unit, because is &lt;strong&gt;fixed&lt;/strong&gt;, and any lenght expressed in this will always have an exact size. As &lt;strong&gt;px&lt;/strong&gt; exist others absolute units: cm, mm, in, pt and pc &lt;em&gt;(but right now we don’t care about that)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;And on the contrary a &lt;strong&gt;relative lenght&lt;/strong&gt; unit is &lt;strong&gt;flexible&lt;/strong&gt;, because its value is not fixed, this value is &lt;strong&gt;referenced&lt;/strong&gt; for other value 😵 keep calm, you will understand it.&lt;/p&gt;

&lt;p&gt;The most popular relative units are % and &lt;strong&gt;em&lt;/strong&gt;, if you have already worked with the &lt;strong&gt;flex-box&lt;/strong&gt; concepts, maybe you used % to express values of lenght in your elements as &lt;strong&gt;width&lt;/strong&gt; or &lt;strong&gt;height&lt;/strong&gt;, and these have a referenced length value of parents elements.&lt;/p&gt;

&lt;h1&gt;
  
  
  So… What is em unit? 😐
&lt;/h1&gt;

&lt;p&gt;The different with the % Unit is, the em unit is used for font sizes, where the value is reference of the closest element that has specified a font size before&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;em&lt;/strong&gt; is a Relative Unit to the closest especified font size.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Go to Example!❤️
&lt;/h1&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;nav&lt;/span&gt; &lt;span class="na"&gt;style = &lt;/span&gt;&lt;span class="s"&gt;"font-size: 16px;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;  &lt;span class="c"&gt;&amp;lt;!-- inital size 16px --&amp;gt;&lt;/span&gt; 
    &lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;style = &lt;/span&gt;&lt;span class="s"&gt;"font-size: 1em;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;  &lt;span class="c"&gt;&amp;lt;!-- 1em = 16px --&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;style = &lt;/span&gt;&lt;span class="s"&gt;"font-size: 2em;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- 1em = 16px, 2em = 32px --&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href= &lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="na"&gt;style = &lt;/span&gt;&lt;span class="s"&gt;"font-size: .5em;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/a&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- 1em = 32px, .5em = 16px --&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In our &lt;strong&gt;nav&lt;/strong&gt; element we assign a font-size of &lt;strong&gt;16px&lt;/strong&gt;, this is our &lt;strong&gt;initial&lt;/strong&gt; size.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As our &lt;strong&gt;initial&lt;/strong&gt; size is 16px, when we declared in &lt;strong&gt;ul&lt;/strong&gt; element a font-size of &lt;strong&gt;1em&lt;/strong&gt;, this takes 16px as &lt;strong&gt;1em&lt;/strong&gt;. &lt;em&gt;(remember it, em unit takes the font-size value of the closest element, in this case nav)&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In &lt;strong&gt;li&lt;/strong&gt; element we declared a font-size of &lt;strong&gt;2em&lt;/strong&gt;, correct! the value of 2em is &lt;strong&gt;32px&lt;/strong&gt;, cool!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pay attention, in the four line, we declared a font-size of &lt;strong&gt;.5em&lt;/strong&gt; for our &lt;strong&gt;a&lt;/strong&gt; element, right? but maybe you’re thinking now, why the font-size value is &lt;strong&gt;16px&lt;/strong&gt;? This happens because the last value declared in the &lt;strong&gt;closest&lt;/strong&gt; element was &lt;strong&gt;32px&lt;/strong&gt; &lt;em&gt;(no matter if was for 2em, now the new value for 1em is 32px)&lt;/em&gt; then, .5em is equals to the middle of 1em, so the final font-size is &lt;strong&gt;16px&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  When should we use the em unit? 👌
&lt;/h1&gt;

&lt;p&gt;How we already know, the &lt;strong&gt;em&lt;/strong&gt; unit is relative, like % in flex-box, we can use em when we’re doing responsive design.&lt;/p&gt;

&lt;p&gt;It is a good practice because when we are doing responsive design, we will only have to declare the &lt;strong&gt;font size&lt;/strong&gt; of the main element in &lt;strong&gt;px&lt;/strong&gt;, and in the children in &lt;strong&gt;em&lt;/strong&gt;, so, when we adapt the design to different device sizes, we will only change the font size in the main element and the children elements will adapt.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;thanks for read, I hope this is very useful for you.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
