<?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: Waqas Khan</title>
    <description>The latest articles on Forem by Waqas Khan (@waqaskhan).</description>
    <link>https://forem.com/waqaskhan</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%2F890439%2F8f557f35-b042-4f21-bda7-0f1d8f795038.jpeg</url>
      <title>Forem: Waqas Khan</title>
      <link>https://forem.com/waqaskhan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/waqaskhan"/>
    <language>en</language>
    <item>
      <title>Mastering Parent-Child Communication with useImperativeHandle Hook in React</title>
      <dc:creator>Waqas Khan</dc:creator>
      <pubDate>Tue, 18 Apr 2023 04:40:45 +0000</pubDate>
      <link>https://forem.com/waqaskhan/mastering-parent-child-communication-with-useimperativehandle-hook-in-react-4ja0</link>
      <guid>https://forem.com/waqaskhan/mastering-parent-child-communication-with-useimperativehandle-hook-in-react-4ja0</guid>
      <description>&lt;h1&gt;
  
  
  Intro:
&lt;/h1&gt;

&lt;p&gt;In &lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt;, a parent component passes props down to a child component, and if the parent component needs to call a function defined in the child component, it typically must be defined in the parent component and then passed down. However, there is a way to break this rule using the &lt;code&gt;useImperativeHandle&lt;/code&gt; hook.&lt;/p&gt;

&lt;h1&gt;
  
  
  The useImperativeHandle:
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;useImperativeHandle&lt;/code&gt; hook is used to expose functions from a child component to a parent component. The useImperativeHandle hook takes a ref as its first argument, some handles as its second argument, and optional dependencies if any. useImperativeHandle returns undefined. It cannot be used alone and must be used with the useRef hook and the forwardRef component.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://react.dev/reference/react/useRef"&gt;useRef&lt;/a&gt; hook is used to create a reference to a DOM node or a value that persists across renders. The &lt;a href="https://react.dev/reference/react/forwardRef"&gt;forwardRef &lt;/a&gt;component is used to pass the ref from the parent component to the child component.&lt;/p&gt;

&lt;p&gt;Let's take a look at the basic syntax to understand all those jargon. &lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Syntax:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;useImperativeHandle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;createHandle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dependencies&lt;/span&gt;&lt;span class="p"&gt;?)&lt;/span&gt;
&lt;span class="c1"&gt;// or &lt;/span&gt;
&lt;span class="nx"&gt;useImperativeHandle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// ... your methods ...&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;h3&gt;
  
  
  Examples:
&lt;/h3&gt;

&lt;p&gt;Let's start better understanding by looking at the following diagram. The useRef hook was defined in the parent component and passed as props to the child component. In the child component, we access the ref and passed it down to useImperativeHandle. useImperativeHandle lets us customize the handle exposed as a ref. The  createHandle is a function that takes no arguments and returns the ref handles we want to expose. That ref handle can have any type. Usually, you will return an object with the methods you want to expose. The forwardRef is used to expose any DOM node to the parent. To do that, wrap your component definition into forwardRef which will receive a ref as the second argument after props.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Parent Component:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useRef&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Modal&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./Modal&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;modalRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleOpenModal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&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;modalRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;openModal&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;parent rendered&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;main&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Parent&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Modal&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;modalRef&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleOpenModal&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Open&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/main&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Child Component:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;forwardRef&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useImperativeHandle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Modal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;modalState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setModalState&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;useImperativeHandle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;openModal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setModalState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}));&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;child rendered&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;modalState&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;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;modal&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;my&lt;/span&gt; &lt;span class="nx"&gt;modal&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setModalState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Close&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;forwardRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Modal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Best Practices:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Limit the number of exposed methods&lt;/li&gt;
&lt;li&gt;useImperativeHandle should only be used when necessary. In most cases, it's better to use props and callbacks to communicate between parent and child components.&lt;/li&gt;
&lt;li&gt;Avoid circular dependencies: useImperativeHandle can create circular dependencies between parent and child components.&lt;/li&gt;
&lt;li&gt;Consider using &lt;a href="https://www.typescriptlang.org/"&gt;TypeScript&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Conclusion:&lt;br&gt;
The useImperativeHandle hook allows you to call a function defined in the child component from the parent component, breaking the typical rule of defining functions in the parent component and passing them down. This hook, used in conjunction with the useRef hook and the forwardRef component, gives you greater flexibility and control over your components.&lt;/p&gt;

