<?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: bhtibrewal</title>
    <description>The latest articles on DEV Community by bhtibrewal (@bhtibrewal).</description>
    <link>https://dev.to/bhtibrewal</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%2F737849%2Ff531ab26-1797-446c-9870-545a223388d8.png</url>
      <title>DEV Community: bhtibrewal</title>
      <link>https://dev.to/bhtibrewal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bhtibrewal"/>
    <language>en</language>
    <item>
      <title>Optimizing Performance of a React Application</title>
      <dc:creator>bhtibrewal</dc:creator>
      <pubDate>Wed, 04 May 2022 10:51:00 +0000</pubDate>
      <link>https://dev.to/bhtibrewal/optimizing-performance-of-a-react-application-2ibn</link>
      <guid>https://dev.to/bhtibrewal/optimizing-performance-of-a-react-application-2ibn</guid>
      <description>&lt;p&gt;Optimization is the number one thing on every dev's mind when building any software, especially web apps. React is a JavaScript library for building user interfaces. React ships with several ways to minimize the number of costly DOM operations required to update the UI. Using React will lead to a fast user interface for many applications without doing much work to specifically optimize for performance.&lt;/p&gt;

&lt;p&gt;When we create a rendered component, React creates a virtual DOM for its element tree in the component. Now, whenever the state of the component changes, React recreates the virtual DOM tree and compares the result with the previous render.&lt;/p&gt;

&lt;p&gt;It then only updates the changed element in the actual DOM. This process is called diffing.&lt;/p&gt;

&lt;p&gt;React uses the concept of a virtual DOM to minimize the performance cost of re-rendering a webpage because the actual DOM is expensive to manipulate.&lt;/p&gt;

&lt;p&gt;The issue comes when the child components are not affected by the state change. In other words, they do not receive any prop from the parent component.&lt;/p&gt;

&lt;p&gt;React nonetheless re-renders these child components. So, as long as the parent component re-renders, all of its child components re-render regardless of whether a prop passes to them or not; this is the default behavior of React.&lt;/p&gt;

&lt;h2&gt;
  
  
  Profiling the React app to understand where bottlenecks are
&lt;/h2&gt;

&lt;p&gt;React allows us to measure the performance of our apps using the Profiler in the React DevTools. There, we can gather performance information every time our application renders.&lt;/p&gt;

&lt;p&gt;The profiler records how long it takes a component to render, why a component is rendering, and more. From there, we can investigate the affected component and provide the necessary optimization.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zYK-8bG9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1651657618756/cXgYegqmt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zYK-8bG9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1651657618756/cXgYegqmt.png" alt="image.png" width="880" height="421"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Keeping component state local where necessary
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from "react";

