<?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: Anojan Thevarasa</title>
    <description>The latest articles on DEV Community by Anojan Thevarasa (@anojtheva789).</description>
    <link>https://dev.to/anojtheva789</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%2F908902%2F0c3136cf-3849-4853-8e96-fc2595fd49b0.JPG</url>
      <title>DEV Community: Anojan Thevarasa</title>
      <link>https://dev.to/anojtheva789</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anojtheva789"/>
    <language>en</language>
    <item>
      <title>ReactJS: prop-drilling and how to work-around it with useContext hook</title>
      <dc:creator>Anojan Thevarasa</dc:creator>
      <pubDate>Tue, 09 Apr 2024 15:33:51 +0000</pubDate>
      <link>https://dev.to/anojtheva789/reactjs-prop-drilling-and-how-to-work-around-it-with-usecontext-hook-dfg</link>
      <guid>https://dev.to/anojtheva789/reactjs-prop-drilling-and-how-to-work-around-it-with-usecontext-hook-dfg</guid>
      <description>&lt;p&gt;A traditional ReactJS application is built using components which represent a part of UI on the application. A component facilitates reusability of data in an application. When we have multiple components, we may have to use data like variables and functions repeatedly across these components. This calls for passing of such reusable data from one component to other and this is where "props" come into play.&lt;/p&gt;

&lt;p&gt;Let's look at a very simple example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Greeting(props) {
  return &amp;lt;h1&amp;gt;Welcome to the city, {props.name}&amp;lt;/h1&amp;gt;;
}

function App() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;Greeting name="Denis" /&amp;gt;
      &amp;lt;Greeting name="Chris" /&amp;gt;
      &amp;lt;Greeting name="Rajni" /&amp;gt;
      &amp;lt;Greeting name="Deva" /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, a greeting text can be repeated for 4 different instances/names, using the props for name variable. The App function/component's variables are passed into the Greeting function/component using props.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prop-Drilling
&lt;/h2&gt;

&lt;p&gt;Passing data from one component to another has its own rules. Usually data can be passed from a parent to a child component using props. In most of the applications, these props may have to be passed from parent component to down the hierarchy across several child and grandchild components and so on. This results in a large number of nested components. &lt;/p&gt;

&lt;p&gt;By default, props can be passed from a parent component only to the immediate next child component in the hierarchy. Suppose a child/grandchild component somewhere far down the line requires the props from the parent component, the props can't be passed directly but only by going through other child components in between, even if those middle child components don't require the props. This phenomenon is called prop-drilling which is obviously not the best coding practice.&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%2Fbur58s1u0hfd3bc6avtu.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%2Fbur58s1u0hfd3bc6avtu.png" alt="Prop-drilling in ReactJS (source:react.dev docs)" width="800" height="532"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Prop-drilling in ReactJS (source:react.dev docs)&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  useContext
&lt;/h2&gt;