&lt;p&gt;Thank you for taking the time to read this blog. I hope it has been informative and has helped you gain a deeper understanding of the topic. If you have any feedback or suggestions for future content, please let me know!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>HTML Tags: Most Beginner does not know (Part 3)</title>
      <dc:creator>Waqas Khan</dc:creator>
      <pubDate>Thu, 18 Aug 2022 17:12:00 +0000</pubDate>
      <link>https://forem.com/waqaskhan/html-tags-most-beginner-does-not-know-part-3-44ae</link>
      <guid>https://forem.com/waqaskhan/html-tags-most-beginner-does-not-know-part-3-44ae</guid>
      <description>&lt;p&gt;In process of learning HTML basics, every beginner knows dev tag, h1 to h6 tags, p tags and few more, but most of the beginner does not know about details tags, table tags and many more like this because he/she thinks its high-level things but its not. Believe me its that easy as h1 and p tags. Let break down these tags...&lt;/p&gt;

&lt;h2&gt;
  
  
  1) Base tag:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Use:
&lt;/h3&gt;

&lt;p&gt;It is use when you add some assets in your site from same site again and again then the basic URL is placed in base tag and remaining part of that URL is placed where required.&lt;br&gt;
let me show how and what I meant by that:&lt;br&gt;&lt;br&gt;
Without Base tag 👇&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;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;img src="https://cutt.ly/XXvfnhj" alt="Smoke-image"&amp;gt;
    &amp;lt;img src="https://cutt.ly/wXvfO3U" alt="Red leaves on Floor"&amp;gt;
    &amp;lt;img src="https://cutt.ly/VXvfZNl" alt="Sky with Stars"&amp;gt;
    &amp;lt;img src="https://cutt.ly/vXvgeBw" alt="A paint"&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you notice I have place 4 images from same site and I am repeatedly using that site. So why not to common this "&lt;a href="https://cutt.ly"&gt;https://cutt.ly&lt;/a&gt;" site, 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;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;base href="https://cutt.ly" target="_blank"&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;img src="/XXvfnhj" alt=""&amp;gt;
    &amp;lt;img src="/wXvfO3U" alt=""&amp;gt;
    &amp;lt;img src="/VXvfZNl" alt=""&amp;gt;
    &amp;lt;img src="/vXvgeBw" alt="Jungle"&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And its not only limit to img tags, it can be use anywhere that is in anchor tags, as links, refences etc. That's it. &lt;br&gt;
Let’s jump to the Table tag.&lt;/p&gt;
&lt;h2&gt;
  
  
  2) Table tag:
&lt;/h2&gt;

&lt;p&gt;Table tag is answer to this question-&amp;gt; How to make tables on web using HTML? So, with table tags we can basically make tables.&lt;/p&gt;
&lt;h3&gt;
  
  
  Basic Syntax:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;table&amp;gt;
        &amp;lt;caption&amp;gt;&amp;lt;/caption&amp;gt;
        &amp;lt;tr&amp;gt; 
            &amp;lt;th&amp;gt;Colum 1 title&amp;lt;/th&amp;gt;
            &amp;lt;th&amp;gt;Colum 2 title&amp;lt;/th&amp;gt;
        &amp;lt;/tr&amp;gt;
        &amp;lt;tr&amp;gt;
            &amp;lt;td&amp;gt;Colum 1 data&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;Colum 2 title&amp;lt;/td&amp;gt;
        &amp;lt;/tr&amp;gt;        
    &amp;lt;/table&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Bear with me I am going to explain everything. let’s break down its syntax:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;table tag-&amp;gt; define that it is a table&lt;/li&gt;
&lt;li&gt;caption tag-&amp;gt; define the main title of the table.&lt;/li&gt;
&lt;li&gt;tr tag -&amp;gt; mean Table Row.&lt;/li&gt;
&lt;li&gt;th tag -&amp;gt; mean table header, actually table column header.&lt;/li&gt;
&lt;li&gt;td tag -&amp;gt; table data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keep these short words in mind it will work for you.&lt;/p&gt;