export default function App() {
  const [input, setInput] = useState("");

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;input
        type="text"
        value={input}
        onChange={(e) =&amp;gt; setInput(e.target.value)}
      /&amp;gt;
      &amp;lt;h3&amp;gt;Input text: {input}&amp;lt;/h3&amp;gt;
      &amp;lt;ChildComponent /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

function ChildComponent() {
  console.log("child component is rendering");
  return &amp;lt;div&amp;gt;This is child component.&amp;lt;/div&amp;gt;;
};

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

&lt;/div&gt;



&lt;p&gt;Whenever the state of the App component updates, the ChildComponent re-renders even when it is not directly affected by the state change.&lt;/p&gt;

&lt;p&gt;To ensure re-rendering a component only happens when necessary, we can extract the part of the code that cares about the component state, making it local to that part of the code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from "react";

export default function App() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;FormInput /&amp;gt;
      &amp;lt;ChildComponent /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;This ensures that only the component that cares about the state renders. In our code, only the input field cares about the state. So, we extracted that state and the input to a &lt;code&gt;FormInput&lt;/code&gt; component, making it a sibling to the &lt;code&gt;ChildComponent&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This means, that when the state changes, only the &lt;code&gt;FormInput&lt;/code&gt; component re-renders, and the &lt;code&gt;ChildComponent&lt;/code&gt; no longer re-renders on every keystroke.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. React. Lazy for Lazy Loading Components
&lt;/h2&gt;

&lt;p&gt;To implement code-splitting, we transform a normal React import like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Home from "./components/Home";
import About from "./components/About";

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

&lt;/div&gt;



&lt;p&gt;And then into something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Home = React.lazy(() =&amp;gt; import("./components/Home"));
const About = React.lazy(() =&amp;gt; import("./components/About"));

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

&lt;/div&gt;



&lt;p&gt;This syntax tells React to load each component dynamically. So, when a user follows a link to the home page, for instance, React only downloads the file for the requested page instead of loading a large bundle file for the entire application.&lt;/p&gt;

&lt;p&gt;After the import, we must render the lazy components inside a Suspense component like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Suspense fallback={&amp;lt;p&amp;gt;Loading page...&amp;lt;/p&amp;gt;}&amp;gt;
  &amp;lt;Route path="/" exact&amp;gt;
    &amp;lt;Home /&amp;gt;
  &amp;lt;/Route&amp;gt;
  &amp;lt;Route path="/about"&amp;gt;
    &amp;lt;About /&amp;gt;
  &amp;lt;/Route&amp;gt;
&amp;lt;/Suspense&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;The Suspense allows us to display a loading text or indicator as a fallback while React waits to render the lazy component in the UI.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. React.memo
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;In computing, memoization is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In essence, if a child component receives a prop, a memoized component shallowly compares the prop by default and skips re-rendering the child component if the prop hasnt changed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from "react";

export default function App() {
  const [input, setInput] = useState("");
  const [count, setCount] = useState(0);

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;input
        type="text"
        value={input}
        onChange={(e) =&amp;gt; setInput(e.target.value)}
      /&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setCount(count + 1)}&amp;gt;Increment counter&amp;lt;/button&amp;gt;
      &amp;lt;h3&amp;gt;Input text: {input}&amp;lt;/h3&amp;gt;
      &amp;lt;h3&amp;gt;Count: {count}&amp;lt;/h3&amp;gt;
      &amp;lt;hr /&amp;gt;
      &amp;lt;ChildComponent count={count} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

function ChildComponent({ count }) {
  console.log("child component is rendering");
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h2&amp;gt;This is a child component.&amp;lt;/h2&amp;gt;
      &amp;lt;h4&amp;gt;Count: {count}&amp;lt;/h4&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;By updating the input field, both the App component and ChildComponent re-render.&lt;/p&gt;

&lt;p&gt;Instead, the &lt;code&gt;ChildComponent&lt;/code&gt; should only re-render when clicking the count button because it must update the UI. Here, we can &lt;code&gt;memoize&lt;/code&gt; the &lt;code&gt;ChildComponent&lt;/code&gt; to optimize our apps performance.&lt;/p&gt;

&lt;p&gt;React.memo is a higher-order component used to wrap a purely functional component to prevent re-rendering if the props received in that component never changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from "react";

const ChildComponent = React.memo(function ChildComponent({ count }) {
  console.log("child component is rendering");
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h2&amp;gt;This is a child component.&amp;lt;/h2&amp;gt;
      &amp;lt;h4&amp;gt;Count: {count}&amp;lt;/h4&amp;gt;
    &amp;lt;/div&amp;gt;
  );
});

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

&lt;/div&gt;



&lt;p&gt;If the count prop never changes, React will skip rendering the &lt;code&gt;ChildComponent&lt;/code&gt; and reuse the previous rendered result. Hence improving Reacts performance.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;React.memo()&lt;/code&gt; works pretty well when we pass down primitive values, such as a number in our example. And, if you are familiar with referential equality, primitive values are always referentially equal and return true if values never change.&lt;/p&gt;

&lt;p&gt;On the other hand, non-primitive values like object, which include arrays and functions, always return false between re-renders because they point to different spaces in memory.&lt;/p&gt;

&lt;p&gt;When we pass down an object, array, or function as a prop, the memoized component always re-renders. Here, we are passing down a function to the child component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from "react";

export default function App() {
  // ...

  const incrementCount = () =&amp;gt; setCount(count + 1);

  return (
    &amp;lt;div&amp;gt;
      {/* ... */}
      &amp;lt;ChildComponent count={count} onClick={incrementCount} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

const ChildComponent = React.memo(function ChildComponent({ count, onClick }) {
  console.log("child component is rendering");
  return (
    &amp;lt;div&amp;gt;
      {/* ... */}
      &amp;lt;button onClick={onClick}&amp;gt;Increment&amp;lt;/button&amp;gt;
      {/* ... */}
    &amp;lt;/div&amp;gt;
  );
});

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

&lt;/div&gt;



&lt;p&gt;This code focuses on the &lt;code&gt;incrementCount&lt;/code&gt; function passing to the &lt;code&gt;ChildComponent&lt;/code&gt;. When the App component re-renders, even when the count button is not clicked, the function redefines, making the &lt;code&gt;ChildComponent&lt;/code&gt; also re-render.&lt;/p&gt;

&lt;p&gt;To prevent the function from always redefining, we will use a &lt;code&gt;useCallback&lt;/code&gt; Hook that returns a memoized version of the callback between renders.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using the &lt;code&gt;useCallback&lt;/code&gt; Hook
&lt;/h3&gt;

&lt;p&gt;With the &lt;code&gt;useCallback&lt;/code&gt; Hook, the &lt;code&gt;incrementCount&lt;/code&gt; function only redefines when the count dependency array changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const incrementCount = React.useCallback(() =&amp;gt; setCount(count + 1), [count]);

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Using the &lt;code&gt;useMemo&lt;/code&gt; Hook
&lt;/h3&gt;

&lt;p&gt;When the prop we pass down to a child component is an array or object, we can use a &lt;code&gt;useMemo&lt;/code&gt; Hook to memoize the value between renders. As weve learned above, these values point to different spaces in memory and are entirely new values.&lt;/p&gt;

&lt;p&gt;You can also use the &lt;code&gt;useMemo&lt;/code&gt; Hook to avoid re-computing the same expensive value in a component. It allows us to &lt;code&gt;memoize&lt;/code&gt; these values and only re-compute them if the dependencies change.&lt;/p&gt;

&lt;p&gt;Similar to &lt;code&gt;useCallback&lt;/code&gt;, the &lt;code&gt;useMemo&lt;/code&gt; Hook also expects a function and an array of dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const memoizedValue = React.useMemo(() =&amp;gt; {
  // return expensive computation
}, []);

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

&lt;/div&gt;



&lt;p&gt;Lets see how to apply the useMemo Hook to improve a React apps performance. Take a look at the following code that weve intentionally delayed to be very slow.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from "react";

const expensiveFunction = (count) =&amp;gt; {
  // artificial delay (expensive computation)
  for (let i = 0; i &amp;lt; 1000000000; i++) {}
  return count * 3;
};

export default function App() {
  // ...
  const myCount = expensiveFunction(count);
  return (
    &amp;lt;div&amp;gt;
      {/* ... */}
      &amp;lt;h3&amp;gt;Count x 3: {myCount}&amp;lt;/h3&amp;gt;
      &amp;lt;hr /&amp;gt;
      &amp;lt;ChildComponent count={count} onClick={incrementCount} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

const ChildComponent = React.memo(function ChildComponent({ count, onClick }) {
  // ...
});

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

&lt;/div&gt;



&lt;p&gt;Every time the App component renders, it invokes the &lt;code&gt;expensiveFunction&lt;/code&gt; and slows down the app.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;expensiveFunction&lt;/code&gt; should only be called when the count button is clicked, not when we type in the input field. We can &lt;code&gt;memoize&lt;/code&gt; the returned value of the &lt;code&gt;expensiveFunction&lt;/code&gt; using the &lt;code&gt;useMemo&lt;/code&gt; Hook so that it only re-computes the function only when needed, i.e., when the count button is clicked.&lt;/p&gt;

&lt;p&gt;For that, we will have something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myCount = React.useMemo(() =&amp;gt; {
  return expensiveFunction(count);
}, [count]);

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

&lt;/div&gt;



&lt;p&gt;Optimization techniques come with a cost if not used properly and wrapping everything in &lt;code&gt;memo&lt;/code&gt; or &lt;code&gt;useCallback&lt;/code&gt; won't magically make your apps fast, but using them properly and profiling along the way could be a lifesaver.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Windowing or list virtualization in React applications
&lt;/h2&gt;

&lt;p&gt;When you want to render an enormous table or list of data, it can significantly slow down your apps performance. Virtualization can help in a scenario like this with the help of a library like react-window. react-window helps solve this problem by rendering only the items in the list that are currently visible, which allows for efficiently rendering lists of any size.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Lazy loading images in React
&lt;/h2&gt;

&lt;p&gt;To optimize an application that consists of several images, we can avoid rendering all of the images at once to improve the page load time. With lazy loading, we can wait until each of the images is about to appear in the viewport before we render them in the DOM.&lt;/p&gt;

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

&lt;p&gt;To optimize our React application, we must first find a performance problem in our application to rectify. In this guide, weve explained how to measure the performance of a React application and how to optimize the performance for a better user experience.&lt;/p&gt;

&lt;p&gt;If you find these techniques helpful do share them with others and also I would love to know of any other techniques, so do comment down below&lt;/p&gt;

</description>
      <category>react</category>
      <category>optimization</category>
    </item>
    <item>
      <title>Temporal Dead Zone</title>
      <dc:creator>bhtibrewal</dc:creator>
      <pubDate>Sun, 09 Jan 2022 13:32:33 +0000</pubDate>
      <link>https://dev.to/bhtibrewal/temporal-dead-zone-j46</link>
      <guid>https://dev.to/bhtibrewal/temporal-dead-zone-j46</guid>
      <description>&lt;p&gt;This phrase seems intimidating, right? Let's make it easy for you and start by breaking the term into pieces. Temporal means something that is temporary, Dead means something that is lifeless, and Zone in programming terms can be interpreted as the memory. The Timespan between the creation of a variable and its declaration is called the Temporal Dead Zone.&lt;/p&gt;

&lt;p&gt;This term came into existence in ES6 with the introduction of let and const to help developers write better code and make debugging easy, by telling them that they are accessing some data before defining it.&lt;/p&gt;

&lt;p&gt;Before ES6 there was no other way to declare variables other than var, and if var variables are accessed before declaration it would give us &lt;code&gt;undefined&lt;/code&gt; instead.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(b);// output -&amp;gt; undefined
var b=100;

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

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; declarations are both block-scoped, which means they are only accessible within the { } surrounding them.&lt;/p&gt;

&lt;p&gt;There's a common misconception that TDZ means let and const do not hoist. This is an inaccurate, or at least slightly misleading, claim. They definitely hoist. Read more about hoisting &lt;a href="https://dev.toLink"&gt;here&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var a = 100;
if (true){
   console.log(a);// a is in TDZ
   let a = 10;
}
output-&amp;gt; ReferenceError: Cannot access 'a' before initialization

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

&lt;/div&gt;



&lt;p&gt;What's going to happen with the console.log(..) statement? If let &lt;code&gt;a&lt;/code&gt; didn't hoist to the top of the scope, then the console.log(..) should print 100, right? At that moment, it would seem, only the outer &lt;code&gt;a&lt;/code&gt; exists, so that's the variable console.log(..) should access and print.&lt;/p&gt;

&lt;p&gt;But instead, the console.log(..) throws a TDZ error, because, the inner scope's &lt;code&gt;a&lt;/code&gt; was hoisted. What didn't happen (yet!) was the auto-initialization of that inner &lt;code&gt;a&lt;/code&gt;; it's still uninitialized at that moment, hence the TDZ violation!&lt;/p&gt;

&lt;p&gt;So to summarize, TDZ errors occur because &lt;code&gt;let/const&lt;/code&gt; declarations do hoist their declarations to the top of their scopes, but unlike &lt;code&gt;var&lt;/code&gt;, they defer the auto-initialization of their variables until the moment in the code's sequencing where the original declaration appeared.&lt;/p&gt;

&lt;p&gt;The TDZ can also be created for default function parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function createTDZ(a=b, b) {
// some code here
}

createTDZ(undefined, 1); 
// output -&amp;gt; ReferenceError

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

&lt;/div&gt;



&lt;p&gt;As arguments are evaluated from left to right, the evaluation of variable &lt;code&gt;a&lt;/code&gt; tries to access variable &lt;code&gt;b&lt;/code&gt; before it has been parsed by the JS engine. The function arguments are all inside the TDZ until they are parsed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Another Example:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By the way, "temporal" in TDZ does indeed refer to time not position in code. Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a = f(); 
const b = 2;
function f() { return b; } // b is in the TDZ

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

&lt;/div&gt;



&lt;p&gt;Even though positionally the &lt;code&gt;return&lt;/code&gt; referencing &lt;code&gt;b&lt;/code&gt; comes after the &lt;code&gt;const b = 2;&lt;/code&gt; declaration, timing-wise the f() function is invoked before the let statement is encountered, while &lt;code&gt;b&lt;/code&gt; is still in its TDZ! Hence the ReferenceError.&lt;/p&gt;

&lt;h3&gt;
  
  
  Takeaway:
&lt;/h3&gt;

&lt;p&gt;To avoid TDZ, always make sure you define your &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; at the top of any scope. Shrink the TDZ window to zero (or near zero) length, and then it'll be moot.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>CSS Box Model: For a 5-year-old</title>
      <dc:creator>bhtibrewal</dc:creator>
      <pubDate>Mon, 08 Nov 2021 10:52:00 +0000</pubDate>
      <link>https://dev.to/bhtibrewal/css-box-model-for-a-5-year-old-2hn8</link>
      <guid>https://dev.to/bhtibrewal/css-box-model-for-a-5-year-old-2hn8</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;When you're starting off with learning HTML and CSS, things can get overwhelming pretty quickly.&lt;/p&gt;

&lt;p&gt;You find that there's a plethora of HTML elements and CSS properties and values, and you start thinking that you need to start memorizing them all. (I got panicked by this thought) But you are wrong ( I was also ) thanks to Google you don't have to memorize them, you can look up things when you need them (and yes that's not cheating).&lt;/p&gt;

&lt;p&gt;All you have to do is learn the basic concepts and in the case of CSS, the box model is one such concept. Before we dive deeper, let's first understand that &lt;strong&gt;every element in web design is a rectangular box nested inside other rectangular boxes.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Box-Model
&lt;/h2&gt;

&lt;p&gt;It's a CSS standard that represents the elements of a document as boxes with certain properties (sizing, positioning, a stack of elements...) based on CSS styles. The box model is the basic building block of CSS. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C7vGOBNP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1636312417796/65As0bKaB.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C7vGOBNP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1636312417796/65As0bKaB.png" alt="Box Model" width="709" height="493"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Content:&lt;/strong&gt; content of our element that has a specific width and height. A fixed height and width can be set using the &lt;code&gt;height&lt;/code&gt; and &lt;code&gt;width&lt;/code&gt; properties.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Padding area:&lt;/strong&gt; space between the content and the border. The size of this area is defined by the &lt;code&gt;padding&lt;/code&gt; property defined in the order: top, right, bottom, and left. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Border area:&lt;/strong&gt; space between the padding and the margin. The size of this area is defined by the &lt;code&gt;border-width&lt;/code&gt; property.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Margin area:&lt;/strong&gt; space between an element and its neighbors. The size of this area is defined by the &lt;code&gt;margin&lt;/code&gt; property, negative values can be provided for margins.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Inline elements:
&lt;/h3&gt;

&lt;p&gt;Inline elements take only the space as that of their content. They do not start on a new line. Examples: a, span, strong, and etc.&lt;/p&gt;

&lt;p&gt;When using inline elements it is not possible to set a fixed width or height for that element, since the element doesnt have any predetermined width and height (because the width and height are determined by the content).&lt;/p&gt;

&lt;h3&gt;
  
  
  Block element:
&lt;/h3&gt;

&lt;p&gt;Elements of this type have their &lt;code&gt;display&lt;/code&gt; property set to block. They take their entire row as its space. They always start on a new line. Eg: div, h1, p and etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inline-Block elements:
&lt;/h3&gt;

&lt;p&gt;These are exactly the same as inline just one basic difference is that in inline-block elements you can adjust the height and width of the element, which you cannot do on inline elements. They sit next to the previous element if there's remaining space, or start on a new line otherwise. Eg: button&lt;/p&gt;

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

&lt;p&gt;So that was CSS box model one topic off the &lt;strong&gt;web development learn list&lt;/strong&gt; and many more to go.&lt;/p&gt;

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