&lt;p&gt;There's a workaround for this prop-drilling in ReactJS. Most times, there may be a need for passing props from the parent component to some distant child component and not to the components in between. This is possible through the Context API in React, by using a hook called &lt;em&gt;useContext&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;In order to deploy Context for components, we need to first Create the Context using &lt;em&gt;createContext&lt;/em&gt;, then wrap the child components using &lt;em&gt;Context Provider&lt;/em&gt; and finally use the &lt;em&gt;useContext&lt;/em&gt; hook from react library. Let's look at the structure of useContext step by step through a simple example where the DOM displays the game level in which a Player is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First import the necessary hooks from react library
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState, createContext, useContext } from "react"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Then create a Context for the Level using &lt;em&gt;createContext&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const LevelContext = createContext()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Create the first Component for displaying a message when user is at Level 01. The first level is initiated using useState.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Component1() {
  const [level, setLevel] = useState("Level 01")
  return (
    &amp;lt;LevelContext.Provider value={level}&amp;gt;
      &amp;lt;h1&amp;gt;{`You are in ${level}!`}&amp;lt;/h1&amp;gt;
      &amp;lt;Component2 /&amp;gt;
    &amp;lt;/UserContext.Provider&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Create rest of the components by hardcoding the level except for the last one which will use Context to take props from Level 01 parent component.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Component2() {
  return (
    &amp;lt;&amp;gt;
      &amp;lt;h1&amp;gt;Level 02&amp;lt;/h1&amp;gt;
      &amp;lt;Component3 /&amp;gt;
    &amp;lt;/&amp;gt;
  );
}
function Component3() {
  return (
    &amp;lt;&amp;gt;
      &amp;lt;h1&amp;gt;Level 03&amp;lt;/h1&amp;gt;
      &amp;lt;Component4 /&amp;gt;
    &amp;lt;/&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Finally the Component 4 will use props from Component 1 directly without involving the components in between
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Component4() {
  const level = useContext(LevelContext);

  return (
    &amp;lt;&amp;gt;
      &amp;lt;h1&amp;gt;Component 4&amp;lt;/h1&amp;gt;
      &amp;lt;h1&amp;gt;{`You are at ${level} again!`}&amp;lt;/h1&amp;gt;
    &amp;lt;/&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here is the whole code altogether:&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, createContext, useContext } from "react"

const LevelContext = createContext()

function Component1() {
  const [level, setLevel] = useState("Level 01")

  return (
    &amp;lt;LevelContext.Provider value={level}&amp;gt;
      &amp;lt;h1&amp;gt;{`You are in ${level}!`}&amp;lt;/h1&amp;gt;
      &amp;lt;Component2 /&amp;gt;
    &amp;lt;/UserContext.Provider&amp;gt;
  );
}

function Component2() {
  return (
    &amp;lt;&amp;gt;
      &amp;lt;h1&amp;gt;Level 02&amp;lt;/h1&amp;gt;
      &amp;lt;Component3 /&amp;gt;
    &amp;lt;/&amp;gt;
  );
}

function Component3() {
  return (
    &amp;lt;&amp;gt;
      &amp;lt;h1&amp;gt;Level 03&amp;lt;/h1&amp;gt;
      &amp;lt;Component4 /&amp;gt;
    &amp;lt;/&amp;gt;
  );
}

function Component4() {
  const level = useContext(LevelContext);

  return (
    &amp;lt;&amp;gt;
      &amp;lt;h1&amp;gt;Component 4&amp;lt;/h1&amp;gt;
      &amp;lt;h1&amp;gt;{`You are at ${level} again!`}&amp;lt;/h1&amp;gt;
    &amp;lt;/&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output for this is:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;You are at Level 01!&lt;br&gt;
Level 02&lt;br&gt;
Level 03&lt;br&gt;
You are at Level 01 again!&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Javascript: Function Declaration vs Function Expression</title>
      <dc:creator>Anojan Thevarasa</dc:creator>
      <pubDate>Tue, 31 Oct 2023 14:13:03 +0000</pubDate>
      <link>https://dev.to/anojtheva789/javascript-function-declaration-vs-function-expression-38f0</link>
      <guid>https://dev.to/anojtheva789/javascript-function-declaration-vs-function-expression-38f0</guid>
      <description>&lt;p&gt;Functions in Javascript are a block of code that execute an action/operation. Functions can take in parameters while being defined and later the parameters shall be passed as arguments while calling. There are, however, two ways in which a function is defined in Javascript based on when the particular function should be executed. One is called Function Declaration and the other way is Function Expressions. There are some differences in the defining and behaviour of the two methods. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function Declaration&lt;/strong&gt;&lt;br&gt;
Function declaration is defining a function right off with the keyword "function" followed by function name, with or without parameters. The syntax for function declaration is:&lt;br&gt;
&lt;code&gt;function exampleFunction (param1,param2, etc){ &lt;br&gt;
//action to execute &lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here's an example function declaration that takes in two int values for parameters and returns the sum of them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function addition(a,b){
  return sum = a + b
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Function Expression&lt;/strong&gt;&lt;br&gt;
This is the way in which functions are defined and equaled(stored in) to a variable name usually with the keyword &lt;em&gt;const&lt;/em&gt;. And later the variable name containing the function can be called. Syntax for a function expression is as follows:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const functionName = function(param1,param2,etc) {&lt;br&gt;
    // action to execute&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The same example sum function from above can be defined in an expression as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const addition = function(a,b){
  return sum = a + b
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Major Difference&lt;/strong&gt;&lt;br&gt;
Both function declaration and function expression are used in Javascript and its frameworks based on some factors, the main of which is the time when a function has to be called for execution. By default, &lt;strong&gt;function declarations are hoisted&lt;/strong&gt;, i.e. they take the top of the order of execution in a block of code irrespective of where they are defined. This way a function can be called either before or after it is defined.&lt;/p&gt;

&lt;p&gt;On the other hand, &lt;strong&gt;a function expression is not hoisted&lt;/strong&gt;. A function defined through expression is usually executed only in the order of where it is defined, in accordance with the synchronous nature of Javascript. Such a function can be called for execution only after it is defined and not before.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Different approaches to Conditional Rendering in React.js and when to use which!</title>
      <dc:creator>Anojan Thevarasa</dc:creator>
      <pubDate>Thu, 21 Sep 2023 09:47:05 +0000</pubDate>
      <link>https://dev.to/anojtheva789/different-approaches-to-conditional-rendering-in-reactjs-and-when-to-use-which-2fkb</link>
      <guid>https://dev.to/anojtheva789/different-approaches-to-conditional-rendering-in-reactjs-and-when-to-use-which-2fkb</guid>
      <description>&lt;h2&gt;
  
  
  Conditional Rendering
&lt;/h2&gt;

&lt;p&gt;Conditional rendering in React.js is all about using the conditional operators of Javascript to dynamically render something out to the ReactDOM if and only when a specific condition is met. The 2 main types of conditional operators used in React rendering are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&amp;amp;&amp;amp; (the AND) operator&lt;/li&gt;
&lt;li&gt;Ternary Operator&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. &amp;amp;&amp;amp; (the AND) operator
&lt;/h2&gt;

&lt;p&gt;The &amp;amp;&amp;amp; operator checks for truthy or flasy (boolean) nature of an expression which can be taken advantage of for whether to render the given element or not. In other words, &amp;amp;&amp;amp; operator can be used to determine to render something or not to render.&lt;br&gt;
The syntax for the same would be:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;condition &amp;amp;&amp;amp; expressionToRender&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For example, in order to render out a message when the number of messages meet a specific condition, it can be achieved as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;notifications.length &amp;gt; 0 &amp;amp;&amp;amp; 
&amp;lt;h1&amp;gt;You have {notifications.length} notifications!&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Ternary Operator
&lt;/h2&gt;

&lt;p&gt;A ternary operator makes use of the &lt;em&gt;truthy&lt;/em&gt; and &lt;em&gt;falsy&lt;/em&gt; conditions existing in Javascript universe. The ternary operator can be substituted in place of the verbose "if else" and "switch" statements, if the options are just two. The syntax for a Ternary operator is: &lt;br&gt;
&lt;code&gt;condition ? expressionIfTrue : expressionIfFalse&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If the condition is true, the first expression after '?' gets executed; and if it is false, the second expression after ':' is executed. So in simple terms, the ternary operator can be used to render one of the given 2 expressions.&lt;/p&gt;

&lt;p&gt;For example, in the same situation as above, to render out either of 2 different messages based on the length of notifications:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; notifications.length === 0 ?
                &amp;lt;h1&amp;gt;You're all caught up!&amp;lt;/h1&amp;gt; :
                &amp;lt;h1&amp;gt;You have {notifications.length} unread  
               notifications&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the message "You're all caught up!" (after "?") will be rendered out (displayed) if the notifications (stored in array) has 0 or no notification, which is checked using &lt;em&gt;array.length&lt;/em&gt; method (before "?"). And if the notifications are 1 or more, the message in second &lt;em&gt;h1&lt;/em&gt; element (after ":") will be displayed (along with number of notifications derived with same &lt;em&gt;array.method&lt;/em&gt; )&lt;/p&gt;

&lt;h2&gt;
  
  
  If Else and Switch statements
&lt;/h2&gt;

&lt;p&gt;Though ternary operator can be used for more than 3 expressions as well, it's best practice to use if else or switch statements if the options are more than 2, to avoid complexity. &lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>'Lists' in HTML</title>
      <dc:creator>Anojan Thevarasa</dc:creator>
      <pubDate>Tue, 04 Oct 2022 19:39:27 +0000</pubDate>
      <link>https://dev.to/anojtheva789/lists-in-html-37jl</link>
      <guid>https://dev.to/anojtheva789/lists-in-html-37jl</guid>
      <description>&lt;p&gt;While building a web page, there will be situations when we have to place a group of items next to each other. Just like conventional writing, a web page of text content may include paragraphs, media and lists. HTML has provisions for creating such lists with the aid of some elements. Firstly let's look at the various kinds of lists we could have.&lt;/p&gt;

&lt;p&gt;Lists in HTML are of 3 types:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Unordered List&lt;/li&gt;
&lt;li&gt;Ordered List&lt;/li&gt;
&lt;li&gt;Description List&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Unordered List&lt;/strong&gt;&lt;br&gt;
An Unordered List usually consists of related items that don't necessarily have to be in any particular order. An example can be a list of groceries or a list of travel essentials. Unordered lists in HTML are created using the &lt;em&gt;ul&lt;/em&gt; tag. And each item of the list is created using the &lt;em&gt;li&lt;/em&gt; tag. The list items by default take a bullet style.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SOVdk92R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s2z9w23geimir48jh3dr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SOVdk92R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s2z9w23geimir48jh3dr.png" alt="Creating Unordered Lists in HTML" width="800" height="324"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ds7xUJYG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xpz5iyjgtwvwuhdv06jr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ds7xUJYG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xpz5iyjgtwvwuhdv06jr.png" alt="Unordered Lists Output" width="800" height="279"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ordered List&lt;/strong&gt;&lt;br&gt;
An Ordered List usually consists of items that have to be in some particular order or hierarchy. An example would be a list of to do items or a recipe. Ordered lists in HTML are created using the &lt;em&gt;ol&lt;/em&gt; tag. And same as unordered list, each item of the ordered list is also created using the &lt;em&gt;li&lt;/em&gt; tag. The items in an ordered list by default are marked using numbers in increasing order.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SkWZGhMO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m15pquwxvphwogdyzjkm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SkWZGhMO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m15pquwxvphwogdyzjkm.png" alt="Creating Ordered Lists in HTML" width="800" height="304"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m_Cr8vFT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l26whg8tp9hp3d6zgyxl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m_Cr8vFT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l26whg8tp9hp3d6zgyxl.png" alt="Ordered Lists Output" width="800" height="264"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Description List&lt;/strong&gt;&lt;br&gt;
The description list is a unique type of list which is used to display a list of terms followed by the description of those terms. In a Description List, the tag that denotes the list is &lt;em&gt;dl&lt;/em&gt;. The name/term is created using &lt;em&gt;dt&lt;/em&gt; tag and the description for the term is created using the &lt;em&gt;dd&lt;/em&gt; tag.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0Pg62j0K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/773jj3ndalgpzxgon6wy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0Pg62j0K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/773jj3ndalgpzxgon6wy.png" alt="Creating Description Lists in HTML" width="800" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--30d7-CmX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/83c3h3aym6kqxrdseoks.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--30d7-CmX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/83c3h3aym6kqxrdseoks.png" alt="Description Lists Output" width="728" height="262"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>html</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Inline-Block in CSS</title>
      <dc:creator>Anojan Thevarasa</dc:creator>
      <pubDate>Mon, 22 Aug 2022 10:50:19 +0000</pubDate>
      <link>https://dev.to/anojtheva789/inline-block-in-css-4nk0</link>
      <guid>https://dev.to/anojtheva789/inline-block-in-css-4nk0</guid>
      <description>&lt;p&gt;Every HTML element is a piece of rectangle in CSS. When building a web page, the different elements will have to be displayed in various formats and sometimes have to be hidden too. This is where the &lt;em&gt;Display&lt;/em&gt; property comes into play. There are 3 major Display properties &lt;em&gt;Block, Inline &amp;amp; Inline-Block&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Block&lt;/strong&gt; level elements by default take up the entire space of the row they are in, whatever width we provide or even if we don't provide a width at all. This way, multiple block level elements end up being placed one below other. The elements don't show up next to each other, even if there is available space.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BcrUYac2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ob0cy75xgusr4qn9qel.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BcrUYac2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ob0cy75xgusr4qn9qel.png" alt="CSS for block display" width="800" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OjdL5kVj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ob721qioyd0qetmah47q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OjdL5kVj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ob721qioyd0qetmah47q.png" alt="Block Output" width="800" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inline&lt;/strong&gt; level elements align horizontally and next to each other in the same row, as long as there is space. However, it is to be noted that we can't provide a width or height to the inline elements like we can for block-level elements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4C2UL9d7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4uyjsk03fugkp90lzvqa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4C2UL9d7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4uyjsk03fugkp90lzvqa.png" alt="CSS for inline display" width="800" height="357"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bXVP768P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/98kumij8ihk8kr7jlsnd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bXVP768P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/98kumij8ihk8kr7jlsnd.png" alt="Inline Output" width="718" height="172"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So what if we want to display elements next to each other and also have them adopt width and height that we provide? That is where Inline-block Display option proves to be handy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inline-Block
&lt;/h2&gt;

&lt;p&gt;The inline-block property of Display takes the best of bothe worlds. With an inline-block display property we can have elements being placed next to each other in same row like inline elements do. And we can also provide width and height for the elements like we are able to do in a block-level element. So inline-block has been a widely used Display property, apart from the recent and most popular Flex property.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PT7EhUD7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ve1myadh68lnjz3kvrp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PT7EhUD7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ve1myadh68lnjz3kvrp.png" alt="CSS for inline-block display" width="800" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PfVKAZOR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mv6lctl8g8pegyzeakav.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PfVKAZOR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mv6lctl8g8pegyzeakav.png" alt="inline-block output" width="800" height="273"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>boxmodel</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