&lt;p&gt;Now let’s understand it with an example.&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;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;style&amp;gt;
        table,
        th,
        td {
            border: 1px solid black;
        }
        table{
            width: 500px;
            text-align: center;
        }
    &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;

    &amp;lt;table&amp;gt; &amp;lt;!-- Table  --&amp;gt;
        &amp;lt;caption&amp;gt;This main title of the table&amp;lt;/caption&amp;gt; &amp;lt;!-- Table Title--&amp;gt;
        &amp;lt;tr&amp;gt; &amp;lt;!-- Table Row --&amp;gt;
            &amp;lt;th&amp;gt;Items&amp;lt;/th&amp;gt; &amp;lt;!-- Table header --&amp;gt;
            &amp;lt;th&amp;gt;Price&amp;lt;/th&amp;gt;
        &amp;lt;/tr&amp;gt;
        &amp;lt;tr&amp;gt; 
            &amp;lt;td&amp;gt;Jacket&amp;lt;/td&amp;gt; &amp;lt;!-- Table data--&amp;gt;
            &amp;lt;td&amp;gt;$100&amp;lt;/td&amp;gt;
        &amp;lt;/tr&amp;gt;
        &amp;lt;tr&amp;gt;
            &amp;lt;td&amp;gt;Suit&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;$80&amp;lt;/td&amp;gt;
        &amp;lt;/tr&amp;gt;
        &amp;lt;tr&amp;gt;
            &amp;lt;td&amp;gt;Trouser&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;$45&amp;lt;/td&amp;gt;
        &amp;lt;/tr&amp;gt;
    &amp;lt;/table&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output:
&lt;/h3&gt;

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

&lt;p&gt;if you don't understand, copy the code, paste it in VS code and open it with live server. Change some values and you will understand what is going on.&lt;/p&gt;

&lt;h2&gt;
  
  
  3) Datalist Tag:
&lt;/h2&gt;

&lt;p&gt;Use: Datalist tag use where a user has to choose some options for input field. OR developer want to provide some pre-set data for the user to choose. &lt;/p&gt;

&lt;h3&gt;
  
  
  Basic Syntax:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;datalist&amp;gt;
    &amp;lt;option value="data 1"&amp;gt;
    &amp;lt;option value="data 2"&amp;gt;
  &amp;lt;/datalist&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Datalist tag contains some options to provide and all those options remains in whole datalist tag. I have provided an example below I tried to shortened as much as I can.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;body&amp;gt;  
    &amp;lt;h3&amp;gt;Choose what you like the most&amp;lt;/h3&amp;gt;
  &amp;lt;input list="connect-with-datalist"&amp;gt; 
  &amp;lt;datalist id="connect-with-datalist"&amp;gt; &amp;lt;!-- list and Id should be same to connect them both --&amp;gt;
    &amp;lt;option value="HTML"&amp;gt;
    &amp;lt;option value="CSS"&amp;gt;
    &amp;lt;option value="Javascript"&amp;gt;
    &amp;lt;option value="React Js"&amp;gt;
     &amp;lt;option value="All"&amp;gt;&amp;lt;/option&amp;gt;
  &amp;lt;/datalist&amp;gt;

  &amp;lt;button&amp;gt;Submit&amp;lt;/button&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wGQ9zvKu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fj8ysob8pned2ya3okio.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wGQ9zvKu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fj8ysob8pned2ya3okio.png" alt="Image description" width="340" height="381"&gt;&lt;/a&gt;&lt;br&gt;
OMG you have learn  a lot today. I will say start using it in you HTML.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Learn Little but Better!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you have found this helpful please give a like and comment.&lt;br&gt;&lt;br&gt;
Thanks&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>html</category>
      <category>devops</category>
    </item>
    <item>
      <title>HTML Audio Explained!</title>
      <dc:creator>Waqas Khan</dc:creator>
      <pubDate>Mon, 15 Aug 2022 12:58:19 +0000</pubDate>
      <link>https://forem.com/waqaskhan/html-audio-explained-3jbd</link>
      <guid>https://forem.com/waqaskhan/html-audio-explained-3jbd</guid>
      <description>&lt;h1&gt;
  
  
  Usage of Audio Tag:
&lt;/h1&gt;

