<?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: Anand Doddamani</title>
    <description>The latest articles on Forem by Anand Doddamani (@anandd17).</description>
    <link>https://forem.com/anandd17</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%2F924125%2Fc7205e34-d463-4254-9ff4-27026c472178.jpeg</url>
      <title>Forem: Anand Doddamani</title>
      <link>https://forem.com/anandd17</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/anandd17"/>
    <language>en</language>
    <item>
      <title>How To Name Classes in HTML and CSS using BEM</title>
      <dc:creator>Anand Doddamani</dc:creator>
      <pubDate>Sat, 10 Sep 2022 19:22:19 +0000</pubDate>
      <link>https://forem.com/catalysts_reachout/how-to-name-classes-in-html-and-css-using-bem-4aod</link>
      <guid>https://forem.com/catalysts_reachout/how-to-name-classes-in-html-and-css-using-bem-4aod</guid>
      <description>&lt;p&gt;Hello Buddies,&lt;/p&gt;

&lt;p&gt;In Today's story we are discussing about naming convention in HTML and CSS. &lt;/p&gt;

&lt;p&gt;We are Discussing about BEM naming convention where B - Body, E - Element, M - Modifier. You may had a glance of naming classes similar as mentioned below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Wrong
.catlystNavbar{ ... }
.catlystNavbarLogo{ ... }
.catlystNavbarBg{ ... }

//Correct
.catalyst-navbar {  ...}
.catalyst-navbar__logo{  ...}
.catalyst-navbar--bg{  ...}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;BEM attempts to divide the overall user interface into small reusable components.&lt;/p&gt;

&lt;p&gt;To understand efficiently let us take an example of our a navbar&lt;br&gt;
Catalysts Navbar&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wSfHXsui--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dyiriiwcew4xon9nhi01.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wSfHXsui--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dyiriiwcew4xon9nhi01.png" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above navbar represents as element, such as a block of design.&lt;/p&gt;

&lt;p&gt;Which represents the first letter of BEM that is &lt;strong&gt;Block&lt;/strong&gt; and the component styled similarly as shown below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.catalyst-navbar{  ... }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;E - Element&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;E stands for Element in BEM&lt;/p&gt;

&lt;p&gt;For instance, the catalyst-navbar a logo and links&lt;/p&gt;

&lt;p&gt;The logo and links are all elements within the component. They may be seen as child components, i.e. children of the overall parent component.&lt;/p&gt;

&lt;p&gt;Using the BEM naming convention, element class names are derived by adding two underscores, followed by the element name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.catalyst-navbar__logo{  ... }
.catalyst-navbar__content{  ... }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;M - Modifier&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;M stands for Modifier in BEM&lt;/p&gt;

&lt;p&gt;What if the navbar was modified and we could have a blue or a red background&lt;/p&gt;

&lt;p&gt;In the real world, this could be a red button or blue button. These are modifications of the component in question.&lt;/p&gt;

&lt;p&gt;Using BEM, modifier class names are derived by adding two hyphens followed by the element name.&lt;/p&gt;

&lt;p&gt;For Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.catalyst-navbar--bg{  ... }
.catalyst-navbar--red{  ... }
.catalyst-navbar--blue{  ... }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the final code I wrote for this navbar&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Vu5n59v7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nd1peuvpio7shjjsocbh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Vu5n59v7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nd1peuvpio7shjjsocbh.png" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now the question arrise , Why naming convention is required ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Naming things is hard. We're trying to make things easier, and save ourselves time in the future with more maintainable code.&lt;/p&gt;

&lt;p&gt;Naming things correctly in CSS will make your code easier to read and maintain.&lt;/p&gt;

&lt;p&gt;If you choose to use the BEM naming convention, it will become easier to see the relationship between your design components/blocks just by looking at the markup.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