&lt;p&gt;The audio tag is used to play sounds, like songs, podcasts or any other type of audio streams. With HTML audio Tag you can embed audio file on your website.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real Example:
&lt;/h2&gt;

&lt;p&gt;The following image show us some collection of audio files.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tuNiULl4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1uuvvaxgccrrx2h2no3n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tuNiULl4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1uuvvaxgccrrx2h2no3n.png" alt="Image description" width="880" height="656"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Let learn its essentials elements to start using it in our HTML.&lt;/p&gt;

&lt;h1&gt;
  
  
  Basic syntax:
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;audio controls autoplay loop muted&amp;gt;
    &amp;lt;source src="Aarzu.mp3" type="audio/mpeg"&amp;gt;
    &amp;lt;source src="Safna.mp3" type="audio/ogg"&amp;gt;
    Your browser does not support Audio
&amp;lt;/audio&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You don't have to worry I will explain everything one by one. &lt;br&gt;&lt;br&gt;
Still after reading the whole blog everything looks confuse. Just follow the basic syntax and you are good to go.&lt;/p&gt;

&lt;h1&gt;
  
  
  Tags:
&lt;/h1&gt;

&lt;p&gt;Basic tags used are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Audio Tag: &lt;code&gt;&amp;lt;audio blah blah blah &amp;gt;&amp;lt;/audio&amp;gt;&lt;/code&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The audio tags tell compiler that its an audio file.&lt;br&gt;
Audio tags has both open and closing tags.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Source Tag: &lt;code&gt;&amp;lt;source blah blah&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It defines one file at a time with file source and its types (explained below). We can define as many files as we want just like I have defined two in this case.&lt;/p&gt;

&lt;h2&gt;
  
  
  Audio Tag Attributes:
&lt;/h2&gt;

&lt;p&gt;Following attributes are used inside HTML audio Tag.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;h4&gt;
  
  
  Control Attribute: &lt;code&gt;&amp;lt;audio controls &amp;gt;&amp;lt;/audio&amp;gt;&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;It specifies that this audio should have audio controlling options like pause and play icon/speaker icon etc.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h4&gt;
  
  
  Automatic Play Attribute: &lt;code&gt;&amp;lt;audio controls autoplay &amp;gt;&amp;lt;/audio&amp;gt;&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This specify that the audio start playing as the page loads. Autoplay mean automatic play.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h4&gt;
  
  
  Repeated Play Attribute: &lt;code&gt;&amp;lt;audio controls autoplay loop&amp;gt;&amp;lt;/audio&amp;gt;&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The audios will play again and again when it ends.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h4&gt;
  
  
  Silent Mode Attribute: &lt;code&gt;&amp;lt;audio controls autoplay loop muted&amp;gt;&amp;lt;/audio&amp;gt;&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;With this attribute the audio will be muted when the page loads and you have to manually unmute it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h4&gt;
  
  
  Preload Attribute: &lt;code&gt;&amp;lt;audio preload="auto/metadata/none" &amp;gt;&amp;lt;/audio&amp;gt;&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Preload attribute give us an option how did we want to &lt;strong&gt;LOAD&lt;/strong&gt; the audio.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;preload="auto"&lt;/code&gt;   =&amp;gt; Load entire file when page load.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;preload="metadata"&lt;/code&gt; =&amp;gt;Load only metadata when page loads&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;preload="none"&lt;/code&gt; =&amp;gt; load nothing.&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;*&lt;em&gt;Important Note: *&lt;/em&gt; The preload attribute is ignored if autoplay is present.&lt;/p&gt;

&lt;p&gt;Wrong: &lt;code&gt;&amp;lt;audio controls autoplay preload="auto" loop muted&amp;gt;&amp;lt;/audio&amp;gt;&lt;/code&gt;&lt;br&gt;&lt;br&gt;
Correct: &lt;code&gt;&amp;lt;audio controls preload="auto" loop muted&amp;gt;&amp;lt;/audio&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Source Tag Attributes:
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;src="file location"&lt;/code&gt; &lt;br&gt;SRC mean source of the file, like where is this file located. It can be a link or a directory path. &lt;br&gt;&lt;br&gt;
&lt;code&gt;type=mpeg/wav/ogg&lt;/code&gt; There are three supported audio formats for HTML audio Tag that have different MIME type values. &lt;br&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mp3 -&amp;gt; audio/mpeg
&lt;/li&gt;
&lt;li&gt;Wav -&amp;gt; audio/wav
&lt;/li&gt;
&lt;li&gt;OGG -&amp;gt; audio/ogg
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Don't worry about MIME now. Just know that it has 3 types.&lt;/p&gt;

&lt;h3&gt;
  
  
  What About the Text Inside Audio Tag?
&lt;/h3&gt;

&lt;p&gt;Well the text will not display until the browser does not support audio.&lt;/p&gt;

&lt;p&gt;Thanks for reading. Give it a Like, Comment and Share it.&lt;br&gt;
&lt;strong&gt;Learn Little but Better&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>html</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>HTML tags: Most beginner does not Know( Part 1)</title>
      <dc:creator>Waqas Khan</dc:creator>
      <pubDate>Mon, 15 Aug 2022 10:15:00 +0000</pubDate>
      <link>https://forem.com/waqaskhan/html-tags-abbrmapareaaside-oa5</link>
      <guid>https://forem.com/waqaskhan/html-tags-abbrmapareaaside-oa5</guid>
      <description>&lt;p&gt;Lets explore some HTML tags to understand the HTML better and use it properly for the next time.&lt;/p&gt;

&lt;p&gt;Using appropriate HTML tags at appropriate location is important.&lt;br&gt;
lets learn few tags today!! (learn little but better)&lt;/p&gt;
&lt;h2&gt;
  
  
  1) HTML abbr Tag
&lt;/h2&gt;

&lt;p&gt;abbr mean abbreviation and it actually use for the Acronym like the world NASA which mean National Aeronautics and Space Administration. OMG this long phrase is difficult to read. so we use abbr tag in HTML body to identify something and when user hover over the mouse, a small explanation or full abbreviation will appear.&lt;br&gt;&lt;br&gt;
Syntax:&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;abbr title= "Full form"&amp;gt;Acronym&amp;lt;/abbr&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&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;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;abbr taf&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;p&amp;gt; 
        This is 
        &amp;lt;abbr title="National Aeronautics and Space Administration"&amp;gt;
            NASA
        &amp;lt;/abbr&amp;gt;
     &amp;lt;/p&amp;gt;
&amp;lt;/body&amp;gt; 
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2) HTML map and area Tag
&lt;/h2&gt;

&lt;p&gt;map tag is use to make different areas of an image clickable and link those parts to some souces. &lt;br&gt;&lt;/p&gt;

&lt;p&gt;But for map we need to understand area tag.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;map tag&lt;/strong&gt; make image clickable&lt;br&gt;&lt;br&gt;
&lt;strong&gt;area tag&lt;/strong&gt; define shape, coordinates and source of that clickable area.&lt;/p&gt;

&lt;p&gt;e.g: Look at below image. What if I want to make each planet clickable. I can only do this by map tag.&lt;br&gt;&lt;br&gt;
How?&lt;br&gt;&lt;br&gt;
By defining the cordinates of pixals and a links inside area tags and wrap those area tag around map tag. lets have a look at 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;&amp;lt;img src="solar.png" usemap="#planetmap"&amp;gt;
    &amp;lt;!-- comment=&amp;gt; usemap connect image with map tag, ignor for now--&amp;gt;
    &amp;lt;map name="planetmap"&amp;gt;
        &amp;lt;area 
            coords="0,0,82,126" 
            href="https://bit.ly/3pgWtiK"   
            alt="sun"  &amp;gt;
    &amp;lt;/map&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;solar.png:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JbFO-TuU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://bit.ly/3QF3ghY" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JbFO-TuU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://bit.ly/3QF3ghY" alt="Image description" width="880" height="542"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3) HTML aside tag
&lt;/h2&gt;

&lt;p&gt;Aside tag is use to display text as the column/side bar text.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5uxyOZ6J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://bit.ly/3zRODkG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5uxyOZ6J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://bit.ly/3zRODkG" alt="Image description" width="617" height="350"&gt;&lt;/a&gt;&lt;br&gt;
syntax:&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;aside&amp;gt; Your Text here &amp;lt;/aside&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Thanks for reading. &lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Learn Little but Better&lt;/p&gt;
&lt;/blockquote&gt;

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