<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ HTML - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ HTML - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 16 Jun 2026 05:48:31 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/html/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Less Common HTML Elements and How to Use Them in Your Code ]]>
                </title>
                <description>
                    <![CDATA[ HTML has a lot of tags that many people use every day, like <div>, <p>, and <a>. But there are also some hidden gems that often go unnoticed. These tags can help make websites more engaging, accessible, and meaningful without much extra effort. In th... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/less-common-html-elements-and-how-to-use-them/</link>
                <guid isPermaLink="false">67292117f26a058bcaa2e19d</guid>
                
                    <category>
                        <![CDATA[ HTML5 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Accessibility ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Joan Ayebola ]]>
                </dc:creator>
                <pubDate>Mon, 04 Nov 2024 19:31:35 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1730747551049/73b334f4-7b4a-448a-bfae-8b95cffe6119.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>HTML has a lot of tags that many people use every day, like <code>&lt;div&gt;</code>, <code>&lt;p&gt;</code>, and <code>&lt;a&gt;</code>. But there are also some hidden gems that often go unnoticed. These tags can help make websites more engaging, accessible, and meaningful without much extra effort.</p>
<p>In this article, we’ll discuss a group of unique HTML elements that can enhance your web pages. They offer specific functions for formatting text, improving readability, and adding interactive features.</p>
<h3 id="heading-table-of-contents">Table of Contents</h3>
<ol>
<li><p><a class="post-section-overview" href="#heading-the-tag-short-inline-quotes">The <code>&lt;q&gt;</code> Tag: Short Inline Quotes</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-tag-strikethrough-text">The <code>&lt;s&gt;</code> Tag: Strikethrough Text</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-tag-highlighted-text">The <code>&lt;mark&gt;</code> Tag: Highlighted Text</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-tag-annotating-east-asian-language-text">The <code>&lt;ruby&gt;</code> Tag: Annotating East Asian Language Text</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-tag-semantic-time-and-date">The <code>&lt;time&gt;</code> Tag: Semantic Time and Date</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-tag-bi-directional-text-isolation">The <code>&lt;bdi&gt;</code> Tag: Bi-Directional Text Isolation</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-tag-defining-terms">The <code>&lt;dfn&gt;</code> Tag: Defining Terms</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-tag-line-break-opportunities">The <code>&lt;wbr&gt;</code> Tag: Line Break Opportunities</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-tag-inserted-text">The <code>&lt;ins&gt;</code> Tag: Inserted Text</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-tag-deleted-text">The <code>&lt;del&gt;</code> Tag: Deleted Text</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></p>
</li>
</ol>
<h2 id="heading-the-tag-short-inline-quotes">The <code>&lt;q&gt;</code> Tag: Short Inline Quotes</h2>
<p>The <code>&lt;q&gt;</code> tag is used to add short quotes inside a paragraph. It helps make quotes look different and easier to spot, without breaking up the flow of the text. This tag automatically adds quotation marks around the content.</p>
<h3 id="heading-description-and-syntax">Description and Syntax</h3>
<p>The basic structure of the <code>&lt;q&gt;</code> tag is simple:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>She said, <span class="hljs-tag">&lt;<span class="hljs-name">q</span>&gt;</span>This is amazing!<span class="hljs-tag">&lt;/<span class="hljs-name">q</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>This would display as:<br><em>She said, “This is amazing!”</em></p>
<h3 id="heading-how-it-differs-from-the-element">How It Differs From the <code>&lt;blockquote&gt;</code> Element</h3>
<p>The <code>&lt;q&gt;</code> tag is for short quotes inside a sentence. On the other hand, the <code>&lt;blockquote&gt;</code> element is used for longer quotes that usually need their own space or paragraph.</p>
<p>For example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">blockquote</span>&gt;</span>
  "This is a long quote that needs its own space. It is different from a short quote."
<span class="hljs-tag">&lt;/<span class="hljs-name">blockquote</span>&gt;</span>
</code></pre>
<p>This block will appear with indentation and is meant to highlight a bigger chunk of quoted text.</p>
<h3 id="heading-use-cases-adding-quotations-within-paragraphs">Use Cases: Adding Quotations Within Paragraphs</h3>
<p>The <code>&lt;q&gt;</code> tag is perfect for cases where you need to mention a quote in a sentence without separating it too much. For instance, when quoting someone in an article or blog post:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>The professor said, <span class="hljs-tag">&lt;<span class="hljs-name">q</span>&gt;</span>Practice makes perfect<span class="hljs-tag">&lt;/<span class="hljs-name">q</span>&gt;</span>, during the class.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>In this case, the <code>&lt;q&gt;</code> tag keeps the quote small and inside the same paragraph.</p>
<center>
<p>The professor said, <q>Practice makes perfect</q>, during the class.</p>
</center>

<h3 id="heading-browser-compatibility-and-styling-tips">Browser Compatibility and Styling Tips</h3>
<p>Most modern browsers automatically add quotation marks to the content inside a <code>&lt;q&gt;</code> tag. But you can change how it looks using CSS if needed. Here’s how you can style it:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">q</span> {
  <span class="hljs-attribute">quotes</span>: <span class="hljs-string">"«"</span> <span class="hljs-string">"»"</span>;
  <span class="hljs-attribute">font-style</span>: italic;
}
</code></pre>
<p>This code will change the quotes to French-style marks (« and ») and make the quote italic.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/YzmNWGd" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p>Most browsers support the <code>&lt;q&gt;</code> tag, so you don’t have to worry about compatibility issues for modern users. But older browsers may need extra care, so always test if your audience uses older versions.</p>
<h2 id="heading-the-tag-strikethrough-text">The <code>&lt;s&gt;</code> Tag: Strikethrough Text</h2>
<p>The <code>&lt;s&gt;</code> tag is used to show text that is no longer correct, relevant, or has been removed. It puts a line through the middle of the text, which we call a "strikethrough." This tag is often used to indicate something that has been edited or updated.</p>
<h3 id="heading-explanation-and-usage">Explanation and Usage</h3>
<p>The <code>&lt;s&gt;</code> tag is simple to use. Wrap it around the text you want to strike through:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This product was <span class="hljs-tag">&lt;<span class="hljs-name">s</span>&gt;</span>$50<span class="hljs-tag">&lt;/<span class="hljs-name">s</span>&gt;</span> now only $30!<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>This will display as:<br><em>This product was <s>$50</s> now only $30!</em></p>
<h3 id="heading-common-use-cases-indicating-removed-or-irrelevant-content">Common Use Cases: Indicating Removed or Irrelevant Content</h3>
<p>The <code>&lt;s&gt;</code> tag is great for showing price changes, edits, or content that is no longer valid. For example:</p>
<p><strong>Price updates</strong>:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">s</span>&gt;</span>$75<span class="hljs-tag">&lt;/<span class="hljs-name">s</span>&gt;</span> $50 (Limited Offer!)<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<center>
<p><s>$75</s> $50 (Limited Offer!)</p>
</center>

<p><strong>Corrections or changes</strong>:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">s</span>&gt;</span>Old website address<span class="hljs-tag">&lt;/<span class="hljs-name">s</span>&gt;</span> New website address<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<center>
<p><s>Old website address</s> New website address</p>
</center>

<p><strong>Content that’s no longer relevant</strong>:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This feature is <span class="hljs-tag">&lt;<span class="hljs-name">s</span>&gt;</span>no longer available<span class="hljs-tag">&lt;/<span class="hljs-name">s</span>&gt;</span>.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<center>
<p>This feature is <s>no longer available</s>.</p>
</center>

<h3 id="heading-styling-possibilities-with-css">Styling Possibilities With CSS</h3>
<p>You can customize how the strikethrough looks using CSS. For example, you can change the color of the line or the text:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">s</span> {
  <span class="hljs-attribute">text-decoration</span>: line-through;
  <span class="hljs-attribute">color</span>: red;
}
</code></pre>
<p>In this case, the text will have a red line through it, giving more emphasis to the fact it’s been crossed out.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/VwoPjWg" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<h3 id="heading-semantic-meaning-versus-visual-decoration">Semantic Meaning Versus Visual Decoration</h3>
<p>The <code>&lt;s&gt;</code> tag holds some semantic meaning. It usually represents content that was once valid but is now incorrect or outdated. It’s more than just a style change. For example, it’s perfect for showing changes in legal documents, corrections in blog posts, or updates to prices.</p>
<p>On the other hand, if you're using strikethrough just for visual decoration without meaning that the text is wrong, it’s better to use CSS directly, like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">span</span><span class="hljs-selector-class">.strike</span> {
  <span class="hljs-attribute">text-decoration</span>: line-through;
}
</code></pre>
<p>And then apply it in your HTML:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This text is <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"strike"</span>&gt;</span>crossed out<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span> just for fun!<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>This approach is purely for styling and doesn’t carry the same meaning as the <code>&lt;s&gt;</code> tag.</p>
<h2 id="heading-the-tag-highlighted-text">The <code>&lt;mark&gt;</code> Tag: Highlighted Text</h2>
<p>The <code>&lt;mark&gt;</code> tag is used to highlight text. It helps draw attention to certain parts of your content, making them stand out. By default, browsers highlight text with a yellow background when the <code>&lt;mark&gt;</code> tag is used.</p>
<h3 id="heading-purpose-of-the-tag">Purpose of the <code>&lt;mark&gt;</code> Tag</h3>
<p>The <code>&lt;mark&gt;</code> tag is great when you want to emphasize something important. It's often used to show search results, recent changes, or any text that needs special attention.</p>
<p>Here’s an example of how it works:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is a <span class="hljs-tag">&lt;<span class="hljs-name">mark</span>&gt;</span>highlighted<span class="hljs-tag">&lt;/<span class="hljs-name">mark</span>&gt;</span> word.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>This will display as:<br><em>This is a</em> <strong><em>highlighted</em></strong> <em>word.</em></p>
<h3 id="heading-best-practices-for-using-for-emphasis-or-search-results">Best Practices for Using <code>&lt;mark&gt;</code> for Emphasis or Search Results</h3>
<p><strong>Highlighting key terms</strong>: If you want to emphasize important words or phrases in an article or blog post, the <code>&lt;mark&gt;</code> tag is a simple way to do that:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>The most important concept here is <span class="hljs-tag">&lt;<span class="hljs-name">mark</span>&gt;</span>efficiency<span class="hljs-tag">&lt;/<span class="hljs-name">mark</span>&gt;</span>.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<center>
<p>The most important concept here is <mark>efficiency</mark>.</p>
</center>

<p><strong>Search results</strong>: When showing search results on a webpage, using the <code>&lt;mark&gt;</code> tag to highlight the matching terms makes it easier for users to find what they’re looking for:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Your search for <span class="hljs-tag">&lt;<span class="hljs-name">mark</span>&gt;</span>HTML<span class="hljs-tag">&lt;/<span class="hljs-name">mark</span>&gt;</span> found these results:<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<center>
<p>Your search for <mark>HTML</mark> found these results:</p>
</center>

<p><strong>Recent updates</strong>: You can also use the <code>&lt;mark&gt;</code> tag to show new updates or changes in your content:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>We have recently added the <span class="hljs-tag">&lt;<span class="hljs-name">mark</span>&gt;</span>new feature<span class="hljs-tag">&lt;/<span class="hljs-name">mark</span>&gt;</span> to the app.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<center>
<p>We have recently added the <mark>new feature</mark> to the app.</p>
</center>

<h3 id="heading-how-to-style-highlighted-text-effectively">How to Style Highlighted Text Effectively</h3>
<p>While the default color for <code>&lt;mark&gt;</code> is yellow, you can change it with CSS to match your website’s design. Here’s an example of how to customize the highlighted text:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">mark</span> {
  <span class="hljs-attribute">background-color</span>: lightblue;
  <span class="hljs-attribute">color</span>: black;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">2px</span>;
}
</code></pre>
<p>This will give the text a light blue background with black text.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/poMRbde" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p>If you want the text to stand out even more, you can add a border or change the font style:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">mark</span> {
  <span class="hljs-attribute">background-color</span>: yellow;
  <span class="hljs-attribute">color</span>: black;
  <span class="hljs-attribute">font-weight</span>: bold;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">4px</span>;
}
</code></pre>
<p>This would make the highlighted text look more polished and noticeable.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/OJKWXzV" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<h3 id="heading-browser-support-and-accessibility-considerations">Browser Support and Accessibility Considerations</h3>
<p>The <code>&lt;mark&gt;</code> tag is supported across all modern browsers, so you won’t face any compatibility issues. Just make sure the background color you choose provides enough contrast for readability, especially for users with visual impairments.</p>
<p>Using a light background with dark text is a good rule of thumb. Testing the color contrast ensures that the highlighted content remains accessible to everyone, including those using screen readers.</p>
<h2 id="heading-the-tag-annotating-east-asian-language-text">The <code>&lt;ruby&gt;</code> Tag: Annotating East Asian Language Text</h2>
<p>The <code>&lt;ruby&gt;</code> tag is used to add small annotations to text, often seen in East Asian languages like Japanese or Chinese. These annotations help readers with pronunciation or meaning, especially when the characters are complex or unfamiliar.</p>
<h3 id="heading-definition-and-use-cases-for">Definition and Use Cases for <code>&lt;ruby&gt;</code></h3>
<p>In languages like Japanese, it's common to use a small guide above or beside characters to show how they should be pronounced. The <code>&lt;ruby&gt;</code> tag pairs the main text with a small annotation, usually in a simpler script.</p>
<p>Here’s a basic example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ruby</span>&gt;</span>漢 <span class="hljs-tag">&lt;<span class="hljs-name">rt</span>&gt;</span>かん<span class="hljs-tag">&lt;/<span class="hljs-name">rt</span>&gt;</span> 字 <span class="hljs-tag">&lt;<span class="hljs-name">rt</span>&gt;</span>じ<span class="hljs-tag">&lt;/<span class="hljs-name">rt</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">ruby</span>&gt;</span>
</code></pre>
<p>This shows the Japanese kanji characters <em>漢字</em> with their pronunciation (furigana) displayed above or beside them as <em>かんじ</em> (kanji).</p>
<center>
<ruby>漢 <rt>かん</rt> 字 <rt>じ</rt></ruby>
</center>

<h3 id="heading-the-importance-of-the-and-sub-elements">The Importance of the <code>&lt;rp&gt;</code> and <code>&lt;rt&gt;</code> Sub-Elements</h3>
<p>The <code>&lt;rt&gt;</code> element is used inside the <code>&lt;ruby&gt;</code> tag to define the annotation (like pronunciation) for the main text. It stands for "ruby text."</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ruby</span>&gt;</span>漢 <span class="hljs-tag">&lt;<span class="hljs-name">rt</span>&gt;</span>かん<span class="hljs-tag">&lt;/<span class="hljs-name">rt</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">ruby</span>&gt;</span>
</code></pre>
<p>This will display <em>漢</em> with <em>かん</em> (kan) above it as the annotation.</p>
<center>
<ruby>漢 <rt>かん</rt></ruby>
</center>

<p>The <code>&lt;rp&gt;</code> element, short for "ruby parenthesis," is used as a fallback for browsers that don’t support the <code>&lt;ruby&gt;</code> tag. It wraps extra characters, such as parentheses, around the ruby text to show that it’s an annotation:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ruby</span>&gt;</span>漢 <span class="hljs-tag">&lt;<span class="hljs-name">rp</span>&gt;</span>(<span class="hljs-tag">&lt;/<span class="hljs-name">rp</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">rt</span>&gt;</span>かん<span class="hljs-tag">&lt;/<span class="hljs-name">rt</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">rp</span>&gt;</span>)<span class="hljs-tag">&lt;/<span class="hljs-name">rp</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">ruby</span>&gt;</span>
</code></pre>
<p>If the browser doesn’t support ruby annotations, it will display the pronunciation inside parentheses, like this:<br><em>漢 (かん)</em>.</p>
<h3 id="heading-practical-examples-ruby-annotations-for-language-learning">Practical Examples: Ruby Annotations for Language Learning</h3>
<p>The <code>&lt;ruby&gt;</code> tag is a helpful tool for language learners. It can display the pronunciation for unfamiliar words or characters directly above or beside them. This makes it easier for beginners to read and learn new vocabulary.</p>
<p>For example, let’s say you want to help someone learn the Chinese word for "person":</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ruby</span>&gt;</span>人 <span class="hljs-tag">&lt;<span class="hljs-name">rt</span>&gt;</span>rén<span class="hljs-tag">&lt;/<span class="hljs-name">rt</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">ruby</span>&gt;</span>
</code></pre>
<p>This would show <em>人</em> with the pronunciation <em>rén</em> above it.</p>
<center>
<ruby>人 <rt>rén</rt></ruby>
</center>

<p>For longer sentences:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">ruby</span>&gt;</span>我 <span class="hljs-tag">&lt;<span class="hljs-name">rt</span>&gt;</span>wǒ<span class="hljs-tag">&lt;/<span class="hljs-name">rt</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">ruby</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">ruby</span>&gt;</span>是 <span class="hljs-tag">&lt;<span class="hljs-name">rt</span>&gt;</span>shì<span class="hljs-tag">&lt;/<span class="hljs-name">rt</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">ruby</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">ruby</span>&gt;</span>学生 <span class="hljs-tag">&lt;<span class="hljs-name">rt</span>&gt;</span>xuéshēng<span class="hljs-tag">&lt;/<span class="hljs-name">rt</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">ruby</span>&gt;</span>.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>This helps students see both the characters and the correct pronunciation.</p>
<center>
<p><ruby>我 <rt>wǒ</rt></ruby> <ruby>是 <rt>shì</rt></ruby> <ruby>学生 <rt>xuéshēng</rt></ruby>.</p>
</center>

<h3 id="heading-cross-browser-compatibility-and-rendering-considerations">Cross-Browser Compatibility and Rendering Considerations</h3>
<p>The <code>&lt;ruby&gt;</code> tag is supported across most modern browsers, but older ones might not render it correctly. That's where the <code>&lt;rp&gt;</code> element comes in handy, making sure the annotations are still readable if the browser doesn’t support ruby text.</p>
<p>For accessibility, make sure the annotations have enough space around them so that they are easy to read. You can also use CSS to adjust how the annotations look:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">ruby</span> <span class="hljs-selector-tag">rt</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0.75em</span>;
  <span class="hljs-attribute">color</span>: gray;
}
</code></pre>
<p>This will make the ruby text smaller and in a different color to keep it visually separate from the main content.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/YzmNWLb" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p>Using <code>&lt;ruby&gt;</code> is a great way to improve readability for language learners or readers unfamiliar with certain scripts. Just remember to check browser support and add fallbacks for a better user experience across different devices.</p>
<h2 id="heading-the-tag-semantic-time-and-date">The <code>&lt;time&gt;</code> Tag: Semantic Time and Date</h2>
<p>The <code>&lt;time&gt;</code> tag is used to mark dates or times in a machine-readable format. It helps search engines, browsers, and other tools recognize time-related information more clearly, which is useful for improving visibility in search results or for better data parsing.</p>
<h3 id="heading-using-the-tag-for-machine-readable-dates-and-times">Using the <code>&lt;time&gt;</code> Tag for Machine-Readable Dates and Times</h3>
<p>When you use the <code>&lt;time&gt;</code> tag, it allows you to provide dates or times that are easy for both people and computers to read. This is especially helpful on blogs, news articles, or event pages.</p>
<p>Here's an example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Published on <span class="hljs-tag">&lt;<span class="hljs-name">time</span> <span class="hljs-attr">datetime</span>=<span class="hljs-string">"2024-10-01"</span>&gt;</span>October 1, 2024<span class="hljs-tag">&lt;/<span class="hljs-name">time</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>The text "October 1, 2024" is what users will see, but the <code>datetime</code> attribute provides a machine-readable version of the date. Search engines can now easily interpret this date.</p>
<center>
<p>Published on <time>October 1, 2024</time></p>
</center>

<p>You can also use the <code>&lt;time&gt;</code> tag to display times:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>The event starts at <span class="hljs-tag">&lt;<span class="hljs-name">time</span> <span class="hljs-attr">datetime</span>=<span class="hljs-string">"13:00"</span>&gt;</span>1:00 PM<span class="hljs-tag">&lt;/<span class="hljs-name">time</span>&gt;</span>.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>This makes it clear to both users and machines when the event takes place.</p>
<center>
<p>The event starts at <time>1:00 PM</time>.</p>
</center>

<h3 id="heading-how-improves-seo-and-data-parsing-for-event-details">How <code>&lt;time&gt;</code> Improves SEO and Data Parsing for Event Details</h3>
<p>Search engines rely on structured data to understand content better. The <code>&lt;time&gt;</code> tag gives them a clearer idea of when events, publications, or deadlines happen, improving the relevance of search results. For example, search engines can better display the publication date of a blog post or the time of an event.</p>
<p>For an event page, the following example provides both human-friendly and machine-friendly time information:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Join us for the workshop on <span class="hljs-tag">&lt;<span class="hljs-name">time</span> <span class="hljs-attr">datetime</span>=<span class="hljs-string">"2024-12-15"</span>&gt;</span>December 15, 2024<span class="hljs-tag">&lt;/<span class="hljs-name">time</span>&gt;</span> at <span class="hljs-tag">&lt;<span class="hljs-name">time</span> <span class="hljs-attr">datetime</span>=<span class="hljs-string">"15:30"</span>&gt;</span>3:30 PM<span class="hljs-tag">&lt;/<span class="hljs-name">time</span>&gt;</span>.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>Search engines and web crawlers can then extract this data and use it to create rich snippets in search results, helping the event get noticed.</p>
<h3 id="heading-examples-of-usage-in-articles-blogs-and-event-pages">Examples of Usage in Articles, Blogs, and Event Pages</h3>
<p>Here are some practical examples of how you can use the <code>&lt;time&gt;</code> tag:</p>
<ol>
<li><p><strong>Blog posts</strong>: You can display when an article was published or last updated:</p>
<pre><code class="lang-html"> <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Last updated on <span class="hljs-tag">&lt;<span class="hljs-name">time</span> <span class="hljs-attr">datetime</span>=<span class="hljs-string">"2024-09-28"</span>&gt;</span>September 28, 2024<span class="hljs-tag">&lt;/<span class="hljs-name">time</span>&gt;</span>.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Event listings</strong>: Event websites can use the <code>&lt;time&gt;</code> tag to list when an event will take place:</p>
<pre><code class="lang-html"> <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Our next meetup will be on <span class="hljs-tag">&lt;<span class="hljs-name">time</span> <span class="hljs-attr">datetime</span>=<span class="hljs-string">"2024-11-10"</span>&gt;</span>November 10, 2024<span class="hljs-tag">&lt;/<span class="hljs-name">time</span>&gt;</span> at <span class="hljs-tag">&lt;<span class="hljs-name">time</span> <span class="hljs-attr">datetime</span>=<span class="hljs-string">"18:00"</span>&gt;</span>6:00 PM<span class="hljs-tag">&lt;/<span class="hljs-name">time</span>&gt;</span>.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Deadlines</strong>: When presenting important deadlines, use the <code>&lt;time&gt;</code> tag for clarity:</p>
<pre><code class="lang-html"> <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Submit your application before <span class="hljs-tag">&lt;<span class="hljs-name">time</span> <span class="hljs-attr">datetime</span>=<span class="hljs-string">"2024-10-30T23:59"</span>&gt;</span>October 30, 2024, 11:59 PM<span class="hljs-tag">&lt;/<span class="hljs-name">time</span>&gt;</span>.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
</li>
</ol>
<p>In all of these examples, the <code>datetime</code> attribute ensures that computers can read the time information correctly, while users see a more readable version.</p>
<h3 id="heading-browser-support-and-accessibility">Browser Support and Accessibility</h3>
<p>The <code>&lt;time&gt;</code> tag is widely supported across modern browsers. It also improves accessibility because screen readers can interpret the date and time more accurately, giving a better experience for users with disabilities.</p>
<h2 id="heading-the-tag-bi-directional-text-isolation">The <code>&lt;bdi&gt;</code> Tag: Bi-Directional Text Isolation</h2>
<p>The <code>&lt;bdi&gt;</code> tag stands for "bi-directional isolation" and is used to prevent text direction problems on multilingual websites. This tag is especially helpful when working with content that includes both left-to-right (LTR) and right-to-left (RTL) languages.</p>
<h3 id="heading-tags-role-in-multilingual-sites"><code>&lt;bdi&gt;</code> Tag’s Role in Multilingual Sites</h3>
<p>When mixing languages with different text directions, like English (LTR) and Arabic (RTL), the natural flow of text can sometimes get messy. The <code>&lt;bdi&gt;</code> tag helps keep the layout of the text clean, ensuring that each portion of text displays correctly, no matter the direction of the language.</p>
<p>For example, if you want to display user input (like a username) next to other text, and you don’t know which language the username will be in, you can use <code>&lt;bdi&gt;</code> to make sure it doesn’t mess with the flow.</p>
<h3 id="heading-how-to-use-for-preventing-text-direction-issues">How to Use <code>&lt;bdi&gt;</code> for Preventing Text Direction Issues</h3>
<p>The <code>&lt;bdi&gt;</code> tag wraps around the part of the text you want to isolate, and it prevents the text direction from being affected by surrounding content.</p>
<p>Here’s a simple example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>User <span class="hljs-tag">&lt;<span class="hljs-name">bdi</span>&gt;</span>اسم<span class="hljs-tag">&lt;/<span class="hljs-name">bdi</span>&gt;</span> has logged in.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>If the username is in Arabic (which reads RTL), the <code>&lt;bdi&gt;</code> tag ensures the rest of the sentence (which is in English and reads LTR) doesn’t get disrupted. Without the <code>&lt;bdi&gt;</code> tag, the sentence could display incorrectly due to the mix of text directions.</p>
<p>Another example with numbers:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Invoice number: <span class="hljs-tag">&lt;<span class="hljs-name">bdi</span>&gt;</span>#1234<span class="hljs-tag">&lt;/<span class="hljs-name">bdi</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>If the invoice number includes text or numbers in different directions, the <code>&lt;bdi&gt;</code> tag makes sure the formatting stays correct.</p>
<h3 id="heading-examples-of">Examples of <code>&lt;bdi&gt;</code></h3>
<p>The <code>&lt;bdi&gt;</code> tag is commonly used in multilingual applications, user-generated content platforms, and websites that handle multiple languages at once. For instance, websites that allow users to input data, such as names or addresses, might use <code>&lt;bdi&gt;</code> to ensure proper text alignment.</p>
<p>Here’s an example on a forum:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">bdi</span>&gt;</span>مستخدم<span class="hljs-tag">&lt;/<span class="hljs-name">bdi</span>&gt;</span> liked your post!<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>Without <code>&lt;bdi&gt;</code>, the text might display awkwardly, but with it, both the Arabic username and the English text display properly.</p>
<h3 id="heading-browser-compatibility">Browser Compatibility</h3>
<p>The <code>&lt;bdi&gt;</code> tag is supported in all modern browsers, including Chrome, Firefox, Safari, and Edge. It’s a lightweight solution, doesn’t require special styling, and helps keep your content layout neat when dealing with multilingual text.</p>
<h2 id="heading-the-tag-defining-terms">The <code>&lt;dfn&gt;</code> Tag: Defining Terms</h2>
<p>The <code>&lt;dfn&gt;</code> tag is used to mark the first instance of a term that is being defined within a webpage. It helps readers quickly recognize that a particular word or phrase is a definition, improving the clarity of your content, especially in technical writing.</p>
<h3 id="heading-how-to-use-for-marking-definitions">How to Use <code>&lt;dfn&gt;</code> for Marking Definitions</h3>
<p>The <code>&lt;dfn&gt;</code> tag is simple to use. You wrap it around the word or phrase that you want to define. Typically, the term appears near the explanation of its meaning.</p>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>The <span class="hljs-tag">&lt;<span class="hljs-name">dfn</span>&gt;</span>DOM<span class="hljs-tag">&lt;/<span class="hljs-name">dfn</span>&gt;</span> (Document Object Model) is a programming interface for web documents.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>Here, the <code>&lt;dfn&gt;</code> tag highlights that "DOM" is the term being defined.</p>
<center>
<p>The <dfn>DOM</dfn> (Document Object Model) is a programming interface for web documents.</p>
</center>

<h3 id="heading-best-practices-for-providing-in-article-explanations">Best Practices for Providing In-Article Explanations</h3>
<p>When using the <code>&lt;dfn&gt;</code> tag, make sure the term you are defining is followed closely by its explanation. This keeps things clear and helps readers connect the term with its meaning right away.</p>
<p>It's also a good idea to only use <code>&lt;dfn&gt;</code> the first time a term is introduced, as repeating it multiple times can confuse the reader.</p>
<p>For example, in a technical article about HTML:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>The <span class="hljs-tag">&lt;<span class="hljs-name">dfn</span>&gt;</span>API<span class="hljs-tag">&lt;/<span class="hljs-name">dfn</span>&gt;</span> (Application Programming Interface) allows different software applications to communicate with each other. Once defined, an API can simplify many web development tasks.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>In this case, "API" is defined when it's first mentioned, and later uses of "API" don’t need the <code>&lt;dfn&gt;</code> tag anymore.</p>
<h3 id="heading-how-improves-the-clarity-of-technical-content">How <code>&lt;dfn&gt;</code> Improves the Clarity of Technical Content</h3>
<p>Using the <code>&lt;dfn&gt;</code> tag in technical writing is a great way to make content easier to follow. It clearly signals to readers when you're introducing a new term, which is especially useful when explaining complex ideas. This helps improve readability and allows users to grasp key concepts faster.</p>
<p>By marking definitions with <code>&lt;dfn&gt;</code>, search engines and other tools may also be able to better interpret your content, making it more accessible. For example, technical glossaries or educational websites can use <code>&lt;dfn&gt;</code> to make their terms stand out.</p>
<h3 id="heading-example-of">Example of <code>&lt;dfn&gt;</code></h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>The <span class="hljs-tag">&lt;<span class="hljs-name">dfn</span>&gt;</span>URL<span class="hljs-tag">&lt;/<span class="hljs-name">dfn</span>&gt;</span> (Uniform Resource Locator) is the address used to access a resource on the web.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>In this sentence, the reader is introduced to the term "URL," followed by a clear explanation. This method of introducing terms with the <code>&lt;dfn&gt;</code> tag helps make technical content much easier to read and understand, especially for those unfamiliar with the topic.</p>
<h2 id="heading-the-tag-line-break-opportunities">The <code>&lt;wbr&gt;</code> Tag: Line Break Opportunities</h2>
<p>The <code>&lt;wbr&gt;</code> tag is used to suggest where a word or URL can be split to create a line break if needed. This is useful when dealing with long words, URLs, or any text that could break the layout of a webpage.</p>
<h3 id="heading-what-the-tag-is-and-why-its-essential-for-long-words-or-urls">What the <code>&lt;wbr&gt;</code> Tag Is and Why it’s Essential for Long Words or URLs</h3>
<p>Sometimes, long words or URLs can mess up the design of a webpage by causing horizontal scrolling or breaking the layout. The <code>&lt;wbr&gt;</code> tag gives the browser a hint on where to break the word, but only if necessary. This helps keep the text readable and prevents overflow.</p>
<p>For example, if you have a long URL, you can place the <code>&lt;wbr&gt;</code> tag to tell the browser where it can break the text:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Visit our website at https://www.example<span class="hljs-tag">&lt;<span class="hljs-name">wbr</span>&gt;</span>.com/super/long-url-that-might-break-layout<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>If the browser needs to break the URL, it will do so after the <code>&lt;wbr&gt;</code>, ensuring the design remains intact.</p>
<h3 id="heading-best-practices-for-controlling-word-wrapping-and-text-overflow">Best Practices for Controlling Word Wrapping and Text Overflow</h3>
<p>The <code>&lt;wbr&gt;</code> tag should be used in places where text might cause overflow issues, such as long technical terms, email addresses, or URLs. But don’t overuse it, as unnecessary breaks can make the text harder to read.</p>
<p>Here’s another example with a long word:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This word is too long: anti<span class="hljs-tag">&lt;<span class="hljs-name">wbr</span>&gt;</span>disestablishmentarianism.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>If the word gets too long for the line, the browser will split it after "anti-" without affecting readability.</p>
<p>In combination with CSS, you can also control word wrapping and text overflow for better results:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">word-wrap</span>: break-word;
  <span class="hljs-attribute">overflow-wrap</span>: break-word;
}
</code></pre>
<p>This CSS ensures that the text will wrap neatly when necessary, and using <code>&lt;wbr&gt;</code> can give more control over where those breaks happen.</p>
<h3 id="heading-browser-support-for-and-potential-challenges">Browser Support for <code>&lt;wr&gt;</code> and Potential Challenges</h3>
<p>The <code>&lt;wbr&gt;</code> tag is supported in all major browsers, including Chrome, Firefox, Safari, and Edge. It’s lightweight and doesn’t need any special styling to work.</p>
<p>But one thing to watch for is that overuse of the tag can make text breaks appear unnatural if the content is resized or viewed on different screen sizes.</p>
<p>For example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Contact us at longemail<span class="hljs-tag">&lt;<span class="hljs-name">wbr</span>&gt;</span>@example<span class="hljs-tag">&lt;<span class="hljs-name">wbr</span>&gt;</span>.com for more information.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>In this case, you can avoid long email addresses causing layout problems, but the email might appear broken at different places depending on the screen width.</p>
<p>Use <code>&lt;wbr&gt;</code> when you anticipate long strings of text that may not naturally break, keeping your design clean and functional across devices.</p>
<h2 id="heading-the-tag-inserted-text">The <code>&lt;ins&gt;</code> Tag: Inserted Text</h2>
<p>The <code>&lt;ins&gt;</code> tag is used to show text that has been added to a document. This is often helpful when tracking edits, updates, or changes in documents. It also comes with a default underline to highlight the new content.</p>
<h3 id="heading-what-is-the-tag-and-how-does-it-compare-to-the-tag">What Is the <code>&lt;ins&gt;</code> Tag and How Does it Compare to the <code>&lt;s&gt;</code> Tag?</h3>
<p>The <code>&lt;ins&gt;</code> tag is designed for marking inserted content, while the <code>&lt;s&gt;</code> tag is used for text that has been removed or is no longer relevant. Both tags are useful when you need to show changes in a document, like updates or revisions.</p>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is the <span class="hljs-tag">&lt;<span class="hljs-name">ins</span>&gt;</span>new text<span class="hljs-tag">&lt;/<span class="hljs-name">ins</span>&gt;</span> that was added.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is the <span class="hljs-tag">&lt;<span class="hljs-name">s</span>&gt;</span>old text<span class="hljs-tag">&lt;/<span class="hljs-name">s</span>&gt;</span> that is no longer valid.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>Here, the <code>&lt;ins&gt;</code> tag highlights what has been added, and the <code>&lt;s&gt;</code> tag shows what has been crossed out as outdated.</p>
<center>
<p>This is the new text that was added.</p>
<p>This is the <s>old text</s> that is no longer valid.</p>
</center>

<h3 id="heading-usage-in-tracking-document-edits-or-versioning">Usage in Tracking Document Edits or Versioning</h3>
<p>The <code>&lt;ins&gt;</code> tag is commonly used when managing documents that need version control or where edits should be visible. For example, you can use it in collaborative writing platforms or legal documents to show which parts have been added.</p>
<p>Example of a document with changes:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>The contract was updated to include <span class="hljs-tag">&lt;<span class="hljs-name">ins</span>&gt;</span>an extra clause<span class="hljs-tag">&lt;/<span class="hljs-name">ins</span>&gt;</span> on data privacy.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>This makes it clear to the reader that the section about "data privacy" was recently added.</p>
<p>In software development or content management, you might use the <code>&lt;ins&gt;</code> tag to show text that has been newly introduced in version-controlled files, making it easier to track edits and revisions over time.</p>
<h3 id="heading-styling-options-to-emphasize-changes">Styling Options to Emphasize Changes</h3>
<p>The default appearance of the <code>&lt;ins&gt;</code> tag is underlined, but you can customize it using CSS for better emphasis, especially if you want the changes to stand out more.</p>
<p>Here’s how you can style the <code>&lt;ins&gt;</code> tag with different visual effects:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">ins</span> {
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#d4edda</span>;
  <span class="hljs-attribute">color</span>: green;
  <span class="hljs-attribute">text-decoration</span>: none; <span class="hljs-comment">/* Removes default underline */</span>
}
</code></pre>
<p>This will give the inserted text a green color and a light green background, making it more noticeable.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/wvVgWRz" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p>You can also add different styles like a bold font or a border:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">ins</span> {
  <span class="hljs-attribute">font-weight</span>: bold;
  <span class="hljs-attribute">border-bottom</span>: <span class="hljs-number">2px</span> solid green;
}
</code></pre>
<p>These styling options make it easier for users to identify what has been added or changed, improving the readability and transparency of document edits.</p>
<p>Overall, the <code>&lt;ins&gt;</code> tag is a simple but effective way to track inserted content, making it very useful for both technical documents and collaborative platforms where revisions need to be clearly visible.</p>
<h2 id="heading-the-tag-deleted-text">The <code>&lt;del&gt;</code> Tag: Deleted Text</h2>
<p>The <code>&lt;del&gt;</code> tag is used to show text that has been deleted or removed from a document. This tag strikes through the text by default, making it easy to identify what has been removed. It’s especially helpful in situations where tracking changes or revisions is necessary.</p>
<h3 id="heading-purpose-and-usage-of-the-tag-for-strikethrough-text">Purpose and Usage of the <code>&lt;del&gt;</code> Tag for Strikethrough Text</h3>
<p>The main job of the <code>&lt;del&gt;</code> tag is to visually show that some content has been removed. It’s common in documents, articles, or code where changes need to be made visible to the reader. The deleted text will usually have a strikethrough, indicating that it’s no longer relevant or valid.</p>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This product costs <span class="hljs-tag">&lt;<span class="hljs-name">del</span>&gt;</span>$50<span class="hljs-tag">&lt;/<span class="hljs-name">del</span>&gt;</span> $40 now.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>In this example, the price change is clear. The old price ($50) is struck through, and the new price ($40) follows right after.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728749690070/6c971036-90b9-4bcb-9d74-1c13bd770750.png" alt="6c971036-90b9-4bcb-9d74-1c13bd770750" class="image--center mx-auto" width="322" height="55" loading="lazy"></p>
<h3 id="heading-how-it-can-be-combined-with-for-tracking-revisions">How It Can Be Combined With <code>&lt;ins&gt;</code> for Tracking Revisions</h3>
<p>The <code>&lt;del&gt;</code> tag can be paired with the <code>&lt;ins&gt;</code> tag to show both removed and newly added content, making it perfect for tracking edits or revisions. This is very useful in collaborative writing, legal documents, or any situation where changes must be recorded clearly.</p>
<p>Example of tracking revisions:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>The meeting has been moved <span class="hljs-tag">&lt;<span class="hljs-name">del</span>&gt;</span>Monday<span class="hljs-tag">&lt;/<span class="hljs-name">del</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">ins</span>&gt;</span>Tuesday<span class="hljs-tag">&lt;/<span class="hljs-name">ins</span>&gt;</span>.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>Here, it’s easy to see that "Monday" was replaced with "Tuesday," and the reader knows exactly what changed.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728749828530/ee3f84d5-9e56-4f27-8ce3-6eac5a79a144.png" alt="ee3f84d5-9e56-4f27-8ce3-6eac5a79a144" class="image--center mx-auto" width="466" height="58" loading="lazy"></p>
<h3 id="heading-best-practices-for-displaying-and-styling-deleted-content">Best Practices for Displaying and Styling Deleted Content</h3>
<p>By default, the <code>&lt;del&gt;</code> tag applies a strikethrough to the text, but you can style it further with CSS to make it more noticeable or match your design needs.</p>
<p>Here’s an example of customizing the appearance of deleted text:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">del</span> {
  <span class="hljs-attribute">color</span>: red;
  <span class="hljs-attribute">text-decoration</span>: line-through;
}
</code></pre>
<p>This makes deleted text appear red, drawing more attention to it. You can also combine it with additional formatting, like fading out the text:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">del</span> {
  <span class="hljs-attribute">color</span>: gray;
  <span class="hljs-attribute">opacity</span>: <span class="hljs-number">0.7</span>;
}
</code></pre>
<p>This style reduces the emphasis on deleted content, making it less distracting but still visible to readers.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/xxvgWNQ" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p>The <code>&lt;del&gt;</code> tag provides a simple and effective way to track and display changes, especially when combined with the <code>&lt;ins&gt;</code> tag. It’s essential for keeping documents transparent and clear for anyone reviewing edits or updates.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Making use of these unique HTML elements expands what’s possible on the web, which helps to create more meaningful and accessible content. Tags like <code>&lt;q&gt;</code>, <code>&lt;s&gt;</code>, <code>&lt;mark&gt;</code>, <code>&lt;ruby&gt;</code>, <code>&lt;time&gt;</code>, <code>&lt;bdi&gt;</code>, <code>&lt;dfn&gt;</code>, <code>&lt;wbr&gt;</code>, <code>&lt;ins&gt;</code>, and <code>&lt;del&gt;</code> each bring their own advantages for specific tasks. These elements do more than just style text; they add context, enhance user experiences, and improve document structure.</p>
<p>Using these tags correctly not only makes your web pages clearer but also boosts compatibility across devices and search engines. As you apply these elements, think about how each one serves both the visual presentation and the information structure. They offer simple but powerful ways to make websites richer and easier to understand while benefiting a wide range of users.</p>
<p>If you have any questions or suggestions, feel free to reach out on <a target="_blank" href="https://ng.linkedin.com/in/joan-ayebola">LinkedIn</a>. If you enjoyed this content, consider <a target="_blank" href="https://www.buymeacoffee.com/joanayebola">buying me a coffee</a> to support the creation of more developer-friendly contents.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Create Filling CSS Loaders Using One Element ]]>
                </title>
                <description>
                    <![CDATA[ In a previous article, I showed you how to create two types of CSS loaders: a spinner and a progress bar. In this article, you’ll learn about another variation called a filling CSS loader. I think a demo is worth thousands of words, so check out this... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/filling-css-loaders/</link>
                <guid isPermaLink="false">6719336f56c24fb7d4fc62b3</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ loaders ]]>
                    </category>
                
                    <category>
                        <![CDATA[ animations ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Temani Afif ]]>
                </dc:creator>
                <pubDate>Wed, 23 Oct 2024 17:33:35 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1729637821745/50ff0461-350c-441c-9726-b838d3ef0a5c.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In <a target="_blank" href="https://www.freecodecamp.org/news/how-to-create-a-css-only-loader">a previous article</a>, I showed you how to create two types of CSS loaders: a spinner and a progress bar. In this article, you’ll learn about another variation called a filling CSS loader.</p>
<p>I think a demo is worth thousands of words, so check out this Codepen:</p>
<div class="embed-wrapper"><iframe height="450" style="width:100%;height:450px" src="https://codepen.io/t_afif/embed/preview/ExqvRXO/77e4af243170fc28a0c8193a55b7ffe5?default-tab=result" title="Embedded content" loading="lazy">
  See the Pen <a href="https://codepen.io/t_afif/pen/ExqvRXO/77e4af243170fc28a0c8193a55b7ffe5">
  Untitled</a> by Temani Afif (<a href="https://codepen.io/t_afif">@t_afif</a>)
  on <a href="https://codepen.io">CodePen</a>.
</iframe></div>

<p>In the above Pen, I’m showing you four different CSS filler-style loaders – but we can make even more. You can check out <a target="_blank" href="https://css-loaders.com/filling/">this collection</a> I created to see more than 20 different loaders.</p>
<p>You might think the article is going to be super long – I mean, how long will it take to explain how to create 20 different CSS loaders?</p>
<p>Well don’t worry – this tutorial will be super quick, because I’ll show a few CSS tricks that help you create as many variation as you want. The loaders look different, but all of them rely on the same techniques. By simply adjusting a few setting you can get a whole new loader.</p>
<h2 id="heading-the-initial-loader-configuration">The Initial Loader Configuration</h2>
<p>Like all <a target="_blank" href="https://css-loaders.com/">the CSS Loaders</a> I create, the HTML code is a simple as a single element. Nothing more! Here’s what it looks like:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"loader"</span>&gt;</span>Loading<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>Then we apply the following CSS:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.loader</span> {
  <span class="hljs-attribute">font-weight</span>: bold;
  <span class="hljs-attribute">text-transform</span>: uppercase;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#0000</span>; <span class="hljs-comment">/* or transparent */</span>
  <span class="hljs-attribute">-webkit-text-stroke</span>: <span class="hljs-number">1px</span> <span class="hljs-number">#000</span>;
}
</code></pre>
<p>Nothing fancy so far. We make the text transparent and we add a black stroke to it. Here’s what that looks like:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1729506785632/fe01d18e-6d7d-4d49-a5d0-ef6766c51241.png" alt="The &quot;loading&quot; text with a black stroke and transparent color" class="image--center mx-auto" width="476" height="190" loading="lazy"></p>
<p>The <code>-webkit-text-stroke</code> is still tagged as experimental, but it has <a target="_blank" href="https://caniuse.com/mdn-css_properties_-webkit-text-stroke">good browser support</a> so you should be able to use it without any issues. This said, it’s always good to test your code in different browsers to make sure everything works fine.</p>
<h2 id="heading-how-to-fill-the-text-with-colors">How to Fill the Text with Colors</h2>
<p>Now it’s time to fill our text (that’s why this technique is called the Filling CSS loaders!). To do this, we are going to rely on gradients and <code>background-clip: text</code>. Here’s the code:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.loader</span> {
  <span class="hljs-attribute">background-image</span>: <span class="hljs-built_in">conic-gradient</span>(#<span class="hljs-number">000</span> <span class="hljs-number">0</span> <span class="hljs-number">0</span>);
  <span class="hljs-attribute">background-position</span>: left;
  <span class="hljs-attribute">background-size</span>: <span class="hljs-number">40%</span> <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">background-repeat</span>: no-repeat;
  <span class="hljs-attribute">background-clip</span>: text;
}
</code></pre>
<p>Or the shorthand version if you prefer more compact code:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.loader</span> {
  <span class="hljs-attribute">background</span>: 
    <span class="hljs-built_in">conic-gradient</span>(#<span class="hljs-number">000</span> <span class="hljs-number">0</span> <span class="hljs-number">0</span>) text
    left/<span class="hljs-number">40%</span> <span class="hljs-number">100%</span> no-repeat;
}
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1729507914013/b8991ffe-0b81-4ae0-a356-c102023c2f6c.png" alt="the difference between with and without background-clip: text" class="image--center mx-auto" width="873" height="190" loading="lazy"></p>
<p>The above figure illustrates the difference between using or not using <code>background-clip: text</code>. It’s pretty clear that the left result is what we are aiming for. We are limiting the background coloration to only the text instead of the whole element.</p>
<p>The <code>conic-gradient(#000 0 0)</code> looks strange, right? It lets you have a one-color gradient. I wrote a small tip about it that I invite you to read to understand why we’re using that particular syntax in this article, “<a target="_blank" href="https://css-tip.com/one-color-gradient/">How to correctly define a one-color gradient</a>“.</p>
<h2 id="heading-how-to-create-the-filling-loaders">How to Create the Filling Loaders</h2>
<p>Believe it or not, we’re almost done because we have everything we need to make the CSS loaders. For the first loader, we simply animate the <code>background-size</code> as follows:</p>
<pre><code class="lang-css"><span class="hljs-selector-id">#l1</span> {
  <span class="hljs-attribute">animation</span>: l1 <span class="hljs-number">1s</span> linear infinite;
}
<span class="hljs-keyword">@keyframes</span> l1 {  <span class="hljs-comment">/*  width  height */</span>
  0% {<span class="hljs-attribute">background-size</span>: <span class="hljs-number">0%</span>   <span class="hljs-number">100%</span>}
  <span class="hljs-selector-tag">to</span> {<span class="hljs-attribute">background-size</span>: <span class="hljs-number">120%</span> <span class="hljs-number">100%</span>}
}
</code></pre>
<p>We start with a width equal to <code>0%</code> until we reach a width equal to <code>120%</code>. I could have used <code>100%</code>, but I want the full coloration to stay longer so I am using a value bigger than <code>100%</code>. As for the height (the second value of the <code>background-size</code>), it remains at <code>100%</code>.</p>
<p>The second loader uses the same animation, but instead of a linear timing function, we use <code>steps()</code> to have a discrete animation.</p>
<pre><code class="lang-css"><span class="hljs-selector-id">#l2</span> {
  <span class="hljs-attribute">font-family</span>: monospace;
  <span class="hljs-attribute">animation</span>: l2 <span class="hljs-number">2s</span> <span class="hljs-built_in">steps</span>(<span class="hljs-number">8</span>, jump-none) infinite;
}
<span class="hljs-keyword">@keyframes</span> l2 {
  0% {<span class="hljs-attribute">background-size</span>: <span class="hljs-number">0%</span>           <span class="hljs-number">100%</span>}
  <span class="hljs-selector-tag">to</span> {<span class="hljs-attribute">background-size</span>: <span class="hljs-number">100%</span> <span class="hljs-number">100%</span>}
}
</code></pre>
<p>The text contains 7 characters so we use 8 steps (<code>N + 1</code>). I am also using a monospace font to make sure all the characters have the same width. In case you are wondering about the <code>jump-none</code> value, read the following: <a target="_blank" href="https://css-tip.com/steps/">How to correctly use steps() with animations</a>.</p>
<p><a target="_blank" href="https://css-tip.com/steps/">That’s basically the main trick. By animat</a>ing the background properties, we create different kinds of loaders. It’s either the <code>background-size</code> like the previous ones or the <code>background-position</code> like the below:</p>
<div class="embed-wrapper"><iframe height="400" style="width:100%;height:400px" src="https://codepen.io/t_afif/embed/preview/bGXogOx/59e12d693e164ac69804a554bbac8588?default-tab=result" title="Embedded content" loading="lazy">
  See the Pen <a href="https://codepen.io/t_afif/pen/bGXogOx/59e12d693e164ac69804a554bbac8588">
  Untitled</a> by Temani Afif (<a href="https://codepen.io/t_afif">@t_afif</a>)
  on <a href="https://codepen.io">CodePen</a>.
</iframe></div>

<p>Can you figure out how they work before checking my code? This will be your first homework!</p>
<h2 id="heading-how-to-use-multiple-gradients">How to Use Multiple Gradients</h2>
<p>Using one gradient is enough to create a lot of variations – but we can do even more if we introduce multiple gradients. If you check the fourth loader of the first demo, you’ll see that I’m using seven gradients – one gradient per character.</p>
<pre><code class="lang-css"><span class="hljs-selector-id">#l4</span> {
  <span class="hljs-attribute">font-family</span>: monospace;
  <span class="hljs-attribute">--g</span>: <span class="hljs-built_in">conic-gradient</span>(#<span class="hljs-number">000</span> <span class="hljs-number">0</span> <span class="hljs-number">0</span>) no-repeat text;
  <span class="hljs-attribute">background</span>: <span class="hljs-built_in">var</span>(--g) <span class="hljs-number">0</span>,<span class="hljs-built_in">var</span>(--g) <span class="hljs-number">1ch</span>,<span class="hljs-built_in">var</span>(--g) <span class="hljs-number">2ch</span>,<span class="hljs-built_in">var</span>(--g) <span class="hljs-number">3ch</span>,<span class="hljs-built_in">var</span>(--g) <span class="hljs-number">4ch</span>,<span class="hljs-built_in">var</span>(--g) <span class="hljs-number">5ch</span>,<span class="hljs-built_in">var</span>(--g) <span class="hljs-number">6ch</span>;
  <span class="hljs-attribute">background-position-y</span>: bottom;
  <span class="hljs-attribute">animation</span>: l4 <span class="hljs-number">3s</span> infinite;
}
<span class="hljs-keyword">@keyframes</span> l4 {
  0%     {<span class="hljs-attribute">background-size</span>: <span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   }
  14<span class="hljs-selector-class">.28</span>% {<span class="hljs-attribute">background-size</span>: <span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   }
  28<span class="hljs-selector-class">.57</span>% {<span class="hljs-attribute">background-size</span>: <span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   }
  42<span class="hljs-selector-class">.85</span>% {<span class="hljs-attribute">background-size</span>: <span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   }
  57<span class="hljs-selector-class">.14</span>% {<span class="hljs-attribute">background-size</span>: <span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   }
  71<span class="hljs-selector-class">.43</span>% {<span class="hljs-attribute">background-size</span>: <span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   ,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   }
  85<span class="hljs-selector-class">.71</span>% {<span class="hljs-attribute">background-size</span>: <span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">0</span>   }
  100%   {<span class="hljs-attribute">background-size</span>: <span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>,<span class="hljs-number">1ch</span> <span class="hljs-number">100%</span>}
}
</code></pre>
<p>I’m using the same gradient, so we consider a CSS variable <code>--g</code> to avoid repetition. Then, I call that variable 7 times inside the background property. All the gradients have the same Y position (<code>bottom</code>) but a different X position. That’s why you see the <code>0, 1ch, 2ch, …,6ch</code>.</p>
<p>Now if you check the animation, I’m simply animating the height of each gradient individually. At <code>0%</code>, all of them have a height equal to <code>0</code>. Then I update their height one by one until all of them are at <code>100%</code>. The width doesn’t change – it’s always equal to <code>1ch</code> (the width of one character).</p>
<p>It may look difficult at first glance, but if you think about it one gradient at a time, it’s pretty simple.</p>
<p>What about the third loader, you might ask? For that one, I will rely on <a target="_blank" href="https://css-generators.com/wavy-shapes/">my online generator for wavy shapes</a> to generate the gradient configuration:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1729635835522/2f8726a3-e6bb-4949-8846-8408dad56a64.png" alt="Screenshot of the wavy shape generator" class="image--center mx-auto" width="1292" height="517" loading="lazy"></p>
<p>Then I animate the <code>background-position</code> like below:</p>
<pre><code class="lang-css"><span class="hljs-selector-id">#l3</span> {
  <span class="hljs-attribute">background</span>:
    <span class="hljs-built_in">radial-gradient</span>(<span class="hljs-number">1.13em</span> at <span class="hljs-number">50%</span> <span class="hljs-number">1.6em</span>,#<span class="hljs-number">000</span> <span class="hljs-number">99%</span>,#<span class="hljs-number">0000</span> <span class="hljs-number">101%</span>) <span class="hljs-built_in">calc</span>(<span class="hljs-number">50%</span> - <span class="hljs-number">1.6em</span>) <span class="hljs-number">0</span>/<span class="hljs-number">3.2em</span> <span class="hljs-number">100%</span>,
    <span class="hljs-built_in">radial-gradient</span>(<span class="hljs-number">1.13em</span> at <span class="hljs-number">50%</span> -<span class="hljs-number">0.8em</span>,#<span class="hljs-number">0000</span> <span class="hljs-number">99%</span>,#<span class="hljs-number">000</span> <span class="hljs-number">101%</span>) <span class="hljs-number">50%</span> .<span class="hljs-number">8em</span>/<span class="hljs-number">3.2em</span> <span class="hljs-number">100%</span> repeat-x;
  <span class="hljs-attribute">background-clip</span>: text;
  <span class="hljs-attribute">animation</span>: l3 <span class="hljs-number">2s</span> linear infinite;
}
<span class="hljs-keyword">@keyframes</span> l3 {
  0% {<span class="hljs-attribute">background-position</span>: <span class="hljs-built_in">calc</span>(<span class="hljs-number">50%</span> - <span class="hljs-number">1.6em</span>) <span class="hljs-number">0</span>,     <span class="hljs-number">50%</span>          .<span class="hljs-number">8em</span>}
  <span class="hljs-selector-tag">to</span> {<span class="hljs-attribute">background-position</span>: <span class="hljs-built_in">calc</span>(<span class="hljs-number">50%</span> + <span class="hljs-number">1.6em</span>) <span class="hljs-number">0</span>,<span class="hljs-built_in">calc</span>(<span class="hljs-number">50%</span> + <span class="hljs-number">3.2em</span>) .<span class="hljs-number">8em</span>}
}
</code></pre>
<p>This one is probably a bit trickier, but it’s another example to illustrate all the possibilities. From the simple gradient configuration to the most complex one, we can create as many loaders as we want.</p>
<p>What about creating your own CSS loader? You can use what you have learned from the article and try to create a loader that is not part of <a target="_blank" href="https://css-loaders.com/filling/">my collection</a>. The best way to learn is to practice – so give it a try!</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>By creating some cool loaders, we went through a bunch of CSS tricks related to gradients and backgrounds. Even if creating loaders is not your goal, you can always re-use the same tricks to do something else.</p>
<p>Don’t forget to check my <a target="_blank" href="https://css-tip.com/">CSS Tip blog</a> where I am sharing cool CSS tricks and demos.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use HTML Attributes to Make Your Websites and Apps More Accessible ]]>
                </title>
                <description>
                    <![CDATA[ Have you ever used an attribute in HTML without fully understanding its purpose? You're not alone! Over time, I've dug into the meaning behind many HTML attributes, especially those that are crucial for accessibility. In this in-depth tutorial, I'll ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-html-attributes-to-make-your-websites-and-apps-more-accessible/</link>
                <guid isPermaLink="false">66db603bf7f8b7688af503af</guid>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ a11y ]]>
                    </category>
                
                    <category>
                        <![CDATA[ aria ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Accessibility ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Elizabeth Lola ]]>
                </dc:creator>
                <pubDate>Fri, 06 Sep 2024 20:04:11 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1725281991044/7edb0d70-c31e-4a41-bc24-232c75d0fae3.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Have you ever used an attribute in HTML without fully understanding its purpose? You're not alone! Over time, I've dug into the meaning behind many HTML attributes, especially those that are crucial for accessibility.</p>
<p>In this in-depth tutorial, I'll break down some key HTML attributes that enhance accessibility, explaining what they do, and when to use them effectively.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>To follow along with this tutorial, you should have a basic understanding of HTML and a little bit of Javascript knowledge as well.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ol>
<li><p><a class="post-section-overview" href="#heading-what-are-aria-attributes">What are ARIA Attributes?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-alt-attribute">The <code>alt</code> Attribute</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-aria-label-attribute">The <code>aria-label</code> Attribute</a></p>
<ul>
<li><a class="post-section-overview" href="#heading-best-practices-for-using-aria-label">Best practices for Using <code>aria-label</code></a></li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-the-aria-labelledby-attribute">The <code>aria-labelledby</code> Attribute</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-how-is-aria-label-different-from-aria-labelledby">How is <code>aria-label</code> Different from <code>aria-labelledby</code>?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-best-practices-for-using-aria-labelledby">Best Practices for Using <code>aria-labelledby</code></a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-the-aria-describedby-attribute">The <code>aria-describedby</code> Attribute</a></p>
<ul>
<li><a class="post-section-overview" href="#heading-best-practices-for-using-aria-describedby">Best Pracices for Using <code>aria-describedby</code></a></li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-the-role-attribute">The <code>role</code> Attribute</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-common-role-values">Common <code>role</code> Values</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-best-practices-for-using-the-role-attribute">Best Practices for Using the <code>role</code> Attribute</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-the-aria-controls-attribute">The <code>aria-controls</code> Attribute</a></p>
<ul>
<li><a class="post-section-overview" href="#heading-best-practices-for-using-aria-controls">Best Practices for Using <code>aria-controls</code></a></li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-the-aria-selected-attribute">The <code>aria-selected</code> Attribute</a></p>
<ul>
<li><a class="post-section-overview" href="#heading-best-practices-for-using-aria-selected">Best Practices for Using <code>aria-selected</code></a></li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-the-tabindex-attribute">The <code>tabindex</code> Attribute</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-possible-tabindex-values">Possible <code>tabindex</code> Values</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-best-practices-for-using-tabindex">Best Practices for Using <code>tabindex</code></a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-the-title-attribute">The <code>title</code> Attribute</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-accessibility-concerns-with-the-title-attribute">Accessibility Concerns with <code>title</code></a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-best-practices-for-using-the-title-attribute">Best Practices for Using the <code>title</code> Attribute</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-using-the-for-attribute-in-label">Using the <code>for</code> Attribute in <code>label</code></a></p>
<ul>
<li><a class="post-section-overview" href="#heading-best-practices-for-using-the-for-attribute">Best Practices for Using the <code>for</code> Attribute</a></li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-the-scope-attribute">The <code>scope</code> Attribute</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-possible-scope-values">Possible <code>scope</code> Values</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-best-practices-for-using-the-scope-attribute">Best Practices for Using <code>scope</code></a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-the-aria-hidden-attribute">The <code>aria-hidden</code> Attribute</a></p>
<ul>
<li><a class="post-section-overview" href="#heading-best-practices-for-using-aria-hidden">Best Practices for Using <code>aria-hidden</code></a></li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-the-inert-attribute">The <code>inert</code> Attribute</a></p>
<ul>
<li><a class="post-section-overview" href="#heading-best-practices-for-using-the-inert-attribute">Best Practices for Using <code>inert</code></a></li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-the-aria-live-attribute">The <code>aria-live</code> Attribute</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-possible-values-for-aria-live">Possible Values for <code>aria-live</code></a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-best-practices-for-using-aria-live">Best Practices for Using <code>aria-live</code></a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-the-aria-roledescription-attribute">The <code>aria-roledescription</code> Attribute</a></p>
<ul>
<li><a class="post-section-overview" href="#heading-best-practices-for-using-aria-roledescription">Best Practices for Using <code>aria-roledescription</code></a></li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-the-aria-atomic-attribute">The <code>aria-atomic</code> Attribute</a></p>
<ul>
<li><a class="post-section-overview" href="#heading-the-aria-atomic-attribute">Best Practices for Using <code>aria-atomic</code></a></li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></p>
</li>
</ol>
<h2 id="heading-what-are-aria-attributes">What Are ARIA Attributes?</h2>
<p>Most of the attributes listed in this article are ARIA attributes. ARIA, which stands for <strong>Accessible Rich Internet Applications</strong>, is a set of attributes defined by the W3C (World Wide Web Consortium) to enhance the accessibility of web applications.</p>
<p>ARIA attributes provide additional information to assistive technologies like screen readers. Using them correctly can make complex web applications more accessible to individuals with visual, auditory, or motor impairments.</p>
<p>One key principle of using ARIA is that sometimes it's best not to use it. Although this might seem contradictory, you should only ARIA attributes when necessary. Overusing ARIA can disrupt the experience for users relying on assistive technologies. While sighted users might not notice any issues, excessive or improper use of ARIA can negatively impact accessibility.</p>
<h2 id="heading-the-alt-attribute">The <code>alt</code> Attribute</h2>
<p>The <code>alt</code> attribute likely isn't new to you if you've used HTML images. You use it to provide <em>alternative</em> text that displays when an image isn't properly shown on the screen.</p>
<p>But the most important use of the <code>alt</code> attribute is for accessibility. If the <code>alt</code> attribute is not present in an image element, then a screen reader may announce the name of the image file or the URL of the image instead of explaining what it's showing. This can be unhelpful and we don't want that.</p>
<p>The content in the <code>alt</code> attribute should be concise because its primary purpose is to briefly describe an image for those who cannot see it. This includes users who rely on screen readers, search engines, and users with slow internet connections where images may not load. If the <code>alt</code> text is too long, it may include unnecessary details that don't add value to the user's understanding.</p>
<p>The <code>alt</code> attribute is different from an image caption. Captions are visible and can provide more context or additional information about an image. Using a caption as <code>alt</code> text can make it too long and redundant.</p>
<p>If the image is purely decorative, then the alt attribute should be left empty. If an image has an empty alt attribute, an assistive tool will skip it. This is important to help keep users focused on the content and not distract them with unnecessary information.</p>
<p>Here's an example of how you can use the alt attribute:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Lions are remarkable for their powerful roars, 
which can be heard up to five miles away. 
These roars are used to communicate with other 
members of the pride, as well as to ward off rival lions and intruders. 
Although lions are often associated with the African savannah, 
a small population of Asiatic lions still exists in India's Gir Forest, 
making them one of the world's most endangered big cats.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"lion.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"a lion"</span> /&gt;</span> <span class="hljs-comment">&lt;!-- brief and gives context to the paragraph --&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"background-stars.png"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span> /&gt;</span> <span class="hljs-comment">&lt;!-- This image is purely for 
decoration so it's left empty --&gt;</span>
</code></pre>
<h2 id="heading-the-aria-label-attribute">The <code>aria-label</code> Attribute</h2>
<p>The <code>aria-label</code> attribute is used to provide an accessible name to an element that might not have visible text. A common example of this is a button that contains an image or SVG.</p>
<p>A lot of elements have an accessible name – the accessible name is the content inside the element. The accessible name for the heading in this example is "Frequently Asked Questions"</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Frequently Asked Questions<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
</code></pre>
<p>Everyone, including people using assistive technology, would clearly understand the meaning of the example above because it contains visible content.</p>
<p>But in the example below, a user relying on a screen reader might miss the content in the button if it doesn't have an <code>aria-label</code>. This is because the content in the button is an SVG and the SVG does not contain any visible content:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">aria-label</span>=<span class="hljs-string">"Search"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">svg</span>
      <span class="hljs-attr">fill</span>=<span class="hljs-string">"#000000"</span> 
      <span class="hljs-attr">height</span>=<span class="hljs-string">"20px"</span>
      <span class="hljs-attr">width</span>=<span class="hljs-string">"20px"</span>
      <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://www.w3.org/2000/svg"</span> 
      <span class="hljs-attr">viewBox</span>=<span class="hljs-string">"0 0 488.4 488.4"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">g</span> <span class="hljs-attr">stroke-width</span>=<span class="hljs-string">"0"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">g</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">g</span> <span class="hljs-attr">stroke-linecap</span>=<span class="hljs-string">"round"</span> <span class="hljs-attr">stroke-linejoin</span>=<span class="hljs-string">"round"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">g</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">g</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">g</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">g</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">d</span>=<span class="hljs-string">"M0,203.25c0,112.1,91.2,203.2,203.2,203.2c51.6,0,98.8-19.4,134.7-51.2l129.5,129.5c2.4,2.4,5.5,3.6,8.7,3.6 s6.3-1.2,8.7-3.6c4.8-4.8,4.8-12.5,0-17.3l-129.6-129.5c31.8-35.9,51.2-83,51.2-134.7c0-112.1-91.2-203.2-203.2-203.2 S0,91.15,0,203.25z M381.9,203.25c0,98.5-80.2,178.7-178.7,178.7s-178.7-80.2-178.7-178.7s80.2-178.7,178.7-178.7 S381.9,104.65,381.9,203.25z"</span> /&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">g</span>&gt;</span> 
        <span class="hljs-tag">&lt;/<span class="hljs-name">g</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">g</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<p>Do not overuse the <code>aria-label</code>. Not all content needs an <code>aria-label</code> – for example, if you have a button that contains an image with <code>alt</code>, or an SVG with a <code>title</code>, then those attributes act as the accessible name for that element.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"search-icon.png"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Search"</span> /&gt;</span> <span class="hljs-comment">&lt;!-- no need for aria-label --&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>

<span class="hljs-comment">&lt;!-- Another example --&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">svg</span>
    <span class="hljs-attr">fill</span>=<span class="hljs-string">"#000000"</span>
    <span class="hljs-attr">height</span>=<span class="hljs-string">"20px"</span>
    <span class="hljs-attr">width</span>=<span class="hljs-string">"20px"</span>
    <span class="hljs-attr">role</span>=<span class="hljs-string">"image"</span>
    <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://www.w3.org/2000/svg"</span>
    <span class="hljs-attr">viewBox</span>=<span class="hljs-string">"0 0 488.4 488.4"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Search Icon<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span> <span class="hljs-comment">&lt;!-- Accessible name --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">g</span> <span class="hljs-attr">stroke-width</span>=<span class="hljs-string">"0"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">g</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">g</span> <span class="hljs-attr">stroke-linecap</span>=<span class="hljs-string">"round"</span> <span class="hljs-attr">stroke-linejoin</span>=<span class="hljs-string">"round"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">g</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">g</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">g</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">g</span>&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">d</span>=<span class="hljs-string">"M0,203.25c0,112.1,91.2,203.2,203.2,203.2c51.6,0,98.8-19.4,134.7-51.2l129.5,129.5c2.4,2.4,5.5,3.6,8.7,3.6 s6.3-1.2,8.7-3.6c4.8-4.8,4.8-12.5,0-17.3l-129.6-129.5c31.8-35.9,51.2-83,51.2-134.7c0-112.1-91.2-203.2-203.2-203.2 S0,91.15,0,203.25z M381.9,203.25c0,98.5-80.2,178.7-178.7,178.7s-178.7-80.2-178.7-178.7s80.2-178.7,178.7-178.7 S381.9,104.65,381.9,203.25z"</span> /&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">g</span>&gt;</span> 
        <span class="hljs-tag">&lt;<span class="hljs-name">g</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">g</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<p>You should use the <code>aria-label</code> sparingly and appropriately. Overusing the attribute can lead to several issues:</p>
<ul>
<li><p>The <code>aria-label</code> content is not visible to sighted users. If a user with a cognitive disability is using a screen reader for support, they might not understand why they’re hearing different information from what they see on the screen.</p>
</li>
<li><p>Using <code>aria-label</code> extensively across a large codebase can make the HTML harder to maintain. You may struggle to track where labels are coming from, especially if they’re set programmatically or in multiple places.</p>
</li>
</ul>
<h3 id="heading-best-practices-for-using-aria-label">Best Practices for Using <code>aria-label</code></h3>
<ul>
<li><p>Whenever possible, use visible text labels. They’re easier to understand and maintain, and they ensure consistent experiences for all users.</p>
</li>
<li><p>When Possible: If there is already a visible label on the page, use <code>aria-labelledby</code> to link the element to the existing text instead of creating a new label with <code>aria-label</code> (we'll talk about this below).</p>
</li>
<li><p>If you use <code>aria-label</code>, keep the text short and to the point. It should describe the element’s purpose in as few words as possible.</p>
</li>
</ul>
<h2 id="heading-the-aria-labelledby-attribute">The <code>aria-labelledby</code> Attribute</h2>
<p>The <code>aria-labelledby</code> attribute is used to associate an element with another element that serves as its label. It links the target element to one or more other elements on the page that contain the text that should be used as the label.</p>
<p>You can use this attribute when there is already a visible text label or when the label needs to be composed of multiple text elements.</p>
<p>For example, you can use <code>aria-labelledby</code> in a <code>&lt;section&gt;</code> element to associate it with a heading or other text that serves as a label for the entire section.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"about-heading"</span>&gt;</span>About Us<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span> 
<span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">aria-labelledby</span>=<span class="hljs-string">"about-heading"</span>&gt;</span> <span class="hljs-comment">&lt;!-- use the id of the h2 --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>We are a company dedicated to providing excellent service...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"services-heading"</span>&gt;</span>Our Services<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">aria-labelledby</span>=<span class="hljs-string">"services-heading"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>We offer a wide range of services including...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
</code></pre>
<p>Sometimes, you might want to combine multiple pieces of text as the label. You can do this by listing multiple IDs in the <code>aria-labelledby</code> attribute:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"dialog-title"</span>&gt;</span>Confirmation Required<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"dialog-description"</span>&gt;</span>Are you sure you want to delete this item?<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">aria-labelledby</span>=<span class="hljs-string">"dialog-title dialog-description"</span>&gt;</span>Yes<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<p>The <code>aria-labelledby</code> is similar to the <code>aria-label</code> in that its purpose is to provide an accessible element.</p>
<h3 id="heading-how-is-aria-label-different-from-aria-labelledby">How is <code>aria-label</code> Different from <code>aria-labelledby</code>?</h3>
<p><code>aria-label</code> directly assigns a string of text as a label for an element. This text is not visible on the screen but is announced by assistive technologies like screen readers. It’s typically used when there is no visible text label.</p>
<p><code>aria-labelledby</code> points to one or more existing elements on the page (using their <code>id</code> attributes) that should be used as the label for the element. The label text is visible to all users because it’s part of the content of another element.</p>
<h3 id="heading-best-practices-for-using-aria-labelledby">Best Practices for Using <code>aria-labelledby</code></h3>
<ul>
<li><p>Use <code>aria-labelledby</code> over <code>aria-label</code> when there is already text on the page that can serve as the label. This reduces redundancy and ensures that both sighted users and screen reader users see the same content.</p>
</li>
<li><p>The <code>id</code> attributes referenced by <code>aria-labelledby</code> must be unique on the page and correctly point to existing elements. If the ID is missing or incorrect, the label won’t work, leading to accessibility issues.</p>
</li>
<li><p>When combining multiple labels, ensure that the resulting label makes sense when read together. The order of IDs in <code>aria-labelledby</code> matters, as screen readers will read the labels in the order they are listed.</p>
</li>
<li><p>Like <code>aria-label</code>, avoid overusing <code>aria-labelledby</code> in situations where a simpler approach (like using a visible <code>label</code> element directly) would suffice. This helps keep the code maintainable and reduces the cognitive load for users.</p>
</li>
</ul>
<h2 id="heading-the-aria-describedby-attribute">The <code>aria-describedby</code> Attribute</h2>
<p>The <code>aria-describedby</code> attribute is used to associate an element with one or more elements that provide additional descriptive information about it. The <code>aria-describedby</code> attribute is used to provide additional context or instructions to an element.</p>
<p>Unlike <code>aria-labelledby</code>, which is meant to provide a label or name, <code>aria-describedby</code> is intended to give users more detailed information or context about an element, often to supplement what they already know from the label.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"full-name"</span>&gt;</span>Full name<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">aria-labelledby</span>=<span class="hljs-string">"full-name"</span> <span class="hljs-attr">aria-describedby</span>=<span class="hljs-string">"info"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"info"</span>&gt;</span>Enter your full name.<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
</code></pre>
<p>When both <code>aria-labelledby</code> and <code>aria-describedby</code> are used on the same element, screen readers will first announce the label (from <code>aria-labelledby</code>), then the role of the element (for example, "button"), and finally the description (from <code>aria-describedby</code>).</p>
<h3 id="heading-best-practices-for-using-aria-describedby">Best Practices for Using <code>aria-describedby</code></h3>
<ul>
<li><p>Apply <code>aria-describedby</code> when you need to provide users with additional context or instructions that go beyond the label. This is particularly useful for forms, complex controls, or any element that might require clarification.</p>
</li>
<li><p>While <code>aria-describedby</code> is meant for more detailed descriptions, avoid overly long text. Keep the description focused on what the user needs to know to interact with the element effectively.</p>
</li>
<li><p>Just like with <code>aria-labelledby</code>, ensure that the elements referenced by <code>aria-describedby</code> have unique and relevant <code>id</code> attributes. The content of these elements should be directly relevant to the element they describe.</p>
</li>
</ul>
<h2 id="heading-the-role-attribute">The <code>role</code> Attribute</h2>
<p>The role attribute is used to specify the role of an element. You can use it to override the default role of a semantic element. It helps assistive technologies understand how an element should be interpreted or interacted with.</p>
<p>When using non-semantic elements (like <code>&lt;div&gt;</code> or <code>&lt;span&gt;</code>) to create interactive controls (buttons, dialogs, tabs, and so on), the <code>role</code> attribute informs assistive technologies of the element’s intended behavior. You can also use the role to define landmark roles that assist in navigation, such as <code>banner</code> or <code>complementary</code>, which defines the structure of the page for screen reader users.</p>
<h3 id="heading-common-role-values">Common <code>role</code> Values</h3>
<p>Roles for Landmark Regions:</p>
<ul>
<li><p><code>banner</code>: Represents the site header.</p>
</li>
<li><p><code>navigation</code>: Defines a navigation section of the page, often for site or page navigation links.</p>
</li>
<li><p><code>main</code>: Marks the main content of a document, distinct from sidebars, footers, and so on.</p>
</li>
<li><p><code>contentinfo</code>: Represents the footer information.</p>
</li>
</ul>
<p>This example below is just for demonstration purposes – you should use the right semantic element when possible:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"banner"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>My Website<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"navigation"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#home"</span>&gt;</span>Home<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#about"</span>&gt;</span>About<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"main"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Welcome to My Website<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Here is some main content...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"contentinfo"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-symbol">&amp;copy;</span> 2024 My Website<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>Roles for Widgets and Interactive Elements:</p>
<ul>
<li><p><code>button</code>: Represents a button element, which users can click to trigger an action.</p>
</li>
<li><p><code>dialog</code>: Marks a dialog box or modal that requires user interaction.</p>
</li>
<li><p><code>alert</code>: Identifies an element as an important message or alert that requires user attention.</p>
</li>
<li><p><code>tablist</code>, <code>tab</code>, <code>tabpanel</code>: Used for tabbed interfaces, where <code>tablist</code> contains the tabs, and each <code>tab</code> controls the visibility of its corresponding <code>tabpanel</code>.</p>
</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">tabindex</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"submitForm()"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"dialog"</span> <span class="hljs-attr">aria-labelledby</span>=<span class="hljs-string">"dialog-title"</span> <span class="hljs-attr">aria-modal</span>=<span class="hljs-string">"true"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"dialog-title"</span>&gt;</span>Confirmation<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Are you sure you want to proceed?<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"closeDialog()"</span>&gt;</span>Close<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>Example of Tabbed panel:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"tablist"</span> <span class="hljs-attr">aria-label</span>=<span class="hljs-string">"Sample Tabs"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"tab"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"tab-1"</span> <span class="hljs-attr">aria-controls</span>=<span class="hljs-string">"panel-1"</span> <span class="hljs-attr">aria-selected</span>=<span class="hljs-string">"true"</span> <span class="hljs-attr">tabindex</span>=<span class="hljs-string">"0"</span>&gt;</span>Tab 1<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"tab"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"tab-2"</span> <span class="hljs-attr">aria-controls</span>=<span class="hljs-string">"panel-2"</span> <span class="hljs-attr">aria-selected</span>=<span class="hljs-string">"false"</span> <span class="hljs-attr">tabindex</span>=<span class="hljs-string">"-1"</span>&gt;</span>Tab 2<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"tab"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"tab-3"</span> <span class="hljs-attr">aria-controls</span>=<span class="hljs-string">"panel-3"</span> <span class="hljs-attr">aria-selected</span>=<span class="hljs-string">"false"</span> <span class="hljs-attr">tabindex</span>=<span class="hljs-string">"-1"</span>&gt;</span>Tab 3<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"tabpanel"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"panel-1"</span> <span class="hljs-attr">aria-labelledby</span>=<span class="hljs-string">"tab-1"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Content for Tab 1<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is the content of the first tab.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"tabpanel"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"panel-2"</span> <span class="hljs-attr">aria-labelledby</span>=<span class="hljs-string">"tab-2"</span> <span class="hljs-attr">hidden</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Content for Tab 2<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is the content of the second tab.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"tabpanel"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"panel-3"</span> <span class="hljs-attr">aria-labelledby</span>=<span class="hljs-string">"tab-3"</span> <span class="hljs-attr">hidden</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Content for Tab 3<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is the content of the third tab.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h3 id="heading-best-practices-for-using-the-role-attribute">Best Practices for Using the <code>role</code> Attribute</h3>
<ul>
<li><p>Always prefer using native HTML elements that already have the appropriate role (for example, <code>&lt;button&gt;</code>, <code>&lt;header&gt;</code>, <code>&lt;nav&gt;</code>, <code>&lt;main&gt;</code>). This provides better accessibility support across a wider range of browsers and devices.</p>
</li>
<li><p>Don't <strong>overuse</strong> or <strong>misuse</strong> the <code>role</code> attribute as this can lead to confusion and reduced accessibility. Use <code>role</code> to enhance or clarify when needed, not to replace semantic HTML.</p>
</li>
<li><p>Understand implicit roles. Many HTML elements have implicit roles. For example, an <code>&lt;a&gt;</code> element with an <code>href</code> attribute automatically has the <code>link</code> role. Avoid adding redundant <code>role</code> attributes to these elements.</p>
</li>
</ul>
<h2 id="heading-the-aria-controls-attribute">The <code>aria-controls</code> Attribute</h2>
<p>The <code>aria-controls</code> attribute informs a screen reader that the element is controlled or affected by another element. It's commonly used to indicate that a component (like a button or a tab) controls or interacts with another part of the page (like a panel or a menu). It is also used in interactive components such as tabs, accordions, and sliders to describe which parts of the page are affected when the user interacts with the component.</p>
<p>For example, you can use <code>aria-controls</code> on a tab button to indicate which panel each button controls:</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!-- Tab Buttons --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"tab1"</span> <span class="hljs-attr">aria-controls</span>=<span class="hljs-string">"panel1"</span>&gt;</span>Tab 1<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"tab2"</span> <span class="hljs-attr">aria-controls</span>=<span class="hljs-string">"panel2"</span>&gt;</span>Tab 2<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>

<span class="hljs-comment">&lt;!-- Content Panels --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"panel1"</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"tabpanel"</span>&gt;</span>Content for Tab 1<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"panel2"</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"tabpanel"</span>&gt;</span>Content for Tab 2<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h3 id="heading-best-practices-for-using-aria-controls">Best Practices for Using <code>aria-controls</code></h3>
<ul>
<li><p>Ensure that the ID used in <code>aria-controls</code> matches the <code>id</code> of the controlled element exactly.</p>
</li>
<li><p>Use <code>aria-controls</code> in conjunction with role and state attributes like <code>aria-selected</code>, or <code>role="tabpanel"</code> to provide more complete information about the controlled elements and their states.</p>
</li>
<li><p>Apply <code>aria-controls</code> to interactive elements such as buttons or links that have a direct effect on other elements. It is not typically used for non-interactive content.</p>
</li>
</ul>
<h2 id="heading-the-aria-selected-attribute">The <code>aria-selected</code> Attribute</h2>
<p>The <code>aria-selected</code> attribute is used to indicate the current selection state of an element within a group of selectable items. A selectable item could be an option in a menu, a tab in a tabbed panel, or an item in a list box.</p>
<p>Here's an example of the selection state in a list box. <code>aria-selected="true"</code> in option 1 indicates that Option 1 is currently selected.</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!-- Listbox --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"listbox"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"option"</span> <span class="hljs-attr">aria-selected</span>=<span class="hljs-string">"true"</span>&gt;</span>Option 1<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"option"</span> <span class="hljs-attr">aria-selected</span>=<span class="hljs-string">"false"</span>&gt;</span>Option 2<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"option"</span> <span class="hljs-attr">aria-selected</span>=<span class="hljs-string">"false"</span>&gt;</span>Option 3<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
</code></pre>
<h3 id="heading-best-practices-for-using-aria-selected">Best Practices for Using <code>aria-selected</code></h3>
<ul>
<li><p>Use <code>aria-selected="true"</code> for the selected item and <code>aria-selected="false"</code> for non-selected items. The value should be a string, not a boolean.</p>
</li>
<li><p>Ensure that the visual state of the element (for example, active tab or selected option) matches the <code>aria-selected</code> value. Inconsistent states can lead to confusion for users of assistive technologies.</p>
</li>
<li><p>Use <code>aria-selected</code> in conjunction with appropriate <code>role</code> attributes (for example, <code>role="option"</code> for listbox items) to provide complete context.</p>
</li>
<li><p>Ensure that <code>aria-selected</code> is updated dynamically as users interact with the interface. For example, when a user selects a new option, update the <code>aria-selected</code> attribute accordingly.</p>
</li>
</ul>
<h2 id="heading-the-tabindex-attribute">The <code>tabindex</code> Attribute</h2>
<p>The <code>tabindex</code> attribute is used to control the keyboard navigation of an element. You can use it to activate focus for non-interactive elements like <code>div</code>, <code>p</code>, or <code>span</code> or disable focus for interactive elements like <code>button</code>, <code>a</code>, <code>input</code>. You can also use it to control focus order on a page.</p>
<h3 id="heading-possible-tabindex-values">Possible <code>tabindex</code> Values</h3>
<p><strong>Positive values:</strong> Elements with positive values become focusable and are included in the tab order with their numbers determining the order in which they are focused. Elements with lower numbers are focused before elements with higher numbers.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">tabindex</span>=<span class="hljs-string">"2"</span>&gt;</span>Cancel<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span> <span class="hljs-comment">&lt;!-- This will recieve focus last --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">tabindex</span>=<span class="hljs-string">"1"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span> <span class="hljs-comment">&lt;!-- This will recieve focus first --&gt;</span>
</code></pre>
<p>Elements with the same values will be navigated in the order in which they appear.</p>
<p><strong>Note:</strong> Using positive <code>tabindex</code> values can lead to a confusing and non-intuitive tab order. It is generally better to use <code>tabindex="0"</code> for elements that should be part of the natural tab order.</p>
<p><strong>Zero:</strong> You use this to make an element focusable and include it in the natural tab order based on its position in the document. It's useful for making elements focusable that are not normally focusable (like <code>&lt;div&gt;</code> or <code>&lt;span&gt;</code>).</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">tabindex</span>=<span class="hljs-string">"0"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span> 
<span class="hljs-comment">&lt;!-- The element becomes focusable using the keyboard --&gt;</span>
</code></pre>
<p><strong>Negative values:</strong> You use this to remove an element from the tab order, meaning it cannot be focused using the <code>Tab</code> key. But it can still be focused programmatically (via JavaScript). It's useful for elements that should not be focusable by default but may need to be focusable under certain conditions.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"name"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"other-names"</span> <span class="hljs-attr">tabindex</span>=<span class="hljs-string">"-1"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"email"</span>&gt;</span>

<span class="hljs-comment">&lt;!-- other-names will be skipped when tabbing through the inputs; 
only name and email will receive focus --&gt;</span>
</code></pre>
<h3 id="heading-best-practices-for-using-tabindex">Best Practices for Using <code>tabindex</code></h3>
<ul>
<li><p>Rely on the natural tab order as much as possible. Use <code>tabindex="0"</code> to include elements in the tab order and avoid using positive values unless absolutely necessary.</p>
</li>
<li><p>Using positive <code>tabindex</code> values can create an unpredictable tab order and make it harder for users to navigate. It's better to use the default flow and <code>tabindex="0"</code>.</p>
</li>
<li><p>Use <code>tabindex="-1"</code> for elements not intended to be focused.</p>
</li>
<li><p>Ensure that the focus order follows a logical and intuitive sequence, which matches the visual layout and interaction flow of the page.</p>
</li>
<li><p>Test with keyboard and assistive technologies.</p>
</li>
<li><p>When dynamically adding or removing focusable elements (for example, through JavaScript), ensure that focus management is handled properly to maintain a smooth experience.</p>
</li>
</ul>
<h2 id="heading-the-title-attribute">The <code>title</code> Attribute</h2>
<p>The <code>title</code> attribute in HTML is used to provide additional information about an element. The content in the attribute shows in a tooltip when a user hovers over the element containing the title. It can be applied to most HTML elements, including links, images, and form fields.</p>
<p>You can use the title attribute to provide a brief explanation or description of the content of an element. For example, you can use it to clarify the meaning of abbreviations or acronyms when used with the <code>&lt;abbr&gt;</code> tag.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">abbr</span> <span class="hljs-attr">title</span>=<span class="hljs-string">"World Wide Web"</span>&gt;</span>WWW<span class="hljs-tag">&lt;/<span class="hljs-name">abbr</span>&gt;</span>
<span class="hljs-comment">&lt;!-- Hovering over "WWW" displays the tooltip "World Wide Web," 
explaining the abbreviation. --&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"logo.png"</span> 
<span class="hljs-attr">alt</span>=<span class="hljs-string">"Company Logo"</span> 
<span class="hljs-attr">title</span>=<span class="hljs-string">"This is the logo of our company"</span>&gt;</span>
<span class="hljs-comment">&lt;!-- Users will see "This is the logo of our company" 
when hovering over the image. --&gt;</span>
</code></pre>
<h3 id="heading-accessibility-concerns-with-the-title-attribute">Accessibility Concerns with the <code>title</code> Attribute</h3>
<p>The title attribute can be useful, but it comes with some accessibility concerns:</p>
<ul>
<li><p>Screen readers do not consistently announce the <code>title</code> attribute, especially when there is also an <code>alt</code> attribute – or they may ignore it altogether. Users of assistive technologies may miss out on the information provided by the <code>title</code> attribute, especially if they rely solely on screen readers.</p>
</li>
<li><p>The tooltip generated by the <code>title</code> attribute typically appears only on hover with a mouse or trackpad. Users who navigate with a keyboard or touch screen may not have access to this information.</p>
</li>
<li><p>The content of the <code>title</code> attribute is hidden by default and only revealed on hover. This makes it less accessible to users who don't know they need to hover to get additional information.</p>
</li>
<li><p>Tooltips can be difficult to read because they often disappear quickly, and their content might be truncated or too long to fit within the tooltip window.</p>
</li>
</ul>
<h3 id="heading-best-practices-for-using-the-title-attribute">Best Practices for Using the <code>title</code> Attribute</h3>
<ul>
<li><p>Avoid relying solely on the <code>title</code> attribute. Ensure that critical information is available in a more accessible manner, such as visible text or ARIA attributes.</p>
</li>
<li><p>Use the <code>title</code> attribute for supplementary, non-essential information that enhances user experience but isn’t critical to understanding the content.</p>
</li>
<li><p>For form inputs, use the <code>aria-describedby</code> attribute to associate additional instructions with a form element. Use visible labels or descriptions instead of or in addition to the <code>title</code> attribute to ensure that all users have access to the information.</p>
</li>
<li><p>If you use the <code>title</code> attribute, keep the text brief and to the point. Long tooltips can be difficult to read and may get truncated.</p>
</li>
</ul>
<h2 id="heading-using-the-for-attribute-in-label">Using the <code>for</code> Attribute in <code>label</code></h2>
<p>The <code>for</code> attribute, when used in <code>&lt;label&gt;</code>, is used to connect a label to its corresponding form control element – that is <code>&lt;input&gt;</code>, <code>&lt;select&gt;</code>, or <code>&lt;textarea&gt;</code>. Screen readers will announce the label when the assigned input is focused. When used correctly, clicking on the label will focus on the corresponding input.</p>
<p>The value of the <code>for</code> attribute should match the <code>id</code> of the input it is associated with:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"fullname"</span>&gt;</span>Full Name<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"fullname"</span>&gt;</span>
<span class="hljs-comment">&lt;!-- When the user clicks on the "Full Name" label, 
the cursor will focus on the corresponding input field. --&gt;</span>
</code></pre>
<h3 id="heading-best-practices-for-using-the-for-attribute">Best Practices for Using the <code>for</code> Attribute</h3>
<ul>
<li><p>Ensure that each form control has a unique <code>id</code> attribute so that the <code>for</code> attribute can correctly reference it. Avoid using duplicate <code>id</code> values on the same page.</p>
</li>
<li><p>Avoid empty <code>for</code> attributes. If there’s no associated form control, it can confuse users of assistive technologies.</p>
</li>
<li><p>Position labels close to their associated form controls. Typically, labels should be placed above or to the left of the form controls for optimal readability and usability.</p>
</li>
</ul>
<h2 id="heading-the-scope-attribute">The <code>scope</code> Attribute</h2>
<p>The <code>scope</code> attribute is used in HTML tables to define the relationship between table headers and the cells they describe. The attribute is particularly important for accessibility because it helps screen readers and other assistive technologies understand the structure of the table and convey the correct information to users.</p>
<p>The <code>scope</code> attribute is applied to <code>&lt;th&gt;</code> (table header) elements to specify whether the header applies to a row, a column, or a group of rows or columns</p>
<h3 id="heading-possible-scope-values">Possible <code>scope</code> Values</h3>
<ul>
<li><code>row</code>: Indicates that the <code>&lt;th&gt;</code> element is a header for a row. In the example below, <code>scope="row"</code> is used for the first <code>&lt;th&gt;</code> element in each row, indicating that the header applies to the entire row.</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">table</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tbody</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"row"</span>&gt;</span>Product A<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$1000<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$1200<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$1100<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"row"</span>&gt;</span>Product B<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$900<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$950<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$1000<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">tbody</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
</code></pre>
<ul>
<li><code>col</code>: Indicates that the <code>&lt;th&gt;</code> element is a header for a column.</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">table</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">thead</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"col"</span>&gt;</span>Name<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"col"</span>&gt;</span>Age<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"col"</span>&gt;</span>Occupation<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
<span class="hljs-comment">&lt;!-- The scope="col" attribute indicates that each &lt;th&gt; element 
serves as a header for the corresponding column beneath it. --&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">thead</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tbody</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Jane<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>30<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Engineer<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Tobe<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>25<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Designer<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">tbody</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
</code></pre>
<ul>
<li><code>rowgroup</code>: Indicates that the <code>&lt;th&gt;</code> element is a header for a group of rows. In the example below, the rows "Marketing Department" and "Sales Department" have the <code>scope="rowgroup"</code> attribute to indicate that these rows act as headers for the groups of rows that follow:</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">table</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">thead</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"col"</span>&gt;</span>Department<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"col"</span>&gt;</span>Employee Name<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"col"</span>&gt;</span>Position<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"col"</span>&gt;</span>Salary<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">thead</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">tbody</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- Row Group for the Marketing Department --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"rowgroup"</span> <span class="hljs-attr">colspan</span>=<span class="hljs-string">"4"</span>&gt;</span>Marketing Department<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"row"</span>&gt;</span>Amari Pere<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Marketing Manager<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$75,000<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"row"</span>&gt;</span>Uyati Hope<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>SEO Specialist<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$65,000<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>

    <span class="hljs-comment">&lt;!-- Row Group for the Sales Department --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"rowgroup"</span> <span class="hljs-attr">colspan</span>=<span class="hljs-string">"4"</span>&gt;</span>Sales Department<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"row"</span>&gt;</span>Timini Prosper<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Sales Manager<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$80,000<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"row"</span>&gt;</span>Delilu Pink<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Account Executive<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$70,000<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">tbody</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
</code></pre>
<ul>
<li><code>colgroup</code>: Indicates that the <code>&lt;th&gt;</code> element is a header for a group of columns. In the example below, <code>scope="colgroup"</code> is used to indicate that the first row of headers applies to groups of columns (Q1 and Q2), while <code>scope="col"</code> and <code>scope="row"</code> are used for individual columns and rows.</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">table</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">thead</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"colgroup"</span>&gt;</span>Region<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"colgroup"</span>&gt;</span>Q1<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"colgroup"</span>&gt;</span>Q2<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"col"</span>&gt;</span>Sales<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"col"</span>&gt;</span>Profit<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"col"</span>&gt;</span>Sales<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"col"</span>&gt;</span>Profit<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">thead</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tbody</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"row"</span>&gt;</span>North<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$2000<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$400<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$2500<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$500<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">"row"</span>&gt;</span>South<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$1500<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$300<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$1800<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>$350<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">tbody</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
</code></pre>
<h3 id="heading-best-practices-for-using-the-scope-attribute">Best Practices for Using the <code>scope</code> Attribute</h3>
<ul>
<li><p>Always define <code>scope</code> for complex tables to clarify the relationship between headers and data cells.</p>
</li>
<li><p>Simplify table structures when possible. While the <code>scope</code> attribute helps with accessibility, consider simplifying table structures where possible. If a table is too complex, it might be difficult for all users to understand, even with proper markup.</p>
</li>
<li><p>For particularly complex tables, consider using ARIA attributes like <code>aria-labelledby</code> or <code>aria-describedby</code> to provide additional context and ensure that all users can navigate the table effectively.</p>
</li>
<li><p>After applying the <code>scope</code> attribute, test the table with screen readers to ensure that the relationships between headers and data cells are announced correctly.</p>
</li>
<li><p>Don’t use <code>scope</code> in situations where it’s unnecessary. For simple tables where each header is clearly associated with a single row or column, HTML’s default behavior is usually sufficient.</p>
</li>
</ul>
<h2 id="heading-the-aria-hidden-attribute">The <code>aria-hidden</code> Attribute</h2>
<p>The aria-hidden attribute is used to control the visibility of an element for assistive technologies while it's still visible on the screen. You can use it to hide purely decorative elements, like icons or images, that don't add meaningful information to the content. This helps prevent screen readers from reading unnecessary information.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">"true"</span>&gt;</span>🔍<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
    Search
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<p>You can also use it to hide content that has already been announced to prevent redundancy in what screen readers announce. For content that is toggled on and off (like modals, or expandable sections), you can use <code>aria-hidden</code> to hide the inactive content from screen readers, ensuring that they only interact with the visible, active content.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">"true"</span>&gt;</span>✉<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span> <span class="hljs-comment">&lt;!-- hide decorative icon --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>Messages<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<p>You can also use <code>aria-hidden</code> when creating complex widgets (like carousels or tabbed interfaces) to hide inactive panels or slides from assistive technologies, focusing their attention on the active part of the widget.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"menu"</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">"true"</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- Menu content here --&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"toggleMenu()"</span>&gt;</span>Toggle Menu<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
    <span class="hljs-keyword">const</span> toggleMenu = <span class="hljs-function">() =&gt;</span> {
        <span class="hljs-keyword">const</span> menu = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'menu'</span>);
        <span class="hljs-keyword">const</span> isHidden = menu.getAttribute(<span class="hljs-string">'aria-hidden'</span>) === <span class="hljs-string">'true'</span>;

        menu.setAttribute(<span class="hljs-string">'aria-hidden'</span>, !isHidden);
    }
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<h3 id="heading-best-practices-for-using-aria-hidden">Best Practices for Using <code>aria-hidden</code></h3>
<ul>
<li><p>Only use <code>aria-hidden</code> when you need to hide content from screen readers to avoid overwhelming users with redundant or irrelevant information.</p>
</li>
<li><p>Do not use on elements that users need to interact with, like buttons or links.</p>
</li>
<li><p>Ensure that <code>aria-hidden</code> accurately reflects the visibility of elements on the screen. If an element becomes visible or hidden via JavaScript or CSS, update <code>aria-hidden</code> accordingly to maintain accessibility.</p>
</li>
<li><p>In a team environment, document why and where <code>aria-hidden</code> is used in your codebase, so that other team members understand its purpose and can maintain it properly.</p>
</li>
</ul>
<h2 id="heading-the-inert-attribute">The <code>inert</code> Attribute</h2>
<p>The <code>inert</code> attribute prevents an element and all of its descendants from being focusable, interactive, or perceivable by assistive technologies. When an element has the <code>inert</code> attribute, it cannot receive focus, be clicked on, or be interacted with in any way. It's also hidden from assistive technologies like screen readers.</p>
<p>Unlike <code>aria-hidden</code>, which only affects accessibility, <code>inert</code> applies to all user interactions. The inert attribute can be used to disable sections of a page that are temporarily irrelevant, such as during form validation errors, while loading data, or when a certain section is hidden but still in the DOM. It can also be used in complex user interfaces like multi-step forms or wizards to ensure that users only interact with the current step or section</p>
<p>The most common use of inert, however, is in a modal, where you want to prevent users from interacting with the background content while the modal is open.</p>
<p>Like in the example below, when the modal is open the <code>inert</code> attribute is added to the main content, making it non-interactive and hidden from screen readers. When the modal is closed, the <code>inert</code> attribute is removed, and the main content becomes interactive again.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"main-content"</span> <span class="hljs-attr">inert</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is the main content of the page. It will be inactive when the modal is open.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"modal"</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"dialog"</span> <span class="hljs-attr">aria-modal</span>=<span class="hljs-string">"true"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Modal Title<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is the content inside the modal.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"closeModal()"</span>&gt;</span>Close Modal<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">openModal</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'main-content'</span>).setAttribute(<span class="hljs-string">'inert'</span>, <span class="hljs-string">''</span>);
    <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'modal'</span>).style.display = <span class="hljs-string">'block'</span>;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">closeModal</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'main-content'</span>).removeAttribute(<span class="hljs-string">'inert'</span>);
    <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'modal'</span>).style.display = <span class="hljs-string">'none'</span>;
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<h3 id="heading-best-practices-for-using-the-inert-attribute">Best Practices for Using the <code>inert</code> Attribute</h3>
<ul>
<li><p>Ensure that when you use <code>inert</code>, the visually inactive or disabled state of elements is clear to sighted users. For example, dimming or blurring background content when a modal is open can complement the <code>inert</code> attribute.</p>
</li>
<li><p>Don't overuse <code>inert</code>, as doing so might unintentionally make significant portions of your page non-interactive and inaccessible. Use it judiciously to manage user focus and interaction only when necessary.</p>
</li>
<li><p>When dynamically adding and removing the <code>inert</code> attribute, ensure that it is properly removed when no longer needed so that users can regain access to previously disabled content.</p>
</li>
</ul>
<h2 id="heading-the-aria-live-attribute">The <code>aria-live</code> Attribute</h2>
<p>You can use the <code>aria-live</code> attribute to notify assistive technologies about dynamic content changes on a webpage. When <code>aria-live</code> is applied to an element, screen readers are alerted when the content inside that element is updated, ensuring that users are informed about important changes that occur after the page has initially loaded.</p>
<p>This attribute can be useful for content that updates dynamically, such as notifications, alerts, chat messages, or stock prices. It ensures that users are aware of changes that might otherwise go unnoticed.</p>
<h3 id="heading-possible-values-for-aria-live">Possible Values for <code>aria-live</code></h3>
<p>There are three main values: <code>off</code>, <code>polite</code>, and <code>assertive</code>.</p>
<ul>
<li><p><code>off</code>: Default value, updates to the element will not be announced by screen readers.</p>
</li>
<li><p><code>polite</code>: Updates will be announced by the screen reader, but only after the user has finished interacting with the current task or reading other content. This ensures that the update does not interrupt the user’s current activity.</p>
</li>
</ul>
<p>In the example below, each new message is added to the <code>#messages</code> container, which has <code>aria-live="polite"</code>. The screen reader will announce the new message only after the user finishes their current activity.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"chat-window"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"messages"</span> <span class="hljs-attr">aria-live</span>=<span class="hljs-string">"polite"</span>&gt;</span>
        <span class="hljs-comment">&lt;!-- Existing messages are here --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>John: Hello!<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>You: Hi there!<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"addMessage()"</span>&gt;</span>Send Message<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">addMessage</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> newMessage = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">'div'</span>);
    newMessage.textContent = <span class="hljs-string">'Alice: How are you?'</span>;
    <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'messages'</span>).appendChild(newMessage);
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<ul>
<li><code>assertive</code>: Updates will be announced immediately, interrupting whatever the screen reader is currently announcing. Use this for urgent or critical information that requires the user’s immediate attention.</li>
</ul>
<p>In the example below, updates to the stock prices are placed within a container that has <code>aria-live="assertive"</code>.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"stock-ticker"</span> <span class="hljs-attr">aria-live</span>=<span class="hljs-string">"assertive"</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- Initial stock prices --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"stock1"</span>&gt;</span>Stock A: $100<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"stock2"</span>&gt;</span>Stock B: $150<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"updateStockPrices()"</span>&gt;</span>Update Prices<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">updateStockPrices</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'stock1'</span>).textContent = <span class="hljs-string">'Stock A: $95'</span>;
    <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'stock2'</span>).textContent = <span class="hljs-string">'Stock B: $155'</span>;
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<h3 id="heading-best-practices-for-using-aria-live">Best Practices for Using <code>aria-live</code></h3>
<ul>
<li><p>Use <code>aria-live="polite"</code> for non-critical updates to avoid disrupting the user’s experience. Reserve <code>aria-live="assertive"</code> for urgent updates that require immediate attention, such as critical errors or security warnings.</p>
</li>
<li><p>Be mindful of how often you use <code>aria-live</code> elements on a page. Overusing it can lead to an overstimulating experience for users who rely on screen readers, as they may be overwhelmed by frequent announcements.</p>
</li>
<li><p>Don’t use <code>aria-live</code> on content that doesn’t need to be announced, or on content that’s already being communicated to the user in another way.</p>
</li>
<li><p><code>aria-live</code> is particularly useful for content that is updated dynamically, such as live sports scores, breaking news, or chat applications. Make sure that the user is kept informed of important updates as they occur.</p>
</li>
</ul>
<h2 id="heading-the-aria-roledescription-attribute">The <code>aria-roledescription</code> Attribute</h2>
<p>You can use <code>aria-roledescription</code> to provide a human-readable, localized description for the role of an element. It overrides the implicit or explicit <code>role</code> value for screen readers, and allows developers to create more intuitive and context-specific descriptions for complex or unconventional user interface components that may not have a standard role name.</p>
<p>You can use it to provide a clearer explanation of the element’s purpose or functionality.</p>
<p>In the example below, screen readers will announce it as "Bookmark Button" instead of just "Button."</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">aria-roledescription</span>=<span class="hljs-string">"Bookmark Button"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">"true"</span>&gt;</span>⭐<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span> Save this page
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<p>You can also use it to support internationalization, like providing role descriptions in different languages.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">aria-roledescription</span>=<span class="hljs-string">"Search Button"</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">"true"</span>&gt;</span>🔍<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span> Search
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">aria-roledescription</span>=<span class="hljs-string">"Botón de busqueda"</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"es"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">"true"</span>&gt;</span>🔍<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span> Buscar
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">aria-roledescription</span>=<span class="hljs-string">"Bouton de recherche"</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"fr"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">"true"</span>&gt;</span>🔍<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span> Recherche
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<h3 id="heading-best-practices-for-using-aria-roledescription">Best Practices for Using <code>aria-roledescription</code></h3>
<ul>
<li><p>Only use <code>aria-roledescription</code> when the standard role does not sufficiently describe the element's purpose.</p>
</li>
<li><p>The description should be short, clear, and directly related to the element's function. Avoid using jargon or overly technical language.</p>
</li>
<li><p><code>aria-roledescription</code> should be used alongside an appropriate ARIA role, not as a replacement. The <code>role</code> provides the foundational context (like <code>"button"</code> or <code>"listbox"</code>), while the description adds clarity.</p>
</li>
<li><p>If your application supports multiple languages, ensure that the <code>aria-roledescription</code> values are localized to match the user's language preferences. This helps provide a consistent and understandable experience.</p>
</li>
<li><p>Ensure that the <code>aria-roledescription</code> does not repeat or conflict with other ARIA attributes or element labels. It should complement, not duplicate, the information already provided.</p>
</li>
</ul>
<h2 id="heading-the-aria-atomic-attribute">The <code>aria-atomic</code> Attribute</h2>
<p>You can use the <code>aria-atomic</code> attribute to control how updates to an element are announced by assistive technologies. When <code>aria-atomic</code> is set to <code>true</code>, it indicates that when changes occur within the element, the entire content of the element should be treated as a single unit and announced in full by the screen reader (rather than announcing only the changed parts).</p>
<p>In cases where updates to part of an element might make the overall context unclear, <code>aria-atomic</code> helps by providing a full announcement of the element's content, giving users a complete understanding of the context.</p>
<p>It is often used in conjunction with <code>aria-live</code>. While <code>aria-live</code> determines how updates are announced (politely or assertively), <code>aria-atomic</code> controls whether the entire content is read or just the changes.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"news-ticker"</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"region"</span> <span class="hljs-attr">aria-live</span>=<span class="hljs-string">"polite"</span> <span class="hljs-attr">aria-atomic</span>=<span class="hljs-string">"true"</span>&gt;</span>
  Breaking News: Major storm expected this weekend.
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"updateHeadline()"</span>&gt;</span>Update Headline<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">updateHeadline</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'news-ticker'</span>).innerText = <span class="hljs-string">'Breaking News: Stock market hits record high!'</span>;
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<h3 id="heading-best-practices-for-using-aria-atomic">Best Practices for Using <code>aria-atomic</code></h3>
<ul>
<li><p>Apply <code>aria-atomic="true"</code> only to elements where a full announcement of updates is essential for understanding the context.</p>
</li>
<li><p>When using <code>aria-atomic="true"</code>, ensure that the content within the element provides consistent and complete context to users.</p>
</li>
<li><p>Use <code>aria-atomic</code> in combination with <code>aria-live</code> to specify how updates should be announced. This ensures that the updates are announced in the appropriate manner and with full context.</p>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Understanding and effectively using HTML attributes for accessibility is crucial for creating inclusive web experiences. By understanding and using these attributes appropriately, you can ensure that your application has a great user experience for all visitors.</p>
<h3 id="heading-resources">Resources</h3>
<ul>
<li><p><a target="_blank" href="https://www.w3.org/WAI/ARIA/apg/practices/names-and-descriptions/">Providing Accessible Names and Descriptions</a></p>
</li>
<li><p><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA">MDN ARIA</a></p>
</li>
<li><p><a target="_blank" href="https://www.w3.org/WAI/ARIA/apg/practices/read-me-first/">No ARIA is better than Bad ARIA</a></p>
</li>
<li><p><a target="_blank" href="https://www.w3.org/WAI/ARIA/apg/example-index/#examples_by_props_label">ARIA examples by properties and states</a></p>
</li>
</ul>
<p>Thank you so much for reading, I hope this guide helps you create more accessible web content. If you found it helpful, consider sharing.</p>
<p>You can connect with me on <a target="_blank" href="https://www.linkedin.com/in/elizabeth-meshioye/">LinkedIn</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Create Interactive HTML Prototypes – How Far Can You Go Without JavaScript? ]]>
                </title>
                <description>
                    <![CDATA[ Interactivity is what makes a website come alive. Whether it's a button that reveals more content or a form that responds to your input, these little touches keep users engaged. Traditionally, we've relied heavily on JavaScript to make websites inter... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-create-interactive-html-prototypes/</link>
                <guid isPermaLink="false">66cdb0be7c4342e19f393004</guid>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Joan Ayebola ]]>
                </dc:creator>
                <pubDate>Tue, 27 Aug 2024 10:55:58 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1724485095228/2bc8f1c3-d0b8-41a2-a741-f9eaa2b6dde0.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Interactivity is what makes a website come alive. Whether it's a button that reveals more content or a form that responds to your input, these little touches keep users engaged. Traditionally, we've relied heavily on JavaScript to make websites interactive. But what if I told you that HTML alone can do more than you think?</p>
<p>In this article, we'll explore how far you can go in creating interactive prototypes using just HTML. We'll challenge the common belief that JavaScript is always necessary for interactivity by showing you how to build engaging features with nothing but HTML. By the end, you'll see that sometimes, simplicity is all you need to bring your ideas to life.</p>
<h3 id="heading-table-of-contents">Table of Contents</h3>
<ul>
<li><p><a class="post-section-overview" href="#heading-basics-of-html-forms">Basics of HTML For</a><a class="post-section-overview" href="#heading-basics-of-html-forms">ms</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-interactive-html-elements">Interactive HTML Elements</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-create-advanced-interactive-prototypes-with-html">Creating Advanced Interactive Prototypes with HTML</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-html-only-interactive-techniques">HTML-Only Interactive Techniques</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-design-tips-for-html-only-prototypes">Design Tips for HTML-Only Prototypes</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></p>
</li>
</ul>
<h2 id="heading-basics-of-html-forms"><strong>Basics of HTML Forms</strong></h2>
<p>HTML forms are essential for collecting user input, whether it's for signing up for a service, submitting feedback<a class="post-section-overview" href="#heading-html-only-interactive-techniques">,</a> or conductin<a class="post-section-overview" href="#heading-design-tips-for-html-only-prototypes">g</a> a search. The power of forms lies <a class="post-section-overview" href="#heading-design-tips-for-html-only-prototypes"></a>in their ability to handle user data and send it to a server for processing. Understanding how to construct a basic form is the first step in leveraging HTML's interactive capabilities.</p>
<p>A basic form in HTML might look like this</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">"/submit"</span> <span class="hljs-attr">method</span>=<span class="hljs-string">"post"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"name"</span>&gt;</span>Name:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"name"</span> <span class="hljs-attr">na</span>&lt;<span class="hljs-attr">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724569293880/1cb1bba7-7532-4741-9451-b4ce6aabf74f.jpeg" alt="A simple form with two input fields labeled &quot;Name:&quot; and &quot;Email:&quot;, followed by a &quot;Submit&quot; button. " class="image--center mx-auto" width="379" height="192" loading="lazy"></p>
<ul>
<li><p>The <code>&lt;form&gt;</code> element is a container for all the input elements. The <code>action</code> attribute specifies where the form data should be sent when the form is submitted. The <code>method</code> attribute determines how the data is sent (typically using <code>GET</code> or <code>POST</code>).</p>
</li>
<li><p>The <code>&lt;label&gt;</code> element provides a user-friendly label for each input field, improving accessibility.</p>
</li>
<li><p>The <code>&lt;input&gt;</code> elements are where users enter their information. Each input has a <code>type</code> attribute that defines what kind of data it accepts (for example: <code>text</code>, <code>email</code>, <code>password</code>).</p>
</li>
<li><p>The <code>&lt;button&gt;</code> element submits the form when clicked.</p>
</li>
</ul>
<p>Forms are fundamental because they involve direct user interaction, making them a critical component of any interactive prototype.</p>
<h2 id="heading-interactive-html-elements"><strong>Interactive HTML Elements</strong></h2>
<p>Beyond forms, HTML includes a variety of elements that naturally respond to user actions. These elements can be used to create interactive interfaces without writing any JavaScript, which is perfect for quick prototyping.</p>
<h3 id="heading-buttons-checkboxes-and-radio-buttons"><strong>Buttons, Checkboxes, and Radio Buttons</strong></h3>
<p><strong>Buttons:</strong> Buttons are one of the most straightforward interactive elements. They can perform a wide range of actions, from submitting a form to triggering a CSS animation. Buttons are usually defined with the <code>&lt;button&gt;</code> or <code>&lt;input type="button"&gt;</code> elements.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span>&gt;</span>Click Me<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724573151277/d726e8ce-3e0e-49c3-a3b0-c20944c6e807.jpeg" alt="A button with the text &quot;Click Me&quot; displayed in the center." class="image--center mx-auto" width="135" height="67" loading="lazy"></p>
<p>In the above example, the button doesn't do anything by itself unless tied to a form or an action. However, in prototypes, buttons can visually represent functionality, making the prototype feel more complete.</p>
<p><strong>Checkboxes:</strong> Checkboxes allow users to select multiple options from a list. They are ideal for scenarios where more than one choice is allowed.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"option1"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"option1"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Option 1"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"option1"</span>&gt;</span>Option 1<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/qBzYwLY" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p>Each checkbox can be checked or unchecked, providing immediate visual feedback.</p>
<p><strong>Radio Buttons:</strong> Radio buttons are used when only one option can be selected from a group. This is useful in cases like surveys or quizzes where the user needs to choose one answer.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"choice1"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"choice"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Choice 1"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"choice1"</span>&gt;</span>Choice 1<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"choice2"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"choice"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Choice 2"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"choice2"</span>&gt;</span>Choice 2<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/BagxEMB" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p>When one radio button in a group is selected, the others are automatically deselected, ensuring that only one option is chosen.</p>
<p>These elements are simple yet powerful, providing the basic building blocks for interactive user interfaces.</p>
<h3 id="heading-the-and-elements"><strong>The</strong> <code>&lt;details&gt;</code> and <code>&lt;summary&gt;</code> Elements</h3>
<p>The <code>&lt;details&gt;</code> and <code>&lt;summary&gt;</code> elements provide a way to create sections of content that users can expand or collapse. This is particularly useful for FAQs, where you might want to show the question and hide the answer until the user chooses to reveal it.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">details</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">summary</span>&gt;</span>What is HTML?<span class="hljs-tag">&lt;/<span class="hljs-name">summary</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>HTML stands for HyperText Markup Language. It is the standard language used to create web pages.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">details</span>&gt;</span>
</code></pre>
<details>
  <summary>What is HTML?</summary>
  <p>HTML stands for HyperText Markup Language. It is the standard language used to create web pages.</p>
</details>

<p><strong>How it works:</strong></p>
<ul>
<li><p>The <code>&lt;summary&gt;</code> element is the clickable heading that the user interacts with.</p>
</li>
<li><p>The content inside the <code>&lt;details&gt;</code> tag (but outside the <code>&lt;summary&gt;</code> tag) remains hidden until the user clicks on the summary, revealing it.</p>
</li>
</ul>
<p>This simple interaction adds a layer of user control, allowing content to be hidden or shown based on user action, all without JavaScript.</p>
<h3 id="heading-different-types-of"><strong>Different Types of</strong> <code>&lt;input&gt;</code></h3>
<p>The <code>&lt;input&gt;</code> element is one of the most versatile in HTML. Depending on its <code>type</code> attribute, it can serve different purposes, from accepting text input to allowing date selection. Understanding the various input types is key to creating functional prototypes.</p>
<p>Here are a few common types:</p>
<p><strong>Text Input:</strong> This is the most common input type, used for single-line text input.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"username"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Enter your username"</span>&gt;</span>
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/eYwroxW" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p>The <code>placeholder</code> attribute provides a hint to the user about what to enter.</p>
<p><strong>Password Input:</strong> This input type hides the characters as the user types, making it suitable for sensitive information like passwords.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"password"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"password"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Enter your password"</span>&gt;</span>
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/dyBeLaq" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p><strong>Email Input:</strong> The <code>email</code> type ensures that the user’s input is in a valid email format.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Enter your email"</span>&gt;</span>
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/OJeZGdK" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p><strong>Date Input:</strong> This type provides a date picker, allowing users to select a date from a calendar interface.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"date"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"birthdate"</span>&gt;</span>
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/yLdjrwV" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p>These different input types enhance user experience by providing specialized interfaces for different types of data. They help make the form more intuitive and reduce the likelihood of user errors.</p>
<h2 id="heading-how-to-create-advanced-interactive-prototypes-with-html"><strong>How to Create Advanced Interactive Prototypes with HTML</strong></h2>
<p>Once you're comfortable with the basics of HTML forms and interactive elements, you can start creating more advanced prototypes that offer a richer user experience. In this section, we'll explore how to combine form elements to build complex interactions and simulate dynamic content updates, using only HTML.</p>
<h3 id="heading-how-to-combine-form-elements-for-complex-interactions"><strong>How to Combine Form Elements for Complex Interactions</strong></h3>
<p>Combining different form elements can help you create more sophisticated interactions and user experiences. While HTML alone has its limitations, you can still achieve quite a bit by using these elements creatively.</p>
<h4 id="heading-multi-step-forms-and-conditional-inputs"><strong>Multi-step Forms and Conditional Inputs</strong></h4>
<p>Multi-step forms are useful when you want to break a long form into smaller, more manageable sections. This approach can improve user experience by making complex forms feel less overwhelming. While HTML alone doesn’t support multi-step functionality directly, you can use the <code>&lt;fieldset&gt;</code> and <code>&lt;legend&gt;</code> elements to organize form sections visually.</p>
<p><strong>Example of a Multi-step Form:</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">fieldset</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">legend</span>&gt;</span>Step 1: Personal Information<span class="hljs-tag">&lt;/<span class="hljs-name">legend</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"name"</span>&gt;</span>Name:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"name"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"name"</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"email"</span>&gt;</span>Email:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"email"</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"document.getElementById('step2').style.display='block';"</span>&gt;</span>Next<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">fieldset</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">fieldset</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"step2"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"display:none;"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">legend</span>&gt;</span>Step 2: Address Details<span class="hljs-tag">&lt;/<span class="hljs-name">legend</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"address"</span>&gt;</span>Address:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"address"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"address"</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"city"</span>&gt;</span>City:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"city"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"city"</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"document.getElementById('step2').style.display='none';"</span>&gt;</span>Previous<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">fieldset</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/JjQvVzv" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p><strong>How it works:</strong></p>
<ul>
<li><p><strong>Fieldsets</strong>: The <code>&lt;fieldset&gt;</code> element groups related fields together and helps visually separate different sections of the form.</p>
</li>
<li><p><strong>Legends</strong>: The <code>&lt;legend&gt;</code> element provides a title for each section.</p>
</li>
<li><p><strong>Buttons</strong>: Use <code>&lt;button&gt;</code> elements with <code>onclick</code> attributes to show or hide sections. In a real-world scenario, you’d use JavaScript for better control, but this example demonstrates the concept.</p>
</li>
</ul>
<p><strong>Conditional Inputs</strong> allow users to fill out additional fields based on previous choices. While HTML alone doesn’t support this functionality natively, you can use checkboxes and radio buttons creatively to show or hide sections of the form.</p>
<p><strong>Example of Conditional Inputs:</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"subscribe"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"subscribe"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"subscribe"</span>&gt;</span>
    Subscribe to newsletter
  <span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"newsletterDetails"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"display:none;"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"frequency"</span>&gt;</span>Preferred Frequency:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">select</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"frequency"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"frequency"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"weekly"</span>&gt;</span>Weekly<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"monthly"</span>&gt;</span>Monthly<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">select</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
    <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'subscribe'</span>).addEventListener(<span class="hljs-string">'change'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
      <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'newsletterDetails'</span>).style.display = <span class="hljs-built_in">this</span>.checked ? <span class="hljs-string">'block'</span> : <span class="hljs-string">'none'</span>;
    });
  </span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/VwJxNRV" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p><strong>How it works:</strong></p>
<ul>
<li><p><strong>Checkboxes</strong>: The checkbox lets users opt into additional options.</p>
</li>
<li><p><strong>Conditional Display</strong>: The <code>&lt;div&gt;</code> with <code>id="newsletterDetails"</code> shows or hides based on the checkbox state. While the JavaScript is necessary to handle the condition, HTML alone provides the structure and initial display.</p>
</li>
</ul>
<h4 id="heading-simulating-dynamic-content-updates"><strong>Simulating Dynamic Content Updates</strong></h4>
<p>Simulating dynamic content updates involves creating sections of a webpage that can change based on user input. While full dynamic updates require JavaScript, you can use HTML and CSS to simulate these changes.</p>
<p><strong>Example of Simulated Dynamic Content Updates:</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"view"</span>&gt;</span>Choose a view:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">select</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"view"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"view"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"overview"</span>&gt;</span>Overview<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"details"</span>&gt;</span>Details<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">select</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"overviewContent"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Overview<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is the overview content.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"detailsContent"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"display:none;"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Details<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is the detailed content.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
    <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'view'</span>).addEventListener(<span class="hljs-string">'change'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
      <span class="hljs-keyword">var</span> selectedView = <span class="hljs-built_in">this</span>.value;
      <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'overviewContent'</span>).style.display = selectedView === <span class="hljs-string">'overview'</span> ? <span class="hljs-string">'block'</span> : <span class="hljs-string">'none'</span>;
      <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'detailsContent'</span>).style.display = selectedView === <span class="hljs-string">'details'</span> ? <span class="hljs-string">'block'</span> : <span class="hljs-string">'none'</span>;
    });
  </span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/rNEvbbz" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p><strong>How it works:</strong></p>
<ul>
<li><p><strong>Dropdown Menu</strong>: A <code>&lt;select&gt;</code> element allows users to choose between different views.</p>
</li>
<li><p><strong>Content Sections</strong>: The content sections are shown or hidden based on the user’s selection. This simulation relies on JavaScript to handle the visibility, but the structure is set up with HTML.</p>
</li>
</ul>
<p>While true dynamic updates are best handled with JavaScript, these examples show how you can create the illusion of interactivity using HTML and CSS alone.</p>
<h2 id="heading-html-only-interactive-techniques"><strong>HTML-Only Interactive Techniques</strong></h2>
<p>While JavaScript is commonly used for creating interactive features, HTML itself offers several techniques to achieve interactivity. In this section, we'll explore four HTML-only techniques: using the <code>target</code> attribute for page-level interactions, emulating modal dialogs, creating tooltips, and building interactive image maps. Each technique highlights how HTML can be used creatively to add interactive elements to your webpages.</p>
<h3 id="heading-how-to-use-the-target-attribute-for-page-level-interactions"><strong>How to Use the</strong> <code>target</code> Attribute for Page-level Interactions</h3>
<p>The <code>target</code> attribute allows you to control where a linked document will open. This can be used to create interactive experiences that involve navigating between different sections of a page or opening new pages within the same window or tab.</p>
<p><strong>Example of Using the</strong> <code>target</code> Attribute:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#section1"</span> <span class="hljs-attr">target</span>=<span class="hljs-string">"_self"</span>&gt;</span>Go to Section 1<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#section2"</span> <span class="hljs-attr">target</span>=<span class="hljs-string">"_self"</span>&gt;</span>Go to Section 2<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"section1"</span>&gt;</span>Section 1<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Content for Section 1...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"section2"</span>&gt;</span>Section 2<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Content for Section 2...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/NWZMmVG" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p><strong>How it works:</strong></p>
<ul>
<li><p><strong>Anchors (</strong><code>&lt;a&gt;</code> elements): These links navigate to different parts of the same page or other pages. The <code>href</code> attribute points to the target location.</p>
</li>
<li><p><code>target="_self"</code>: This attribute ensures the link opens in the same window or tab, which is the default behavior. You can use other values like <code>_blank</code> to open links in a new tab or window.</p>
</li>
</ul>
<p>Using the target attribute allows you to control how users interact with links and navigate your site, enhancing the user experience without relying on JavaScript.</p>
<h3 id="heading-how-to-emulate-modal-dialogs"><strong>How to Emulate Modal Dialogs</strong></h3>
<p>Modal dialogs are often used to display important information or prompts that require user interaction before proceeding. While creating true modals typically involves JavaScript, you can use HTML and CSS to simulate modal dialogs.</p>
<p><strong>Example of Emulating a Modal Dialog:</strong></p>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!-- Hidden checkbox to toggle the modal --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"modal-toggle"</span>&gt;</span>

    <span class="hljs-comment">&lt;!-- Button to open the modal --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"modal-toggle"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"cursor: pointer;"</span>&gt;</span>Open Modal<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>

    <span class="hljs-comment">&lt;!-- The Modal --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"modal"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"modal-content"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"close"</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"document.getElementById('modal-toggle').click();"</span>&gt;</span><span class="hljs-symbol">&amp;times;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Modal Title<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is a simple modal dialog without JavaScript!<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
<span class="hljs-comment">/* Hide the checkbox */</span>
<span class="hljs-selector-id">#modal-toggle</span> {
    <span class="hljs-attribute">display</span>: none;
}

<span class="hljs-comment">/* The modal background */</span>
<span class="hljs-selector-class">.modal</span> {
    <span class="hljs-attribute">display</span>: none;
    <span class="hljs-attribute">position</span>: fixed;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0.5</span>);
    <span class="hljs-attribute">justify-content</span>: center;
    <span class="hljs-attribute">align-items</span>: center;
}

<span class="hljs-comment">/* Show the modal when the checkbox is checked */</span>
<span class="hljs-selector-id">#modal-toggle</span><span class="hljs-selector-pseudo">:checked</span> ~ <span class="hljs-selector-class">.modal</span> {
    <span class="hljs-attribute">display</span>: flex;
}

<span class="hljs-comment">/* The modal content */</span>
<span class="hljs-selector-class">.modal-content</span> {
    <span class="hljs-attribute">background-color</span>: white;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span>;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">5px</span>;
    <span class="hljs-attribute">max-width</span>: <span class="hljs-number">500px</span>;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">text-align</span>: center;
    <span class="hljs-attribute">position</span>: relative;
}

<span class="hljs-comment">/* The close button */</span>
<span class="hljs-selector-class">.close</span> {
    <span class="hljs-attribute">position</span>: absolute;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">10px</span>;
    <span class="hljs-attribute">right</span>: <span class="hljs-number">10px</span>;
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">24px</span>;
    <span class="hljs-attribute">text-decoration</span>: none;
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#333</span>;
    <span class="hljs-attribute">cursor</span>: pointer;
}

<span class="hljs-selector-class">.close</span><span class="hljs-selector-pseudo">:hover</span> {
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#ff4c4c</span>;
}

</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/poXVBmN" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p><strong>How it works:</strong></p>
<ul>
<li><p><strong>Checkbox (</strong><code>&lt;input type="checkbox"&gt;</code>): Used to control the visibility of the modal.</p>
</li>
<li><p><strong>Labels</strong>: The labels act as buttons to open and close the modal. Clicking the "Open Modal" label checks the checkbox, which makes the modal visible. Clicking the "Close" label unchecks the checkbox and hides the modal.</p>
</li>
<li><p><strong>CSS</strong>: Controls the appearance and positioning of the modal and its overlay.</p>
</li>
</ul>
<p>This approach allows you to create a modal-like effect with HTML and CSS alone, providing a user-friendly way to present information or options.</p>
<h3 id="heading-how-to-create-html-only-tooltips"><strong>How to Create HTML-only Tooltips</strong></h3>
<p>Tooltips provide additional information when a user hovers over an element. While JavaScript can enhance tooltips, you can create basic tooltips using just HTML and CSS.</p>
<p><strong>Example of Creating Tooltips:</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"tooltip"</span>&gt;</span>
  Hover over me
  <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"tooltip-text"</span>&gt;</span>Tooltip text<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
  <span class="hljs-selector-class">.tooltip</span> {
    <span class="hljs-attribute">position</span>: relative;
    <span class="hljs-attribute">display</span>: inline-block;
    <span class="hljs-attribute">cursor</span>: pointer;
  }
  <span class="hljs-selector-class">.tooltip</span> <span class="hljs-selector-class">.tooltip-text</span> {
    <span class="hljs-attribute">visibility</span>: hidden;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">120px</span>;
    <span class="hljs-attribute">background-color</span>: black;
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#fff</span>;
    <span class="hljs-attribute">text-align</span>: center;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">5px</span>;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">5px</span> <span class="hljs-number">0</span>;
    <span class="hljs-attribute">position</span>: absolute;
    <span class="hljs-attribute">z-index</span>: <span class="hljs-number">1</span>;
    <span class="hljs-attribute">bottom</span>: <span class="hljs-number">125%</span>; <span class="hljs-comment">/* Position above the tooltip trigger */</span>
    <span class="hljs-attribute">left</span>: <span class="hljs-number">50%</span>;
    <span class="hljs-attribute">margin-left</span>: -<span class="hljs-number">60px</span>;
    <span class="hljs-attribute">opacity</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">transition</span>: opacity <span class="hljs-number">0.3s</span>;
  }
  <span class="hljs-selector-class">.tooltip</span><span class="hljs-selector-pseudo">:hover</span> <span class="hljs-selector-class">.tooltip-text</span> {
    <span class="hljs-attribute">visibility</span>: visible;
    <span class="hljs-attribute">opacity</span>: <span class="hljs-number">1</span>;
  }
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/MWMXyoO" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p><strong>How it works:</strong></p>
<ul>
<li><p><strong>Tooltip Container</strong>: The <code>&lt;div class="tooltip"&gt;</code> contains the text that triggers the tooltip and the tooltip text itself.</p>
</li>
<li><p><strong>Tooltip Text</strong>: The <code>&lt;span class="tooltip-text"&gt;</code> is hidden by default and only becomes visible when the user hovers over the tooltip container.</p>
</li>
<li><p><strong>CSS</strong>: Uses <code>visibility</code> and <code>opacity</code> to show and hide the tooltip, with a transition effect for smooth appearance.</p>
</li>
</ul>
<p>This method allows you to add helpful hints or extra information to your webpage without needing JavaScript.</p>
<h3 id="heading-how-to-build-interactive-image-maps"><strong>How to Build Interactive Image Maps</strong></h3>
<p>Image maps enable you to create clickable areas on an image, allowing users to interact with different parts of an image. HTML’s <code>&lt;map&gt;</code> and <code>&lt;area&gt;</code> elements are used to define these clickable regions.</p>
<p><strong>Example of Building an Image Map:</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"map-image.jpg"</span> <span class="hljs-attr">usemap</span>=<span class="hljs-string">"#image-map"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Map Image"</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">map</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"image-map"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">area</span> <span class="hljs-attr">shape</span>=<span class="hljs-string">"rect"</span> <span class="hljs-attr">coords</span>=<span class="hljs-string">"34,44,270,350"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"page1.html"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Region 1"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">area</span> <span class="hljs-attr">shape</span>=<span class="hljs-string">"circle"</span> <span class="hljs-attr">coords</span>=<span class="hljs-string">"130,136,60"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"page2.html"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Region 2"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">area</span> <span class="hljs-attr">shape</span>=<span class="hljs-string">"poly"</span> <span class="hljs-attr">coords</span>=<span class="hljs-string">"300,50,400,150,350,200"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"page3.html"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Region 3"</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">map</span>&gt;</span>
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/joanayebola/embed/KKjezQv" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<p><strong>How it works:</strong></p>
<ul>
<li><p><strong>Image</strong>: The <code>&lt;img&gt;</code> tag includes the <code>usemap</code> attribute, which links to the <code>&lt;map&gt;</code> element.</p>
</li>
<li><p><strong>Map and Areas</strong>: The <code>&lt;map&gt;</code> element contains one or more <code>&lt;area&gt;</code> elements. Each <code>&lt;area&gt;</code> defines a clickable region on the image.</p>
<ul>
<li><p><code>shape="rect"</code>: Defines a rectangular area with specified coordinates.</p>
</li>
<li><p><code>shape="circle"</code>: Defines a circular area with a center and radius.</p>
</li>
</ul>
</li>
</ul>
<p>Image maps allow you to create interactive images with different regions that lead to various pages or actions, adding an extra layer of engagement to your prototypes.</p>
<h2 id="heading-design-tips-for-html-only-prototypes"><strong>Design Tips for HTML-Only Prototypes</strong></h2>
<p>Designing HTML-only prototypes involves focusing on both usability and performance. While HTML alone provides a solid foundation for interactive elements, it’s essential to ensure that your prototypes are accessible, fast, and efficient. This section offers tips on making your HTML-only prototypes more effective, covering accessibility, performance, and limitations.</p>
<h3 id="heading-make-sure-your-prototype-is-accessible"><strong>Make Sure Your Prototype is Accessible</strong></h3>
<p>Accessibility ensures that your prototypes can be used by everyone, including those with disabilities. By adhering to accessibility principles, you improve the user experience for all users and make your prototypes more inclusive.</p>
<h4 id="heading-keyboard-friendly-navigation"><strong>Keyboard-friendly Navigation</strong></h4>
<p>Many users rely on keyboards for navigation, so it’s crucial to ensure that all interactive elements can be accessed and used via keyboard alone.</p>
<p><strong>Tips for Keyboard-Friendly Navigation:</strong></p>
<ul>
<li><p><strong>Use Semantic HTML</strong>: Proper use of HTML elements like <code>&lt;button&gt;</code>, <code>&lt;a&gt;</code>, and <code>&lt;input&gt;</code> helps with keyboard navigation. These elements are naturally focusable and keyboard-navigable.</p>
</li>
<li><p><strong>Tab Index</strong>: The <code>tabindex</code> attribute can be used to manage the order of focusable elements. For example, <code>tabindex="0"</code> allows an element to be focusable, while negative values like <code>tabindex="-1"</code> remove an element from the tab order.</p>
</li>
<li><p><strong>Visible Focus Indicators</strong>: Ensure that focus indicators (like outlines) are visible when navigating with the keyboard. This helps users see which element is currently in focus.</p>
</li>
</ul>
<p><strong>Example:</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">tabindex</span>=<span class="hljs-string">"0"</span>&gt;</span>Click Me<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#section1"</span> <span class="hljs-attr">tabindex</span>=<span class="hljs-string">"0"</span>&gt;</span>Go to Section 1<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">tabindex</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Enter text here"</span>&gt;</span>
</code></pre>
<h4 id="heading-screen-reader-support"><strong>Screen Reader Support</strong></h4>
<p>Screen readers help visually impaired users navigate your site. To ensure that your prototypes are accessible to these users, include relevant ARIA (Accessible Rich Internet Applications) attributes and use semantic HTML.</p>
<p><strong>Tips for Screen Reader Support:</strong></p>
<ul>
<li><p><strong>Alt Text</strong>: Use the <code>alt</code> attribute for images to provide descriptive text for screen readers.</p>
</li>
<li><p><strong>ARIA Roles and Labels</strong>: Use ARIA roles and labels to enhance the accessibility of interactive elements. For example, <code>role="button"</code> can be used for clickable elements that are not inherently buttons.</p>
</li>
<li><p><strong>Descriptive Labels</strong>: Ensure that form inputs and interactive elements have clear and descriptive labels.</p>
</li>
</ul>
<p><strong>Example:</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"logo.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Company Logo"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">aria-label</span>=<span class="hljs-string">"Close"</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"closeModal()"</span>&gt;</span>X<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<p>Incorporating these practices makes your prototypes more navigable and usable for individuals with disabilities.</p>
<h3 id="heading-the-speed-and-simplicity-of-html-only-prototypes"><strong>The Speed and Simplicity of HTML-only Prototypes</strong></h3>
<p>HTML-only prototypes are often faster to load and simpler to maintain due to their reliance on minimal resources. These benefits contribute to a more efficient user experience.</p>
<h4 id="heading-faster-loading"><strong>Faster Loading</strong></h4>
<p>HTML-only prototypes typically load faster because they don’t rely on external scripts or complex interactions that can slow down performance. The simplicity of HTML means fewer resources need to be processed by the browser.</p>
<p><strong>Benefits:</strong></p>
<ul>
<li><p><strong>Reduced Load Times</strong>: Without JavaScript or complex CSS, the browser can render the content more quickly.</p>
</li>
<li><p><strong>Improved Performance</strong>: Fewer resources mean less strain on the client’s device, resulting in smoother performance.</p>
</li>
</ul>
<h4 id="heading-lower-resource-use"><strong>Lower Resource Use</strong></h4>
<p>Using HTML alone minimizes resource consumption. Without JavaScript or heavy CSS, your prototype consumes less memory and processing power.</p>
<p><strong>Benefits:</strong></p>
<ul>
<li><p><strong>Lower Memory Usage</strong>: Less reliance on external scripts means reduced memory footprint.</p>
</li>
<li><p><strong>Less CPU Usage</strong>: Simplified interactions reduce the need for extensive computation, leading to lower CPU usage.</p>
</li>
</ul>
<p>These aspects contribute to a more efficient and responsive user experience, especially important for users on slower connections or less powerful devices.</p>
<h3 id="heading-where-html-falls-short"><strong>Where HTML Falls Short</strong></h3>
<p>HTML is great for building interactive prototypes, but it has some limits. Knowing these limits helps you decide when to add other technologies.</p>
<h4 id="heading-no-complex-logic"><strong>No Complex Logic</strong></h4>
<p>HTML alone is limited in handling complex logic and dynamic interactions. For example, conditions, loops, or advanced calculations require JavaScript.</p>
<p><strong>Limitations:</strong></p>
<ul>
<li><p><strong>Conditional Logic</strong>: HTML cannot perform actions based on complex conditions or states.</p>
</li>
<li><p><strong>Dynamic Updates</strong>: Changes to the page content or structure based on user input often require JavaScript.</p>
</li>
</ul>
<p><strong>Example Limitation:</strong></p>
<ul>
<li><strong>Interactive Forms</strong>: Complex forms with dynamic fields or conditional sections generally need JavaScript to manage the logic and interactions effectively.</li>
</ul>
<h4 id="heading-difficulties-with-more-advanced-interactions"><strong>Difficulties with More Advanced Interactions</strong></h4>
<p>Some interactions, such as real-time updates or complex animations, are challenging to achieve with HTML alone. While CSS can handle some animations, more advanced interactions often require scripting.</p>
<p><strong>Limitations:</strong></p>
<ul>
<li><p><strong>Real-time Data</strong>: Updating content in real time based on user actions or external data sources is typically not possible with HTML alone.</p>
</li>
<li><p><strong>Complex Animations</strong>: Advanced animations and transitions usually require JavaScript or CSS animations.</p>
</li>
</ul>
<p><strong>Example Limitation:</strong></p>
<ul>
<li><strong>Live Content Updates</strong>: HTML cannot fetch or update content dynamically without JavaScript or server-side solutions.</li>
</ul>
<p>Recognizing these limitations helps you balance the use of HTML with other technologies when needed to achieve your desired functionality.</p>
<h2 id="heading-when-to-use-html-only-prototypes"><strong>When to Use HTML-Only Prototypes</strong></h2>
<p>HTML-only prototypes can be a powerful tool in your design toolkit, especially when simplicity and performance are key.</p>
<p>Understanding when to use HTML-only solutions, considering your audience, and knowing how to blend HTML with JavaScript can help you create effective prototypes that meet your project needs.</p>
<h3 id="heading-when-html-only-is-the-right-choice"><strong>When HTML-only is the Right Choice</strong></h3>
<p>HTML-only prototypes are particularly useful in specific scenarios where their simplicity and efficiency shine. Here are some situations where using HTML-only prototypes makes sense:</p>
<p><strong>1. Simple Forms and Surveys:</strong> When you need to create basic forms or surveys to collect user input, HTML forms with standard input elements can be used effectively. These prototypes are easy to set up and provide a straightforward way for users to submit information.</p>
<p><strong>Example:</strong></p>
<ul>
<li><p>A contact form on a website.</p>
</li>
<li><p>A quick survey to gather feedback from users.</p>
</li>
</ul>
<p><strong>2. Static Information Display:</strong> For displaying static content or information, HTML is sufficient. Prototypes that focus on showcasing content without requiring dynamic interactions are ideal candidates for HTML-only design.</p>
<p><strong>Example:</strong></p>
<ul>
<li><p>An informational landing page.</p>
</li>
<li><p>A product details page that provides static information.</p>
</li>
</ul>
<p><strong>3. Prototyping Early Concepts:</strong> When prototyping early concepts or initial designs, HTML-only prototypes can help quickly visualize and test ideas without the need for complex scripting. This approach allows you to iterate rapidly and focus on layout and structure.</p>
<p><strong>Example:</strong></p>
<ul>
<li><p>Wireframes or mockups of a new feature.</p>
</li>
<li><p>Early-stage designs for a website or application.</p>
</li>
</ul>
<p><strong>4. Performance Considerations:</strong> For situations where performance is critical and you need to ensure fast loading times and low resource usage, HTML-only prototypes can be advantageous. They eliminate the overhead of additional scripts and reduce processing demands.</p>
<p><strong>Example:</strong></p>
<ul>
<li><p>A mobile landing page with minimal resources.</p>
</li>
<li><p>A lightweight information page with fast load times.</p>
</li>
</ul>
<p><strong>5. Accessibility and Simplicity:</strong> When designing for accessibility and simplicity, HTML provides a strong foundation. Using semantic HTML and built-in attributes ensures that your prototypes are accessible to users with disabilities.</p>
<p><strong>Example:</strong></p>
<ul>
<li><p>An accessible form with clear labels and input fields.</p>
</li>
<li><p>A simple navigation menu with clear, focusable links.</p>
</li>
</ul>
<h3 id="heading-understanding-your-audience"><strong>Understanding Your Audience</strong></h3>
<p>Knowing your audience is crucial when deciding whether to use HTML-only prototypes. Consider the following factors:</p>
<p><strong>1. User Needs and Expectations:</strong> Understand what your users need and expect from the prototype. If your audience is looking for simple, straightforward interactions, HTML-only may be sufficient. For more complex interactions or dynamic content, consider integrating JavaScript.</p>
<p><strong>Example:</strong></p>
<ul>
<li><p>Users who need a basic contact form may be satisfied with an HTML-only solution.</p>
</li>
<li><p>Users who expect interactive features or real-time updates might require a combination of HTML and JavaScript.</p>
</li>
</ul>
<p><strong>2. Technical Constraints:</strong> Consider the technical constraints of your audience’s devices and browsers. HTML-only prototypes generally perform well across various devices and browsers, making them suitable for diverse audiences.</p>
<p><strong>Example:</strong></p>
<ul>
<li>A prototype for users with older devices or limited internet connectivity may benefit from the simplicity of HTML-only design.</li>
</ul>
<p><strong>3. User Expertise:</strong> Assess the technical expertise of your audience. If they are not familiar with complex interactions or scripting, HTML-only prototypes can provide a more accessible and user-friendly experience.</p>
<p><strong>Example:</strong></p>
<ul>
<li>A prototype for a non-technical audience may prioritize simplicity and ease of use with HTML-only design.</li>
</ul>
<p><strong>4. Feedback and Iteration:</strong> Gather feedback from users to understand how they interact with your prototype. If users find HTML-only prototypes sufficient for their needs, you can continue with this approach. If more advanced features are requested, consider integrating additional technologies.</p>
<p><strong>Example:</strong></p>
<ul>
<li>Collect user feedback on a basic form and decide if additional features or interactions are needed.</li>
</ul>
<h3 id="heading-mixing-html-and-javascript"><strong>Mixing HTML and JavaScript</strong></h3>
<p>While HTML-only prototypes have their strengths, combining HTML with JavaScript can enhance functionality and provide a richer user experience.</p>
<p>Here’s when and how to mix HTML and JavaScript effectively:</p>
<p><strong>1. Adding Dynamic Interactions:</strong> When your prototype requires dynamic interactions, such as real-time updates or complex logic, JavaScript can complement HTML to provide these features.</p>
<p><strong>Example:</strong></p>
<ul>
<li><p>A form that updates in real time based on user input.</p>
</li>
<li><p>An interactive map with zoom and filter capabilities.</p>
</li>
</ul>
<p><strong>2. Enhancing User Experience:</strong> JavaScript can be used to improve the user experience by adding interactive elements like modals, carousels, or animations that HTML alone cannot achieve.</p>
<p><strong>Example:</strong></p>
<ul>
<li><p>A modal dialog that opens and closes based on user actions.</p>
</li>
<li><p>A carousel that allows users to navigate through images or content.</p>
</li>
</ul>
<p><strong>3. Handling Complex Logic:</strong> For prototypes involving complex calculations, conditional logic, or data manipulation, JavaScript can handle these requirements more effectively than HTML alone.</p>
<p><strong>Example:</strong></p>
<ul>
<li><p>A calculator that performs complex calculations based on user input.</p>
</li>
<li><p>A dynamic form that adjusts fields based on previous selections.</p>
</li>
</ul>
<p><strong>4. Iterating and Testing:</strong> Start with an HTML-only prototype to establish the basic structure and layout. Once you have a clear understanding of the design, integrate JavaScript to add interactivity and test the enhanced functionality.</p>
<p><strong>Example:</strong></p>
<ul>
<li>Begin with a static prototype of a feature and then add JavaScript to refine and test interactive elements.</li>
</ul>
<p><strong>5. Balancing Complexity:</strong> Use JavaScript to enhance the prototype where necessary, but avoid overcomplicating the design. Maintain a balance between simplicity and functionality to ensure the prototype remains easy to use and understand.</p>
<p><strong>Example:</strong></p>
<ul>
<li>Implement JavaScript for essential interactions but keep the overall design and layout straightforward.</li>
</ul>
<h3 id="heading-conclusion"><strong>Conclusion</strong></h3>
<p>HTML-only prototypes are a great choice for many design tasks because they are simple and quick to build. They work well for basic interactions like forms and displaying information.</p>
<p>HTML alone is powerful for straightforward designs. However, if you need more advanced features or dynamic interactions, adding JavaScript can help. Mixing HTML with JavaScript lets you enhance your prototypes when needed.</p>
<p>In summary, HTML-only prototypes offer speed, accessibility, and ease of use. Understanding when to use HTML by itself and when to add other tools ensures that your prototypes are both effective and user-friendly.</p>
<p>That's all for this article! If you'd like to continue the conversation or have questions, suggestions, or feedback, feel free to reach out to connect with me on <a target="_blank" href="https://ng.linkedin.com/in/joan-ayebola">LinkedIn</a>. If you enjoyed this content, consider <a target="_blank" href="https://www.buymeacoffee.com/joanayebola">buying me a coffee</a> to support the creation of more developer-friendly contents.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Server-Side Rendering in Next.js Apps for Better SEO ]]>
                </title>
                <description>
                    <![CDATA[ Server-side rendering (SSR) is a web development technique that can help improve your site's SEO. It does this by generating HTML content on the server in response to a user's request.  This approach contrasts with client-side rendering (CSR), where ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/server-side-rendering-in-next-js-for-improved-seo/</link>
                <guid isPermaLink="false">66c4c415bd556981b1bdc441</guid>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Next.js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ SEO ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Server side rendering ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Joan Ayebola ]]>
                </dc:creator>
                <pubDate>Wed, 17 Jul 2024 18:02:11 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/07/How-to-Use-Server-Side-Rendering-in-Next.js-Apps-for-Better-SEO-Cover-Image.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Server-side rendering (SSR) is a web development technique that can help improve your site's SEO. It does this by generating HTML content on the server in response to a user's request. </p>
<p>This approach contrasts with client-side rendering (CSR), where content is delivered as a basic HTML shell, and JavaScript fetches and displays data in the browser.</p>
<p>SSR offers significant SEO advantages, making it a perfect fit for Next.js, a popular React framework. Let's discuss how using SSR with Next.js can elevate your website's search engine visibility.</p>
<h3 id="heading-table-of-contents">Table of Contents</h3>
<ol>
<li><a class="post-section-overview" href="#heading-what-is-server-side-rendering">What is Server-Side Rendering</a>?</li>
<li><a class="post-section-overview" href="#heading-how-to-get-started-with-nextjs-and-ssr">How to Get Started with Next.js and SSR</a></li>
<li><a class="post-section-overview" href="#heading-how-nextjs-enables-server-side-rendering">How Next.js Enables Server-side Rendering</a></li>
<li><a class="post-section-overview" href="#heading-data-fetching-with-getstaticprops-and-getserversideprops">Data Fetching with getStaticProps and getServerSideProps</a></li>
<li><a class="post-section-overview" href="#heading-benefits-of-ssr-for-seo-with-nextjs-and-how-to-optimize">Benefits of SSR for SEO with Next.js and How to Optimize</a></li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></li>
</ol>
<h2 id="heading-what-is-server-side-rendering">What is Server-Side Rendering?</h2>
<p>Server-side rendering (SSR) is a technique in web development where the web server generates the complete HTML content of a web page before sending it to the user's browser. </p>
<p>This is unlike client-side rendering (CSR), where the browser downloads a basic HTML structure and then uses JavaScript to fetch and display the content.</p>
<h2 id="heading-how-to-get-started-with-nextjs-and-ssr">How to Get Started with Next.js and SSR</h2>
<p>Getting started with Next.js and server-side rendering (SSR) involves a few steps. Here's a step-by-step guide to help you set up a Next.js project and implement SSR.</p>
<h3 id="heading-step-1-install-nextjs">Step 1: Install Next.js</h3>
<p>First, you need to install Next.js. You can do this using <code>create-next-app</code>, which sets up a new Next.js project with a default configuration. Run the following command in your terminal:</p>
<pre><code class="lang-bash">npx create-next-app my-next-app
<span class="hljs-built_in">cd</span> my-next-app
npm run dev
</code></pre>
<p>This command creates a new Next.js application in a folder called <code>my-next-app</code> and starts the development server.</p>
<h3 id="heading-step-2-understand-the-project-structure">Step 2: Understand the Project Structure</h3>
<p>Next.js organizes the project with some default folders and files:</p>
<ul>
<li><strong><code>pages/</code></strong>: This folder contains all the pages of your application. Each file represents a route in your app.</li>
<li><strong><code>public/</code></strong>: Static assets like images can be placed here.</li>
<li><strong><code>styles/</code></strong>: Contains CSS files for styling your application.</li>
</ul>
<h3 id="heading-step-3-create-a-simple-page-with-ssr">Step 3: Create a Simple Page with SSR</h3>
<p>Now, let's create a simple page that uses SSR.</p>
<p>Create a new file <code>pages/index.js</code>:</p>
<pre><code class="lang-jsx"><span class="hljs-comment">// pages/index.js</span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-keyword">const</span> Home = <span class="hljs-function">(<span class="hljs-params">{ data }</span>) =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Welcome to Next.js with SSR<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Data fetched from the server: {data.message}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getServerSideProps</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-comment">// Fetch data from an API or other sources</span>
  <span class="hljs-keyword">const</span> res = <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">'https://api.example.com/data'</span>);
  <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> res.json();

  <span class="hljs-comment">// Return the data as props to the Home component</span>
  <span class="hljs-keyword">return</span> {
    <span class="hljs-attr">props</span>: {
      data,
    },
  };
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Home;
</code></pre>
<p>Let's discuss this code in some detail. For the <code>home</code> component:</p>
<ul>
<li>The <code>Home</code> component is a functional component that accepts <code>props</code>.</li>
<li>The <code>data</code> prop contains the data fetched from the server.</li>
<li>Inside the component, we render a welcome message and the fetched data.</li>
</ul>
<p>The <code>getServerSideProps</code> function:</p>
<ul>
<li>This function is exported from the <code>pages/index.js</code> file.</li>
<li>It executes on the server for each request to this page.</li>
<li>Inside this function, you can perform asynchronous operations such as fetching data from an external API.</li>
<li>The fetched data is returned as an object with a <code>props</code> key. This object will be passed to the <code>Home</code> component as props.</li>
</ul>
<p>You can add error handling to the <code>getServerSideProps</code> function to manage any issues that might arise during data fetching. Here's an example:</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">export</span> <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getServerSideProps</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">try</span> {
    <span class="hljs-keyword">const</span> res = <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">'https://api.example.com/data'</span>);
    <span class="hljs-keyword">if</span> (!res.ok) {
      <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'Failed to fetch data'</span>);
    }
    <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> res.json();
    <span class="hljs-keyword">return</span> {
      <span class="hljs-attr">props</span>: {
        data,
      },
    };
  } <span class="hljs-keyword">catch</span> (error) {
    <span class="hljs-built_in">console</span>.error(error);
    <span class="hljs-keyword">return</span> {
      <span class="hljs-attr">props</span>: {
        <span class="hljs-attr">data</span>: { <span class="hljs-attr">message</span>: <span class="hljs-string">'Error fetching data'</span> },
      },
    };
  }
}
</code></pre>
<h4 id="heading-step-4-run-the-application">Step 4: Run the Application</h4>
<p>Start your development server if it's not already running:</p>
<pre><code class="lang-bash">npm run dev
</code></pre>
<p>Open your browser and go to <code>http://localhost:3000</code>. You should see the message fetched from the API displayed on the page.</p>
<h2 id="heading-how-nextjs-enables-server-side-rendering">How Next.js Enables Server-Side Rendering</h2>
<p>Next.js provides a seamless way to enable SSR and Static Site Generation (SSG). It pre-renders every page by default. Depending on the use case, you can choose between SSR and SSG:</p>
<ul>
<li><strong>Server-Side Rendering (SSR)</strong>: Pages are rendered on each request.</li>
<li><strong>Static Site Generation (SSG)</strong>: Pages are generated at build time.</li>
</ul>
<p>Next.js determines which rendering method to use based on the functions you implement in your page components (<code>getStaticProps</code> and <code>getServerSideProps</code>).</p>
<h3 id="heading-nextjs-page-components">Next.js Page Components</h3>
<p>Next.js uses the <code>pages/</code> directory to define routes. Each file in this directory corresponds to a route in your application.</p>
<ul>
<li><code>pages/index.js</code> → <code>/</code></li>
<li><code>pages/about.js</code> → <code>/about</code></li>
<li><code>pages/posts/[id].js</code> → <code>/posts/:id</code></li>
</ul>
<p>Here's a basic example of a page component:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// pages/index.js</span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-keyword">const</span> Home = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Welcome to Next.js<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is the home page.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Home;
</code></pre>
<h3 id="heading-data-fetching-with-getstaticprops-and-getserversideprops">Data Fetching with <code>getStaticProps</code> and <code>getServerSideProps</code></h3>
<p><code>getStaticProps</code> is used for static generation. It runs at build time and allows you to fetch data and pass it to your page as props. Use this for data that doesn't change often.</p>
<p>Example:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// pages/index.js</span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-keyword">const</span> Home = <span class="hljs-function">(<span class="hljs-params">{ posts }</span>) =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Blog Posts<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
        {posts.map(post =&gt; (
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{post.id}</span>&gt;</span>{post.title}<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        ))}
      <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};

<span class="hljs-comment">// This function runs at build time</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getStaticProps</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-comment">// Fetch data from an API</span>
  <span class="hljs-keyword">const</span> res = <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">'https://jsonplaceholder.typicode.com/posts'</span>);
  <span class="hljs-keyword">const</span> posts = <span class="hljs-keyword">await</span> res.json();

  <span class="hljs-keyword">return</span> {
    <span class="hljs-attr">props</span>: {
      posts,
    },
  };
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Home;
</code></pre>
<p><code>getServerSideProps</code> is used for server-side rendering. It runs on every request and allows you to fetch data at request time.</p>
<p>Example:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// pages/index.js</span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-keyword">const</span> Home = <span class="hljs-function">(<span class="hljs-params">{ data }</span>) =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Server-Side Rendering with Next.js<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Data fetched from the server: {data.message}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};

<span class="hljs-comment">// This function runs on every request</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getServerSideProps</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-comment">// Fetch data from an external API</span>
  <span class="hljs-keyword">const</span> res = <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">'https://api.example.com/data'</span>);
  <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> res.json();

  <span class="hljs-keyword">return</span> {
    <span class="hljs-attr">props</span>: {
      data,
    },
  };
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Home;
</code></pre>
<h2 id="heading-benefits-of-ssr-for-seo-with-nextjs-and-how-to-optimize">Benefits of SSR for SEO with Next.js and How to Optimize</h2>
<p>In this section, we will look at the main benefits of using SSR for SEO and give easy-to-follow tips on how to make the most of these benefits with your Next.js application.</p>
<h3 id="heading-1-improved-indexing-by-search-engines">1. Improved Indexing by Search Engines</h3>
<p>Client-side rendering (CSR) can cause issues with search engines struggling to index content properly since it is rendered in the user's browser using JavaScript. </p>
<p>SSR, however, renders content on the server before sending it to the user's browser, ensuring the HTML is complete and can be easily crawled and indexed by search engines.</p>
<p><strong>Use SSR for important pages:</strong> Ensure that key pages, such as landing pages, blog posts, and product pages, are rendered on the server to facilitate better indexing.</p>
<p>Example – Using SSR for a blog post page:</p>
<pre><code class="lang-jsx"><span class="hljs-comment">// pages/blog/[id].js</span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { useRouter } <span class="hljs-keyword">from</span> <span class="hljs-string">'next/router'</span>;
<span class="hljs-keyword">import</span> Head <span class="hljs-keyword">from</span> <span class="hljs-string">'next/head'</span>;

<span class="hljs-keyword">const</span> BlogPost = <span class="hljs-function">(<span class="hljs-params">{ post }</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> router = useRouter();
  <span class="hljs-keyword">if</span> (router.isFallback) {
    <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Loading...<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>;
  }

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Head</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>{post.title}<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"description"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">{post.excerpt}</span> /&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">Head</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>{post.title}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>{post.content}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getServerSideProps</span>(<span class="hljs-params">{ params }</span>) </span>{
  <span class="hljs-keyword">const</span> res = <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">`https://api.example.com/posts/<span class="hljs-subst">${params.id}</span>`</span>);
  <span class="hljs-keyword">const</span> post = <span class="hljs-keyword">await</span> res.json();

  <span class="hljs-keyword">return</span> {
    <span class="hljs-attr">props</span>: {
      post,
    },
  };
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> BlogPost
</code></pre>
<ul>
<li><strong>BlogPost Component:</strong> This component displays a blog post. It uses <code>next/head</code> to manage meta tags, which are important for SEO.</li>
<li><strong>getServerSideProps Function:</strong> This function fetches data for the blog post from an API. It runs on the server for every request to this page, ensuring the content is ready for search engines to index when they crawl the page.</li>
</ul>
<h3 id="heading-2-faster-load-times">2. Faster Load Times</h3>
<p>Search engines like Google use page load speed as a ranking factor. SSR can improve initial load time because the server sends a fully rendered page to the browser, enhancing perceived performance and user experience.</p>
<p><strong>Optimize server response time:</strong> Ensure your server is optimized for quick responses. Use caching strategies to reduce server load.</p>
<p>Example – cache-control header for SSR:</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">export</span> <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getServerSideProps</span>(<span class="hljs-params">{ res }</span>) </span>{
  res.setHeader(<span class="hljs-string">'Cache-Control'</span>, <span class="hljs-string">'public, s-maxage=10, stale-while-revalidate=59'</span>);

  <span class="hljs-keyword">const</span> resData = <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">'https://api.example.com/data'</span>);
  <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> resData.json();

  <span class="hljs-keyword">return</span> {
    <span class="hljs-attr">props</span>: {
      data,
    },
  };
}
</code></pre>
<ul>
<li><strong><code>getServerSideProps</code> Function:</strong> This function sets cache-control headers to cache the response for 10 seconds and serve stale content while revalidating for 59 seconds. This improves server response time and page load speed, contributing to better SEO.</li>
</ul>
<h3 id="heading-3-improved-social-media-sharing">3. Improved Social Media Sharing</h3>
<p>When sharing links on social media, platforms like Facebook and Twitter scrape the URL content to generate previews. SSR ensures that necessary metadata is available in the initial HTML, resulting in better previews and increased click-through rates.</p>
<p><strong>Manage meta tags with <code>next/head</code>:</strong> Use the <code>next/head</code> component to add meta tags for social media and SEO.</p>
<p>Example – Adding meta tags to a page:</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">import</span> Head <span class="hljs-keyword">from</span> <span class="hljs-string">'next/head'</span>;

<span class="hljs-keyword">const</span> Page = <span class="hljs-function">(<span class="hljs-params">{ data }</span>) =&gt;</span> (
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">Head</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>{data.title}<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"description"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">{data.description}</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">property</span>=<span class="hljs-string">"og:title"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">{data.title}</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">property</span>=<span class="hljs-string">"og:description"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">{data.description}</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">property</span>=<span class="hljs-string">"og:image"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">{data.image}</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"twitter:card"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"summary_large_image"</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">Head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>{data.title}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>{data.content}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
);
</code></pre>
<ul>
<li><strong><code>Page</code> Component:</strong> This component uses <code>next/head</code> to add SEO meta tags, including Open Graph tags for social media previews. This ensures that when the page is shared, social media platforms can generate rich previews with the provided metadata.</li>
</ul>
<h3 id="heading-4-enhanced-user-experience">4. Enhanced User Experience</h3>
<p>A faster, more responsive website enhances the overall user experience, leading to longer visit durations and lower bounce rates. Both factors positively influence your SEO rankings.</p>
<p><strong>Pre-render pages with static generation (SSG) for less dynamic content:</strong> Use SSG for pages that don’t change often to reduce server load and improve performance.</p>
<p>Example – Using SSG for a static page:</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">export</span> <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getStaticProps</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> res = <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">'https://api.example.com/static-data'</span>);
  <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> res.json();

  <span class="hljs-keyword">return</span> {
    <span class="hljs-attr">props</span>: {
      data,
    },
    <span class="hljs-attr">revalidate</span>: <span class="hljs-number">10</span>, <span class="hljs-comment">// Revalidate at most once every 10 seconds</span>
  };
}

<span class="hljs-keyword">const</span> StaticPage = <span class="hljs-function">(<span class="hljs-params">{ data }</span>) =&gt;</span> (
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>{data.title}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>{data.content}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
);

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> StaticPage;
</code></pre>
<ul>
<li><strong><code>StaticPage</code> Component:</strong> This component displays static content fetched from an API.</li>
<li><strong><code>getStaticProps</code> Function:</strong> This function fetches data at build time and revalidates it every 10 seconds, ensuring the content is always fresh while reducing server load.</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Using server-side rendering and Next.js together is like giving your website an extra boost for search engines. With pre-built content for search engines and a smooth experience for visitors, your site is set up to be seen by more people naturally.  </p>
<p>This works great for any kind of website, from online stores to blogs. Next.js with SSR makes it easy to build a website that search engines love and users enjoy.</p>
<p>That's all for this article! If you'd like to continue the conversation or have questions, suggestions, or feedback, feel free to reach out to connect with me on <a target="_blank" href="https://ng.linkedin.com/in/joan-ayebola">LinkedIn</a>. And if you enjoyed this content, consider <a target="_blank" href="https://www.buymeacoffee.com/joanayebola">buying me a coffee</a> to support the creation of more developer-friendly contents.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Change Background Color with JavaScript – BG Color in JS and HTML ]]>
                </title>
                <description>
                    <![CDATA[ You can style elements with JavaScript using the element's style property. In this article, you'll learn how to change background color using JavaScript. Here's what the mini project you'll build looks like: In the image above, each button changes t... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-change-background-color-with-javascript/</link>
                <guid isPermaLink="false">667ee30607498d8fd2726201</guid>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ihechikara Abba ]]>
                </dc:creator>
                <pubDate>Fri, 28 Jun 2024 16:21:26 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/_t-l5FFH8VA/upload/7dac186ffa0ba7f32d72ccf06d1d5baf.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>You can style elements with JavaScript using the element's <code>style</code> property. In this article, you'll learn how to change background color using JavaScript.</p>
<p>Here's what the mini project you'll build looks like:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719585559018/23123259-9540-40c6-8f1f-3f444c154b2c.png" alt="image showing five buttons that each change the background color of a page" class="image--center mx-auto" width="940" height="434" loading="lazy"></p>
<p>In the image above, each button changes the background color of the page to a specific color.</p>
<p>You can get the starter files for the project <a target="_blank" href="https://github.com/ihechikara/change-bg-color-with-js/tree/main">here</a>.</p>
<p>There are five buttons in the <strong>index.html</strong> file, and each of them changes the background color to a specific value:</p>
<pre><code class="lang-xml"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"style.css"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Change BG Color With JS<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Choose background color<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Red<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Blue<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Green<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Yellow<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Reset<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
​
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"script.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
​
</code></pre>
<p>You won't be making any changes to the <strong>style.css</strong> file. Its purpose is to center the elements on the page and style the buttons to have the same size.</p>
<p>At the moment, nothing happens when you click on the buttons. Let's write the logic for that in the <strong>script.js</strong> file.</p>
<h2 id="heading-how-to-change-background-color-with-javascript">How to Change Background Color with JavaScript</h2>
<p>To change the background color of an element with JavaScript, you can use the element's <code>style</code> property:</p>
<p>Here's how:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">setBgGreen</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">document</span>.body.style.backgroundColor = <span class="hljs-string">'green'</span>;
}
​
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">setBgRed</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">document</span>.body.style.backgroundColor = <span class="hljs-string">'red'</span>;
}
​
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">setBgBlue</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">document</span>.body.style.backgroundColor = <span class="hljs-string">'blue'</span>;
}
​
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">setBgYellow</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">document</span>.body.style.backgroundColor = <span class="hljs-string">'yellow'</span>;
}
​
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">defaultBgColor</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">document</span>.body.style.backgroundColor = <span class="hljs-string">'white'</span>;
}
</code></pre>
<p>In the code above, we created five functions: <code>setBgGreen()</code>, <code>setBgRed()</code>, <code>setBgBlue()</code>, <code>setBgYellow()</code>, and <code>defaultBgColor()</code>.</p>
<p>Each function has one thing in common: they all target the <code>body</code>. Through the <code>body</code> element (which represents the webpage), we accessed the <code>style.backgroundColor</code> property. The property returns or sets the background color of an element.</p>
<p>So:</p>
<ul>
<li><p><code>document.body.style.backgroundColor = 'green';</code> in the <code>setBgGreen()</code> function sets the background color of <code>body</code> to green.</p>
</li>
<li><p><code>document.body.style.backgroundColor = 'red';</code> in the <code>setBgRed()</code> function sets the background color of <code>body</code> to red.</p>
</li>
<li><p><code>document.body.style.backgroundColor = 'blue';</code> in the <code>setBgBlue()</code> function sets the background color of <code>body</code> to blue.</p>
</li>
<li><p><code>document.body.style.backgroundColor = 'yellow';</code> in the <code>setBgYellow()</code> function sets the background color of <code>body</code> to yellow.</p>
</li>
<li><p><code>document.body.style.backgroundColor = 'white';</code> in the <code>defaultBgColor()</code> function sets the background color of <code>body</code> to white.</p>
</li>
</ul>
<p>Next, you'll assign each function to their respective button using the <code>onclick</code> attribute in your HTML file. This is what your <strong>index.html</strong> file should look like after that:</p>
<pre><code class="lang-xml"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"style.css"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Change BG Color With JS<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Choose background color<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"setBgRed()"</span>&gt;</span>Red<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"setBgBlue()"</span>&gt;</span>Blue<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"setBgGreen()"</span>&gt;</span>Green<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"setBgYellow()"</span>&gt;</span>Yellow<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"defaultBgColor()"</span>&gt;</span>Reset<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
​
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"script.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>When you click the buttons, you should see the background color of the page change to the color assigned to the button.</p>
<p>Note that this is not only applicable to the <code>body</code> element. You can do this for specific parts of your page as well.</p>
<p>For a example, the background color of a <code>div</code> with an <code>id</code> of <code>container</code> can be changed using <code>container.style.backgroundColor = "red"</code> .</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article, you learned how to change background color with JavaScript using an element's <code>style</code> property.</p>
<p>You can find the full project code <a target="_blank" href="https://github.com/ihechikara/change-bg-color-with-js/tree/feat/change-bg-color">here</a>.</p>
<p>Happy coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Create a Masonry Layout Using HTML and CSS ]]>
                </title>
                <description>
                    <![CDATA[ A masonry layout is a grid-based design where items are arranged in a way that minimizes vertical gaps between them.  an example of a masonry layout Unlike traditional grids with fixed row heights, masonry layouts adjust the positioning of items dyn... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-create-a-mansory-layout-using-html-and-css/</link>
                <guid isPermaLink="false">66ba1be4b6a437d5f189cf85</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Fanny Nyayic ]]>
                </dc:creator>
                <pubDate>Tue, 18 Jun 2024 12:22:43 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/06/HTML---CSS-Only-Masonry-Layout.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>A masonry layout is a grid-based design where items are arranged in a way that minimizes vertical gaps between them. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/06/masonry-layout.png" alt="Image" width="600" height="400" loading="lazy">
<em>an example of a masonry layout</em></p>
<p>Unlike traditional grids with fixed row heights, masonry layouts adjust the positioning of items dynamically based on their content height, creating a visually appealing and space-efficient arrangement.</p>
<h2 id="heading-key-characteristics-of-masonry-layouts">Key Characteristics of Masonry Layouts</h2>
<ul>
<li>Items can have varying heights, which makes the layout look more organic and less uniform when compared to standard grids. </li>
<li>Items are positioned to fill vertical gaps, creating a tightly packed layout without large spaces between items.</li>
<li>Masonry layouts can adapt to different screen sizes, adjusting the number of columns and the positioning of items accordingly.</li>
<li>The layout is often used for galleries, portfolios, and other visual content where an aesthetically pleasing presentation is important.</li>
</ul>
<h3 id="heading-common-uses">Common Uses</h3>
<ul>
<li>Image Galleries: Displaying images of different sizes without cropping.</li>
<li>Blog Layouts: Arranging posts of varying lengths.</li>
<li>E-commerce Sites: Showcasing products with different dimensions.</li>
</ul>
<h3 id="heading-how-it-works">How It Works</h3>
<p>Masonry layouts are often implemented using CSS Grid or JavaScript libraries like Masonry.js. Here, we'll focus on the CSS Grid approach.</p>
<h2 id="heading-how-to-create-a-masonry-layout">How to Create a Masonry Layout</h2>
<h3 id="heading-step-1-set-up-your-project">Step 1: Set Up Your Project</h3>
<ul>
<li>Create a project folder: Create a folder for your project on your computer.</li>
<li>Create HTML and CSS files: Inside the project folder, create two files: <code>index.html</code> and <code>styles.css</code>.</li>
</ul>
<pre><code class="lang-folder">Masonry/
├── index.html
└── styles.css
</code></pre>
<h3 id="heading-step-2-write-the-html">Step 2: Write the HTML</h3>
<ul>
<li>Use a text editor like Visual Studio Code, Sublime Text, or any other editor you prefer.</li>
<li>Add the basic structure of an HTML document by pressing <code>Shift+!</code></li>
<li>Change the title from Document to "CSS Masonry Layout"</li>
<li>Below the title, link your <code>styles.css</code> file as shown below:</li>
</ul>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>CSS Masonry Layout<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    /** Link styles.css **/
        <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"styles.css"</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<ul>
<li>After setting up your HTML structure, create the different divisions for your layout within the body area.</li>
</ul>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"masonry"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item1"</span>&gt;</span>Item 1<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item2"</span>&gt;</span>Item 2<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item3"</span>&gt;</span>Item 3<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item4"</span>&gt;</span>Item 4<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item5"</span>&gt;</span>Item 5<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item6"</span>&gt;</span>Item 6<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item7"</span>&gt;</span>Item 7<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item8"</span>&gt;</span>Item 8<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item9"</span>&gt;</span>Item 9<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item10"</span>&gt;</span>Item 10<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<ul>
<li><code>&lt;div class="masonry"&gt;</code> is the container for our masonry layout. We'll use CSS Grid to create the masonry effect inside this container.</li>
<li><code>&lt;div class="item item1"&gt;Item 1&lt;/div&gt;</code> to <code>&lt;div class="item item10"&gt;Item 10&lt;/div&gt;</code> are the individual items (or boxes) inside our masonry layout. Each item has a class of <code>item</code> to style them uniformly and a specific class (for example: <code>item1</code>, <code>item2</code>, and so on) to apply unique styles—like different heights and colors—to each item.</li>
</ul>
<p>Breakdown of the CSS classes:</p>
<ul>
<li><code>item</code>: This class is used to style all items uniformly. It sets the background color, padding, box-sizing, box shadow, border-radius, and transitions for the items.</li>
<li><code>item1</code> to <code>item10</code>: These classes are used to set specific styles for each item. For example, <code>item1</code> might have a different height and background color than <code>item2</code>, and so on. These classes will be used in the CSS to apply specific styles.</li>
</ul>
<h4 id="heading-step-3-style-with-css">Step 3: Style with CSS</h4>
<ul>
<li>Open <code>styles.css</code> in a text editor: Use the same text editor to open your CSS file.</li>
<li>Add some basic styles for the <code>body</code> and the <code>masonry</code> container.</li>
</ul>
<pre><code class="lang-css"> <span class="hljs-selector-tag">body</span> {
        <span class="hljs-attribute">font-family</span>: Arial, sans-serif;
        <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#f0f0f0</span>;
        <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span>;
        <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
    }
    <span class="hljs-selector-class">.masonry</span> {
        <span class="hljs-attribute">display</span>: grid;
        <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(auto-fill, minmax(<span class="hljs-number">200px</span>, <span class="hljs-number">1</span>fr));
        <span class="hljs-attribute">grid-auto-rows</span>: <span class="hljs-number">10px</span>;
        <span class="hljs-attribute">gap</span>: <span class="hljs-number">20px</span>;
    }
</code></pre>
<p>What this means:</p>
<ul>
<li><code>body</code> sets the font, background color, padding, and removes default margin.</li>
<li><code>.masonry</code> uses CSS Grid to create a responsive layout with columns that are at least <code>200px</code> wide and automatically fills the available space. The rows have a base height of <code>10px</code>, and there's a <code>20px</code> gap between items.</li>
</ul>
<p>Add styles for the items inside the masonry layout.</p>
<pre><code class="lang-css"> <span class="hljs-selector-class">.item</span> {
        <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ffffff</span>;
        <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span>;
        <span class="hljs-attribute">box-sizing</span>: border-box;
        <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">4px</span> <span class="hljs-number">6px</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0.1</span>);
        <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">8px</span>;
        <span class="hljs-attribute">transition</span>: transform <span class="hljs-number">0.3s</span>;
        <span class="hljs-attribute">display</span>: flex;
        <span class="hljs-attribute">align-items</span>: center;
        <span class="hljs-attribute">justify-content</span>: center;
        <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.2em</span>;
        <span class="hljs-attribute">color</span>: <span class="hljs-number">#fff</span>;
    }
    <span class="hljs-selector-class">.item</span><span class="hljs-selector-pseudo">:hover</span> {
        <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translateY</span>(-<span class="hljs-number">10px</span>);
    }
</code></pre>
<p>What the above means:</p>
<ul>
<li><code>.item</code> sets a white background, padding, box shadow for elevation, rounded corners, and a hover effect to lift the item slightly. <code>display: flex</code> centers the content.</li>
<li><code>.item:hover</code> will add a transform effect when the item is hovered on.</li>
</ul>
<p>Set specific dimensions and colors by defining specific styles for each item to give them different heights and background colors.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.item1</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">15</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ff6f61</span>; }
<span class="hljs-selector-class">.item2</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">20</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#6b5b95</span>; }
<span class="hljs-selector-class">.item3</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">10</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#88b04b</span>; }
<span class="hljs-selector-class">.item4</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">25</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#d65076</span>; }
<span class="hljs-selector-class">.item5</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">30</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ffb347</span>; }
<span class="hljs-selector-class">.item6</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">15</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#45b8ac</span>; }
<span class="hljs-selector-class">.item7</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">20</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#e94b3c</span>; }
<span class="hljs-selector-class">.item8</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">10</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#6c5b7b</span>; }
<span class="hljs-selector-class">.item9</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">25</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#00a86b</span>; }
<span class="hljs-selector-class">.item10</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">30</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#b565a7</span>;}
</code></pre>
<ul>
<li>Each item class (.item1, .item2, and so on) sets the number of rows it spans (grid-row: span X;) and assigns a unique background color.</li>
</ul>
<h3 id="heading-step-4-view-your-layout">Step 4: View Your Layout</h3>
<p>Open <code>index.html</code> in a web browser to see the masonry layout.</p>
<p>You can add more items, change colors, or adjust sizes to fit your design needs. Below is the layout we created.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/06/masonry-layout-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-putting-it-all-together">Putting it all together</h3>
<p>The <code>index.html</code> file should look like this:</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>CSS Masonry Layout<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"styles.css"</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"masonry"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item1"</span>&gt;</span>Item 1<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item2"</span>&gt;</span>Item 2<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item3"</span>&gt;</span>Item 3<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item4"</span>&gt;</span>Item 4<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item5"</span>&gt;</span>Item 5<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item6"</span>&gt;</span>Item 6<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item7"</span>&gt;</span>Item 7<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item8"</span>&gt;</span>Item 8<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item9"</span>&gt;</span>Item 9<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item10"</span>&gt;</span>Item 10<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>The <code>styles.css</code> file will look like this:.</p>
<pre><code class="lang-css">    <span class="hljs-selector-tag">body</span> {
        <span class="hljs-attribute">font-family</span>: Arial, sans-serif;
        <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#f0f0f0</span>;
        <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span>;
        <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
    }
    <span class="hljs-selector-class">.masonry</span> {
        <span class="hljs-attribute">display</span>: grid;
        <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(auto-fill, minmax(<span class="hljs-number">200px</span>, <span class="hljs-number">1</span>fr));
        <span class="hljs-attribute">grid-auto-rows</span>: <span class="hljs-number">10px</span>;
        <span class="hljs-attribute">gap</span>: <span class="hljs-number">20px</span>;
    }

    <span class="hljs-selector-class">.item</span> {
        <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ffffff</span>;
        <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span>;
        <span class="hljs-attribute">box-sizing</span>: border-box;
        <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">4px</span> <span class="hljs-number">6px</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0.1</span>);
        <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">8px</span>;
        <span class="hljs-attribute">transition</span>: transform <span class="hljs-number">0.3s</span>;
        <span class="hljs-attribute">display</span>: flex;
        <span class="hljs-attribute">align-items</span>: center;
        <span class="hljs-attribute">justify-content</span>: center;
        <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.2em</span>;
        <span class="hljs-attribute">color</span>: <span class="hljs-number">#fff</span>;
    }

    <span class="hljs-selector-class">.item</span><span class="hljs-selector-pseudo">:hover</span> {
        <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translateY</span>(-<span class="hljs-number">10px</span>);
    }

    <span class="hljs-comment">/* Specific dimensions and colors for each item */</span>
    <span class="hljs-selector-class">.item1</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">15</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ff6f61</span>; }
    <span class="hljs-selector-class">.item2</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">20</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#6b5b95</span>; }
    <span class="hljs-selector-class">.item3</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">10</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#88b04b</span>; }
    <span class="hljs-selector-class">.item4</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">25</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#d65076</span>; }
    <span class="hljs-selector-class">.item5</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">30</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ffb347</span>; }
    <span class="hljs-selector-class">.item6</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">15</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#45b8ac</span>; }
    <span class="hljs-selector-class">.item7</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">20</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#e94b3c</span>; }
    <span class="hljs-selector-class">.item8</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">10</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#6c5b7b</span>; }
    <span class="hljs-selector-class">.item9</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">25</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#00a86b</span>; }
    <span class="hljs-selector-class">.item10</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">30</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#b565a7</span>; }
</code></pre>
<h2 id="heading-summary">Summary</h2>
<p>A masonry layout is an effective way to display content with varying heights in a grid-like structure without large vertical gaps, making it ideal for image galleries, blogs, and portfolios. </p>
<p>Using CSS Grid, you can create a responsive and visually appealing masonry layout with minimal code.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ HTML for Beginners – HTML Basics With Code Examples ]]>
                </title>
                <description>
                    <![CDATA[ Welcome to the exciting world of web development! In this beginner's guide, you will learn the fundamentals of HTML, the backbone of every web page. Imagine a tree: its roots anchor and nourish the entire plant. Similarly, HTML, the root of web devel... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/introduction-to-html-basics/</link>
                <guid isPermaLink="false">66d45e043a8352b6c5a2aa19</guid>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Casmir Onyekani ]]>
                </dc:creator>
                <pubDate>Tue, 07 May 2024 19:45:50 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/05/cover-img.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Welcome to the exciting world of web development! In this beginner's guide, you will learn the fundamentals of HTML, the backbone of every web page.</p>
<p>Imagine a tree: its roots anchor and nourish the entire plant. Similarly, HTML, the root of web development, provides the foundation for every webpage.</p>
<p>Understanding HTML's role is like grasping a tree's roots, it forms the fundamental basis for comprehending how web pages come to life.</p>
<p>By the end of this tutorial, you'll be equipped with the knowledge to kick-start your coding journey.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a class="post-section-overview" href="#heading-what-is-html">What is HTML?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-basic-structure-of-an-html-document">Basic Structure of an HTML Document</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-comments">Comments</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-tags-and-elements">Tags and Elements</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-html-attributes">HTML Attributes</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-html-multimedia">HTML Multimedia</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-best-practices">Best Practices</a></p>
</li>
</ul>
<h2 id="heading-what-is-html">What is HTML?</h2>
<p>HTML, which stands for Hypertext Markup Language, is the standard language used for creating and designing the structure of a web page. It allows you to organize content on your website, define its structure, and establish the relationships between different elements.</p>
<h2 id="heading-basic-structure-of-an-html-document">Basic Structure of an HTML Document</h2>
<p>An HTML document follows a specific structure that acts as the foundation for your web page:</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Document<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">link</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- your web page content goes here --&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>Let's break it down:</p>
<p><code>&lt;!DOCTYPE html&gt;</code>: defines the document type and version of HTML being used (HTML5 in this case).</p>
<p><code>&lt;html lang="en"&gt;</code> and <code>&lt;/html&gt;</code>: opening and closing tag of the root element that wraps the entire HTML content. The attribute <code>lang="en"</code> defines the language (in this case, USA English)</p>
<p><code>&lt;head&gt;</code> and <code>&lt;/head&gt;</code>: opening and closing tag of the <code>head</code> element contains meta-information <code>&lt;meta &gt;</code> about the HTML document, the page title <code>&lt;title&gt;&lt;/title&gt;</code> you see in the browser tab, and link <code>&lt;link /&gt;</code> which defines a link between your HTML document and an external resources, like stylesheet, favicon, import and so on.</p>
<p><code>&lt;body&gt;</code> and <code>&lt;/body&gt;</code> : opening and closing <code>body</code> tag encloses all the visible content of a web page, including text, images, links, forms, and other elements that users interact with.</p>
<p><strong>Note</strong>: All HTML elements have opening (<code>**&lt; &gt;**</code>) and closing (<code>**&lt;/ &gt;**</code>) tags, except for self-closing (<code>**&lt; &gt;**</code> or <code>**&lt; /&gt;**</code>) tags, which I will explain in more detail later.</p>
<h2 id="heading-comments">Comments</h2>
<p>Notice this <code>&lt;!-- your web page content goes here --&gt;</code> in the above html basic structure, it's called comments. Comments are used to add explanatory notes that are not displayed when the web page is viewed in a browser. They are useful for documenting your code, providing information to other developers, or temporarily excluding specific parts of the code. You can create comment using this tag <code>&lt;!--</code> <code>your comment goes here</code> <code>--&gt;</code>.</p>
<p>There are:</p>
<ol>
<li><p><strong>Single-line commen</strong>t: <code>&lt;!-- This is a single-line comment --&gt;</code></p>
</li>
<li><p><strong>Multi-line comment</strong>: <code>&lt;!-- This is a multi-line comment. It can span multiple lines. All content within the comment block will be ignored by the browser. --&gt;</code></p>
</li>
</ol>
<h2 id="heading-tags-and-elements">Tags and Elements</h2>
<p>HTML uses tags to define different elements on a webpage. Tags are enclosed in angle brackets (<code>&lt; &gt;</code>). There are opening (<code>&lt; &gt;</code>) and closing (<code>&lt;/ &gt;</code>) tags, and self-closing (<code>&lt; &gt;</code> or <code>&lt; /&gt;</code>) tag. Here are a few examples:</p>
<h3 id="heading-headings">Headings</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>This is a Heading 1<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>This is a Heading 2<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
<span class="hljs-comment">&lt;!-- ... up to &lt;h6&gt; --&gt;</span>
</code></pre>
<p>The heading tags <code>&lt;h1&gt;</code> to <code>&lt;h6&gt;</code> are used to define headings or subheadings within a document. These tags represent a hierarchy of headings, with <code>&lt;h1&gt;</code> being the highest level (main heading) and <code>&lt;h6&gt;</code> being the lowest level (lowest subheading level).</p>
<p>Its purpose is to structure and organize the content of a web page, making it more readable and accessible.</p>
<h3 id="heading-paragraph">Paragraph</h3>
<p>The paragraph tag (<code>&lt;p&gt; your text goes here &lt;/p&gt;</code>) is used to separate blocks of text into distinct paragraphs. It is a block-level element that represents a unit of text or a block of content, and it is commonly used to structure and separate text on a webpage.</p>
<p>The <code>&lt;p&gt;</code> tag is part of the structural markup in HTML and helps in creating well-organized and readable content.</p>
<h3 id="heading-line-breaks">Line Breaks</h3>
<p>To create a line break without starting a new paragraph, use the break (<code>&lt;br&gt;</code>) tag.</p>
<p>Example 1 - Basic Line Break:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is the first line.<span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>This is the second line.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>This will render as:</p>
<p>This is the first line.<br>This is the second line.</p>
<p>Example 2 - Line Breaks in Text:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This text contains a<span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>line break.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>This will render as:</p>
<p>This text contains a<br>line break.</p>
<p>Example 3 - Line Breaks in List:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 1<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 2<span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>with a line break<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 3<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
</code></pre>
<p>This will render as:</p>
<ul>
<li><p>Item 1</p>
</li>
<li><p>Item 2<br>  with a line break</p>
</li>
<li><p>Item 3</p>
</li>
</ul>
<p>Example 4 - Line Breaks in Address:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">address</span>&gt;</span>
  Nuel Cas<span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
  23 Musa Yar'Dua VI<span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
  Lagos, Nigeria
<span class="hljs-tag">&lt;/<span class="hljs-name">address</span>&gt;</span>
</code></pre>
<p>This will render as:</p>
<p>Nuel Cas<br>23 Musa Yar'Dua VI<br>Lagos, Nigeria</p>
<p>Example 5: Line Breaks with Multiple<br>Tags</p>
<pre><code class="lang-python">&lt;p&gt;This <span class="hljs-keyword">is</span> a paragraph <span class="hljs-keyword">with</span>&lt;br&gt;&lt;br&gt;multiple line breaks.&lt;/p&gt;
</code></pre>
<p>This will render as:</p>
<p>This is a paragraph with</p>
<p>multiple line breaks.</p>
<p>While break (<code>&lt;br&gt;</code>) tag is commonly used for simple line breaks, CSS and block-level elements like <code>&lt;p&gt;</code> and <code>&lt;div&gt;</code> tags are often preferred for more complex layouts.</p>
<p>Overusing <code>&lt;br&gt;</code> tags for layout purposes is discouraged. CSS is generally more suitable for controlling the spacing and layout of elements on a webpage.</p>
<h3 id="heading-div">Div</h3>
<p>A <code>&lt;div&gt;</code> tag, which stands for "division" is one of the most commonly used container elements in HTML. It is a block-level container that is used to group other HTML elements together and apply styles or scripting to them collectively.</p>
<p>Here's an example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is a paragraph inside a div.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>List item 1<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>List item 2<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>In this example, the <code>&lt;div&gt;</code> element wraps around a paragraph (<code>&lt;p&gt;</code>) and an unordered list (<code>&lt;ul&gt;</code>). This grouping allows you to apply styles or manipulate these elements together using CSS or JavaScript.</p>
<p><strong>Note</strong>: The <code>&lt;div&gt;</code> tag is often used for layout purposes, helping structure the content of a webpage. For more semantic and specific meanings, HTML5 introduced new semantic tags like <code>&lt;section&gt;</code>, <code>&lt;article&gt;</code>, <code>&lt;header&gt;</code>, <code>&lt;footer&gt;</code>, and so on, which provide better clarity about the content's purpose.</p>
<h3 id="heading-semantic-tags">Semantic Tags</h3>
<p>They are like special labels that tell web browsers and developers what different parts of a webpage are all about. They help make websites easier to understand for both people and computers.</p>
<p>By using these tags, you can make your websites more accessible and easier to find on search engines. Here are some common HTML semantic tags along with examples:</p>
<ol>
<li><code>&lt;header&gt;</code>: The header tag represents introductory content at the beginning of a section or webpage. It typically contains logos, navigation menus, and other introductory elements.</li>
</ol>
<p>Example:</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">header</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Website Title<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">nav</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Home<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>About<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Contact<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">header</span>&gt;</span>
</code></pre>
<ol start="2">
<li><code>&lt;nav&gt;</code>: Use nav tag to define navigation links within your webpage. It contains links to other pages or sections of the website.</li>
</ol>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">nav</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Home<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>About<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Contact<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
</code></pre>
<ol start="3">
<li><code>&lt;main&gt;</code>: Used to define the main content of a webpage. It helps improve the accessibility and structure of your HTML code, as it clearly identifies the main content area for screen readers and other assistive technologies. It also helps search engines understand the relevance of the content on your page, which can improve your website's Search Engine Optimization (SEO).</li>
</ol>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">main</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">article</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Page Title<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Page content goes here...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">article</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">main</span>&gt;</span>
</code></pre>
<ol start="4">
<li><code>&lt;section&gt;</code>: Use the <code>section</code> tag when you want to define sections within a webpage. Also, for grouping related content together.</li>
</ol>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">section</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Section Title<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Section content goes here...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
</code></pre>
<ol start="5">
<li><code>&lt;article&gt;</code>: Use the <code>article</code> tag when you want to define an independent piece of content that can stand alone, such as a blog post, news article, or forum post.</li>
</ol>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">article</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Article Title<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Article content goes here...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">article</span>&gt;</span>
</code></pre>
<ol start="6">
<li><code>&lt;aside&gt;</code>: Use the <code>aside</code> tag when you want to define content that is related to the main content but not part of it, such as sidebars, advertisements, or related links.</li>
</ol>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">aside</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>Related Links<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Link 1<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Link 2<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Link 3<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">aside</span>&gt;</span>
</code></pre>
<ol start="7">
<li><code>&lt;footer&gt;</code>: Used to define the footer of a webpage, typically containing copyright information, contact details, or links to related pages.</li>
</ol>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">footer</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-symbol">&amp;copy;</span> Nuel Cas Website<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">footer</span>&gt;</span>
</code></pre>
<h3 id="heading-list-tag">List Tag</h3>
<p>Lists <code>&lt;li&gt;</code> allow you to organize and structure content in a hierarchical manner. They are two types: ordered <code>&lt;ol&gt;</code> (numbered) and unordered (<code>&lt;ul&gt;</code>) (bulleted) lists.</p>
<p>Ordered List: Use <code>&lt;ol&gt;</code> for ordered lists, and <code>&lt;li&gt;</code> for list items.</p>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ol</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>First item<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Second item<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Third item<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ol</span>&gt;</span>
</code></pre>
<p>This will render as:</p>
<ol>
<li><p>First item</p>
</li>
<li><p>Second item</p>
</li>
<li><p>Third item</p>
</li>
</ol>
<p>Unordered List: The <code>&lt;ul&gt;</code> tag is used to create an unordered list, where the order of the items doesn't matter, it renders bulleted items. Each item in the list is represented by the <code>&lt;li&gt;</code> (list item) tag.</p>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 1<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 2<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 3<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
</code></pre>
<p>This will render as:</p>
<ul>
<li><p>Item 1</p>
</li>
<li><p>Item 2</p>
</li>
<li><p>Item 3</p>
</li>
</ul>
<p>Lists can be nested within each other. For example, you can have an ordered list within an unordered list or vice versa.</p>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Unordered List Item 1<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Unordered List Item 2
    <span class="hljs-tag">&lt;<span class="hljs-name">ol</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Ordered List Item 1<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Ordered List Item 2<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">ol</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Unordered List Item 3<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
</code></pre>
<p>This will render as:</p>
<ul>
<li><p>Unordered List Item 1</p>
</li>
<li><p>Unordered List Item 2</p>
</li>
</ul>
<ol>
<li><p>Ordered List Item 1</p>
</li>
<li><p>Ordered List Item 2</p>
</li>
</ol>
<ul>
<li>Unordered List Item 3</li>
</ul>
<p>List items can also have attributes. For example, you might use the <code>type</code> attribute with the <code>&lt;ol&gt;</code> tag to change the numbering style.</p>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ol</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"A"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 1<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 2<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 3<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ol</span>&gt;</span>
</code></pre>
<p>This will render as:</p>
<p>A. Item 1<br>B. Item 2<br>C. Item 3</p>
<p>The <code>&lt;ul&gt;</code>, <code>&lt;ol&gt;</code>, and <code>&lt;li&gt;</code> tags in HTML are essential for creating organized lists and structuring content on web pages. They provide flexibility in presenting information in both ordered and unordered formats.</p>
<h3 id="heading-span-tag">Span Tag</h3>
<p>The <code>&lt;span&gt;</code> tag is a generic inline (it does not create a line break) container used to group and apply styles to inline elements or text. It is typically used when you want to apply styles or using JavaScript to manipulate specific portions of text within a larger block of content without affecting the overall structure.</p>
<p>Here's an example of how the <code>&lt;span&gt;</code> tag can be used in HTML:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is a <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"color: red; font-weight: bold;"</span>&gt;</span>highlighted<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span> text.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>In this example, the word "highlighted" will be displayed in red and bold, as specified by the inline styles applied to the <code>&lt;span&gt;</code> element.</p>
<h3 id="heading-links">Links</h3>
<p>The <code>&lt;link&gt;</code> tag is used to define a link between a document and an external resource. Its primary purpose is to include external resources, such as stylesheets, icons, and other documents. Let's look at the common use cases of the <code>&lt;link&gt;</code> tag:</p>
<p><strong>Linking stylesheet</strong>: The most common use of the <code>&lt;link&gt;</code> tag is to link an external CSS (Cascading Style Sheets) file to an HTML document. This allows you to separate the styling of your website from its structure, making it easier to maintain and update.</p>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/css"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"styles.css"</span>&gt;</span>
</code></pre>
<p>In this example, the <code>rel</code> attribute specifies the relationship between the HTML document and the linked resource (stylesheet), the <code>type</code> attribute indicates the type of the linked resource (<code>text/css</code> for stylesheets), and the <code>href</code> attribute specifies the path to the external CSS file.</p>
<p><strong>Note</strong>: Linking a CSS file should be done inside the <code>&lt;head&gt;</code> element.</p>
<p><strong>Linking icon</strong>: The <code>&lt;link&gt;</code> tag is also commonly used to link the favicon icon for a webpage, which is the small icon that appears in the browser tab or next to the URL in the address bar.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"icon"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"favicon.ico"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"image/x-icon"</span>&gt;</span>
</code></pre>
<p>In this case, the <code>rel</code> attribute is set to "icon" to indicate that it is an icon file, and the <code>href</code> attribute specifies the path to the icon file. The <code>type</code> attribute indicates the type of the linked file, in this case, <code>image/x-icon</code> for icons.</p>
<p><strong>Linking external documents</strong>: The <code>&lt;link&gt;</code> tag can be used to link other external documents, such as:</p>
<ol>
<li>Stylesheet for printing: Imagine you have a special design for when someone wants to print your webpage. The <code>&lt;link&gt;</code> tag can connect your webpage to a separate stylesheet designed just for printing. This way, when someone prints your page, it looks nice and tidy.</li>
</ol>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!-- Link to the stylesheet for printing --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/css"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"print-styles.css"</span> <span class="hljs-attr">media</span>=<span class="hljs-string">"print"</span>&gt;</span>
</code></pre>
<ol start="2">
<li>Alternative versions of a document (like translations): Sometimes, you might have different versions of your webpage for different languages or purposes. The <code>&lt;link&gt;</code> tag can connect your webpage to these alternative versions.</li>
</ol>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"alternate"</span> <span class="hljs-attr">hreflang</span>=<span class="hljs-string">"es"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"spanish-version.html"</span>&gt;</span>
</code></pre>
<ol start="3">
<li>Feeds for content syndication: Let's say you have a blog, and you want others to easily see your latest posts. The <code>&lt;link&gt;</code> tag can help by connecting your webpage to a feed, which is like a stream of your latest content.</li>
</ol>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"alternate"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"application/rss+xml"</span> <span class="hljs-attr">title</span>=<span class="hljs-string">"RSS Feed"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"rss-feed.xml"</span>&gt;</span>
</code></pre>
<p>The <code>&lt;link&gt;</code> tag is like a connector that helps your webpage interact with other files on the internet.</p>
<h3 id="heading-anchor-tag">Anchor Tag</h3>
<p>The anchor tag, represented by <code>&lt;a&gt;</code>, is used to create hyperlinks or anchor points within a webpage. It is primarily used to define a hyperlink, allowing users to navigate to another webpage, a different section of the same page, or even an external resource.</p>
<p>The anchor tag uses the <code>href</code> attribute to specify the destination URL (Uniform Resource Locator).</p>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://www.example.com"</span>&gt;</span>Visit Example.com<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<h3 id="heading-form-tag">Form tag</h3>
<p>HTML forms are essential for user interaction on websites. They allow users to input data that can be sent to a server for processing. The basic structure of an HTML form involves several key elements:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- Your form elements go here --&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p>The <code>&lt;form&gt;</code> tag marks the beginning and end of your form. It acts as a container for various form elements. It commonly houses label, input types, textarea, and button tags.</p>
<h4 id="heading-label">Label</h4>
<p>The <code>&lt;label&gt;</code> tag is used to define a label for an input element. Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"username"</span>&gt;</span>Username:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
</code></pre>
<h4 id="heading-input-type">Input type</h4>
<p>In a form, different input types serve various purposes. The input (<code>&lt;input&gt;</code>) tag defines an interactive element for users to enter data. Commonly used ones are:</p>
<p>Text Input:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"username"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Enter your username"</span>&gt;</span>
</code></pre>
<p>Password Input:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"password"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"password"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Enter your password"</span>&gt;</span>
</code></pre>
<p>Radio Buttons:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"gender"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"male"</span>&gt;</span> Male
<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"gender"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"female"</span>&gt;</span> Female
</code></pre>
<p>Checkboxes:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"subscribe"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"yes"</span>&gt;</span> Subscribe to newsletter
</code></pre>
<h4 id="heading-textarea">Textarea</h4>
<p>The <code>&lt;textarea&gt;</code> tag defines a multi-line text input control, commonly used within form elements. Example:</p>
<pre><code class="lang-python">&lt;textarea name=<span class="hljs-string">"message"</span> placeholder=<span class="hljs-string">"Enter your message"</span>&gt;&lt;/textarea&gt;
</code></pre>
<h4 id="heading-button-for-submitting-forms">Button (for submitting forms)</h4>
<p>The most crucial part of a form is allowing users to submit their input. For this, you can use a button (<code>&lt;button&gt;</code>) tag to submit:</p>
<p>Example:</p>
<pre><code class="lang-python">&lt;button type=<span class="hljs-string">"submit"</span>&gt;Submit&lt;/button&gt;
</code></pre>
<p>The <code>&lt;button&gt;</code> tag creates a clickable button. The <code>type="submit"</code> attribute indicates that clicking this button will submit the form.</p>
<h3 id="heading-quick-tips">Quick Tips</h3>
<ul>
<li><p>Always include a <code>name</code> attribute in your form elements. It helps identify and process the data on the server.</p>
</li>
<li><p>Use the <code>placeholder</code> attribute to give users a hint about the expected input.</p>
</li>
<li><p>Consider the user experience when choosing input types. For instance, use radio buttons for mutually exclusive options.</p>
</li>
</ul>
<p>Here is a code snippet demonstrating usage of a form element:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"username"</span>&gt;</span>Username:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"username"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"username"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Enter your username"</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"password"</span>&gt;</span>Password:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"password"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"password"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"password"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Enter your password"</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">label</span>&gt;</span>Gender:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"gender"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"male"</span>&gt;</span> Male
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"gender"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"female"</span>&gt;</span> Female

  <span class="hljs-tag">&lt;<span class="hljs-name">label</span>&gt;</span>Subscribe to newsletter:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"subscribe"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"yes"</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"message"</span>&gt;</span>Your Message:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">textarea</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"message"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"message"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Enter your message"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">textarea</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<h3 id="heading-self-closing-tags">Self-closing Tags</h3>
<p>The <code>&lt;input&gt;</code> or <code>&lt;input /&gt;</code> element above is a self-closing tag, which means it doesn't require a separate closing tag.</p>
<p>There are other self-closing tags in HTML:</p>
<ul>
<li><p>Image (<code>&lt;img&gt;</code> or <code>&lt;img /&gt;</code>).</p>
</li>
<li><p>Line breaks (<code>&lt;br&gt;</code> or <code>&lt;br /&gt;</code>).</p>
</li>
<li><p>External resource link (<code>&lt;link&gt;</code> or <code>&lt;link /&gt;</code>).</p>
</li>
<li><p>Horizontal rule (<code>&lt;hr&gt;</code> or <code>&lt;hr /&gt;</code>).</p>
</li>
<li><p>Meta data (<code>&lt;meta&gt;</code> or <code>&lt;meta /&gt;</code>).</p>
</li>
<li><p>Table column (<code>&lt;col&gt;</code> or <code>&lt;col /&gt;</code>).</p>
</li>
<li><p>Base URL for relative links (<code>&lt;base&gt;</code> or <code>&lt;base /&gt;</code>).</p>
</li>
<li><p>Word break opportunity (<code>&lt;wbr&gt;</code> or <code>&lt;wbr /&gt;</code>).</p>
</li>
<li><p>Area (<code>&lt;area&gt;</code> or <code>&lt;area /&gt;</code>) which defines an area inside an image map so the image can have a clickable region.</p>
</li>
</ul>
<p>Note: HTML5 (latest version of HTML) allows you to omit the slash (<code>/</code>) at the end of self-closing tags, but including it ensures compatibility with older standards like XHTML and some tools.</p>
<h2 id="heading-html-attributes">HTML Attributes</h2>
<p>This is an additional information or characteristics that you can apply to HTML elements to modify their behavior, appearance, or define certain properties. Attributes are always included in the opening tag of an HTML element and are written as name-value pairs.</p>
<p>The basic syntax for an HTML attribute is:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">tagname</span> <span class="hljs-attr">attribute</span>=<span class="hljs-string">"value"</span>&gt;</span>Content<span class="hljs-tag">&lt;/<span class="hljs-name">tagname</span>&gt;</span>
</code></pre>
<p>Here, <code>attribute</code> is the name of the attribute, and <code>"value"</code> is the value assigned to that attribute.</p>
<p>There are many attributes available for various HTML elements, here are few ones:</p>
<h3 id="heading-id-attribute">id Attribute</h3>
<p>It provides a unique identifier for an HTML element. It should be unique within the entire HTML document.</p>
<p>"id" attribute helps you uniquely identify and control specific elements on a webpage, just like how each student's ID number helps identify them uniquely in a school.</p>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"header"</span>&gt;</span>This is a div with an id attribute.<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h3 id="heading-class-attribute">class Attribute</h3>
<p>Used to assign one or more class names to an HTML element. It also helps you organize and style different parts of a webpage by grouping them together.</p>
<p>Here is the syntax for class attribute:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">tagname</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"classname1 classname2 ..."</span>&gt;</span>Content<span class="hljs-tag">&lt;/<span class="hljs-name">tagname</span>&gt;</span>
</code></pre>
<p>Suppose you want to style multiple paragraphs with the same font and color. Instead of writing the same CSS styles for each paragraph individually, you can assign a common class to all those paragraphs and define the styles for that class in your CSS file. Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"highlight"</span>&gt;</span>This is the first paragraph.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"highlight"</span>&gt;</span>This is the second paragraph.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"highlight"</span>&gt;</span>This is the third paragraph.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre>
<p><strong>Note</strong>: The "id" attribute and the "class" attribute in HTML serve similar purposes in that they both allow you to uniquely identify elements on a webpage. However, there are key differences between the two:</p>
<ul>
<li><p>Use the "id" attribute when you need to uniquely identify a single element.</p>
</li>
<li><p>Use the "class" attribute when you want to group multiple elements together and apply styling or functionality to them collectively.</p>
</li>
</ul>
<p>While both attributes can be used for styling, the "id" attribute is more suitable for unique styling, while the "class" attribute is ideal for applying consistent styles to multiple elements.</p>
<h3 id="heading-src-source-attribute">src (source) Attribute</h3>
<p>It specifies the source URL of an image to be displayed. Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"image.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Nuel Cas Photo"</span>&gt;</span>
</code></pre>
<p><strong>Note</strong>: The <code>alt</code> attribute is used to provide alternative text for an image if the image fails to load. It serves as a descriptive text that is displayed in place of the image, helping users understand the content or purpose of the image even when it's not visible.</p>
<h3 id="heading-href-attribute-for-links">href Attribute (for links)</h3>
<p>It specifies the URL that the hyperlink points to. Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://www.nuelcas.com"</span>&gt;</span>Visit Nuel Cas<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<h3 id="heading-width-and-height-attribute-for-images">width and height Attribute (for images)</h3>
<p>It determines the width and height of an image in pixels. Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"image.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Nuel Cas Photo"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"400"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"300"</span>&gt;</span>
</code></pre>
<h3 id="heading-style-attribute">style Attribute</h3>
<p>Allows you to apply inline CSS styles to an HTML element. Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"color: red; font-size: 18px;"</span>&gt;</span>This is a red text.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<h3 id="heading-disabled-attribute-for-form-elements">disabled Attribute (for form elements)</h3>
<p>Allows you to disable user interaction with form element. Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">disabled</span>&gt;</span>
</code></pre>
<h3 id="heading-type-attribute-for-form-element-and-list-items">type Attribute (for form element and list items)</h3>
<p>You can use the <code>type</code> attribute with the <code>&lt;ol&gt;</code> tag to change the numbering style. Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ol</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"A"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item A<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item B<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item C<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ol</span>&gt;</span>
</code></pre>
<p>This will render as:</p>
<pre><code class="lang-text">A. Item A
B. Item B
C. Item C
</code></pre>
<p>Also, you can use <code>type</code> attribute to specify the input type of form element. Say you want to notify the browser that this input is for password, use the code below</p>
<pre><code class="lang-python">&lt;input type=<span class="hljs-string">"password"</span> name=<span class="hljs-string">"password"</span> placeholder=<span class="hljs-string">"Enter your password"</span>&gt;
</code></pre>
<h3 id="heading-name-attribute-for-form-element">name attribute (for form element)</h3>
<p>The <code>name</code> attribute provides a unique identifier for each form field. When the form is submitted to the server, the data entered into each field is sent with the corresponding name as a <em>key-value</em> pair. The code snippet below shows that you want the server to identify this input as email.</p>
<pre><code class="lang-python"> &lt;input type=<span class="hljs-string">"email"</span> id=<span class="hljs-string">"email"</span> name=<span class="hljs-string">"email"</span> placeholder=<span class="hljs-string">"Enter your email"</span>&gt;
</code></pre>
<p><strong>Note</strong>: Understanding and using attributes effectively is essential for controlling the appearance and behavior of elements in your HTML documents.</p>
<h2 id="heading-html-multimedia">HTML Multimedia</h2>
<p>You may need to integrate various types of media content into web pages, such as images, audio, and video. These media elements enhance the user experience by making web content more engaging and dynamic.</p>
<p>Here are the different types of multimedia you can use in HTML:</p>
<h3 id="heading-images">Images</h3>
<p>Images are the most common type of multimedia in HTML. You can add images to a web page using the <code>&lt;img&gt;</code> tag. Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"image.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Description of the image"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"200"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"150"</span>&gt;</span>
</code></pre>
<p>In the above example, <code>src</code> specifies the source URL of the image, <code>alt</code> provides alternative text for accessibility and SEO, and <code>width</code> and <code>height</code> are optional attributes to set the dimensions of the image.</p>
<h3 id="heading-audio">Audio</h3>
<p>You can embed audio files directly into a web page using the <code>&lt;audio&gt;</code> tag. This allows you to play audio clips, music, or other sound recordings. Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">audio</span> <span class="hljs-attr">controls</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">source</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"audio.mp3"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"audio/mpeg"</span>&gt;</span>
  Your browser may not support the audio element.
<span class="hljs-tag">&lt;/<span class="hljs-name">audio</span>&gt;</span>
</code></pre>
<p>In the above example, <code>controls</code> provides play, pause, and volume controls for the user, <code>src</code>specifies the source URL of the audio file, while <code>type</code> specifies the <a target="_blank" href="https://en.wikipedia.org/wiki/MIME">MIME</a> (Multipurpose Internet Mail Extensions) type of the audio file.</p>
<h3 id="heading-video">Video</h3>
<p>The <code>&lt;video&gt;</code> tag is used to embed video files into a web page. This allows you to play videos within the content. Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">video</span> <span class="hljs-attr">controls</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"640"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"360"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">source</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"video.mp4"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"video/mp4"</span>&gt;</span>
  Your browser may not support the video element.
<span class="hljs-tag">&lt;/<span class="hljs-name">video</span>&gt;</span>
</code></pre>
<p>In the above example, <code>controls</code> provides play, pause, and volume controls for the user, <code>width</code> and <code>height</code> specifies the dimensions of the video, <code>src</code> specifies the source URL of the video file, while <code>type</code> specifies the MIME type of the video file.</p>
<h3 id="heading-iframe">iframe</h3>
<p><code>&lt;iframe&gt;</code> allows you to display content from a different source or page inside a frame on your webpage. This can be useful for embedding videos, maps, web pages, or other external content. Example using <code>&lt;iframe&gt;</code> to embed a video from YouTube:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">iframe</span> 
  <span class="hljs-attr">src</span>=<span class="hljs-string">"https://www.youtube.com/embed/VIDEO_ID"</span> 
  <span class="hljs-attr">width</span>=<span class="hljs-string">"560"</span> 
  <span class="hljs-attr">height</span>=<span class="hljs-string">"315"</span> 
  <span class="hljs-attr">title</span>=<span class="hljs-string">"YouTube Video"</span> 
  <span class="hljs-attr">frameborder</span>=<span class="hljs-string">"0"</span> 
  <span class="hljs-attr">allowfullscreen</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">iframe</span>&gt;</span>
</code></pre>
<p>In the above code snippet, <code>src</code> attribute specifies the URL of the page or content you want to embed. Sizes are controlled using the <code>width</code> and <code>height</code> attributes. <code>title</code> attribute provides a description for the content, which is important for accessibility.</p>
<p>The <code>frameborder</code> attribute controls whether the iframe has a border (0 for no border, 1 for a border), while the <code>allowfullscreen</code> attribute allows the video to be played in full-screen mode.</p>
<p><strong>Note</strong>: Replace <code>"VIDEO_ID"</code> with the ID of the YouTube video you want to embed.</p>
<h2 id="heading-best-practices">Best Practices</h2>
<ol>
<li>Follow proper HTML document structure:</li>
</ol>
<ul>
<li><p>Start your HTML document with a <code>&lt;!DOCTYPE html&gt;</code> declaration to ensure browser compatibility and standards compliance.</p>
</li>
<li><p>Always include the <code>&lt;html&gt;</code>, <code>&lt;head&gt;</code>, and <code>&lt;body&gt;</code> tags in your document.</p>
</li>
<li><p>Use the <code>&lt;meta charset="UTF-8"&gt;</code> tag to specify the character encoding of your document.</p>
</li>
<li><p>Define the language of your document using the language (<code>&lt;html lang="en"&gt;</code>) attribute.</p>
</li>
<li><p>Include a descriptive title (<code>&lt;title&gt;</code>) tag within the head (<code>&lt;head&gt;</code>) section to provide context for the page.</p>
</li>
</ul>
<ol start="2">
<li>Use semantic HTML element:</li>
</ol>
<ul>
<li>Utilize semantic HTML elements like <code>&lt;header&gt;</code>, <code>&lt;nav&gt;</code>, <code>&lt;main&gt;</code>, <code>&lt;section&gt;</code>, <code>&lt;article&gt;</code>, <code>&lt;aside&gt;</code>, and <code>&lt;footer&gt;</code> to provide clarity and structure to your content. Semantic elements improve accessibility, SEO, and maintainability of your code.</li>
</ul>
<ol start="3">
<li>Comment your code:</li>
</ol>
<ul>
<li>Use comments <code>&lt;!-- --&gt;</code> to document your HTML code, explaining its purpose and functionality. Comments improve code readability and facilitate collaboration among developers.</li>
</ul>
<ol start="4">
<li>Structure your content with proper tags:</li>
</ol>
<ul>
<li><p>Use heading tags <code>&lt;h1&gt;</code> to <code>&lt;h6&gt;</code> for defining the hierarchy of your content.</p>
</li>
<li><p>Utilize paragraph tags <code>&lt;p&gt;</code> to separate blocks of text into distinct paragraphs.</p>
</li>
<li><p>Employ lists (<code>&lt;ul&gt;</code>, <code>&lt;ol&gt;</code>, <code>&lt;li&gt;</code>) to organize and structure content in a hierarchical manner.</p>
</li>
</ul>
<ol start="5">
<li>Group elements with <code>&lt;div&gt;</code> and <code>&lt;span&gt;</code> sparingly:</li>
</ol>
<ul>
<li>Use <code>&lt;div&gt;</code> and <code>&lt;span&gt;</code> tags as needed to group and style elements, but avoid excessive nesting and over-reliance on these elements. Prefer more semantic alternatives where appropriate.</li>
</ul>
<ol start="6">
<li>Do not overuse line breaks (<code>&lt;br&gt;</code>):</li>
</ol>
<ul>
<li>While <code>&lt;br&gt;</code> tags can be useful for simple line breaks, avoid overusing them for layout purposes. Instead, use CSS and block-level elements for more complex layouts to maintain better code readability and maintainability.</li>
</ul>
<ol start="7">
<li>Always use alternative text for images (<code>alt</code> attribute):</li>
</ol>
<ul>
<li>Always include descriptive alternative text using the <code>alt</code> attribute for images (<code>&lt;img&gt;</code> tags). This improves accessibility for users with visual impairments and ensures that content remains understandable even if images fail to load.</li>
</ul>
<ol start="8">
<li>Optimize forms for user experience (UX):</li>
</ol>
<ul>
<li><p>Include meaningful <code>name</code> attributes for form elements to identify and process data accurately on the server.</p>
</li>
<li><p>Utilize appropriate input types (<code>type</code> attribute) for form fields to enhance user experience and ensure data validation.</p>
</li>
<li><p>Use the <code>placeholder</code> attribute to provide hints or expected input for form fields.</p>
</li>
</ul>
<ol start="9">
<li>Ensure compatibility with older browsers:</li>
</ol>
<ul>
<li><p>Your code should undergo <a target="_blank" href="https://www.freecodecamp.org/news/cross-browser-compatibility-testing-best-practices-for-web-developers/">compatibility testing</a> across different browsers and devices to ensure consistent rendering and functionality.</p>
</li>
<li><p>Include appropriate fallbacks for newer HTML features or attributes, this will help maintain compatibility with older browsers.</p>
</li>
</ul>
<ol start="10">
<li>Stay updated with HTML standards:</li>
</ol>
<ul>
<li>Keep yourself updated with the latest HTML standards and best practices to leverage new features, improve performance, and enhance the user experience of your web applications.</li>
</ul>
<p>By adhering to these best practices, you can create well-structured, accessible, and maintainable HTML code that contributes to the overall quality and usability of your web projects.</p>
<h4 id="heading-if-you-have-read-enjoyed-and-desire-more-of-this-piece-feel-free-to-reach-out-to-me-on-xhttpstwittercomcaswebdev-and-linkedinhttpswwwlinkedincomincasmir-onyekani-for-further-collaboration">If you have read, enjoyed, and desire more of this piece, feel free to reach out to me on <a target="_blank" href="https://twitter.com/casweb_dev">X</a> and <a target="_blank" href="https://www.linkedin.com/in/casmir-onyekani/">LinkedIn</a> for further collaboration.</h4>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The Difference Between <b> and <Strong> in HTML – Explained with Examples ]]>
                </title>
                <description>
                    <![CDATA[ Bold text is a common formatting technique used to grab attention and highlight important information on webpages.  In HTML, we have two seemingly interchangeable tags for bold formatting: <b> and <strong>. While they may achieve a similar visual out... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/difference-between-b-and-strong-in-html/</link>
                <guid isPermaLink="false">66c4c3c5bd556981b1bdc439</guid>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Joan Ayebola ]]>
                </dc:creator>
                <pubDate>Fri, 26 Apr 2024 23:24:38 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/04/Ivory-and-Blue-Lavender-Aesthetic-Photo-Collage-Presentation--6-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Bold text is a common formatting technique used to grab attention and highlight important information on webpages. </p>
<p>In HTML, we have two seemingly interchangeable tags for bold formatting: <code>&lt;b&gt;</code> and <code>&lt;strong&gt;</code>. While they may achieve a similar visual outcome, there's a crucial difference between them. </p>
<p>This article dives deep into the distinction between <code>&lt;b&gt;</code> and <code>&lt;strong&gt;</code> in HTML, exploring their semantic meaning, rendering, accessibility, and best practices for their use.</p>
<h2 id="heading-what-is-the-b-tag-in-html">What is the <code>b</code> Tag in HTML?</h2>
<p>The <code>&lt;b&gt;</code> tag is an HTML element used to apply bold formatting to text content. It stands for "bold" and is a part of the set of inline elements in HTML. When you wrap text within <code>&lt;b&gt;</code> tags, the enclosed text is rendered in a bold font style by web browsers.</p>
<p>But it's essential to note that the <code>&lt;b&gt;</code> tag doesn't convey any specific semantic meaning to the text it wraps. Unlike other elements like <code>&lt;strong&gt;</code>, which indicates strong importance or emphasis, the <code>&lt;b&gt;</code> tag is primarily used for stylistic purposes. It simply instructs the browser to display the enclosed text in bold, without implying any inherent significance or importance.</p>
<p>For example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is <span class="hljs-tag">&lt;<span class="hljs-name">b</span>&gt;</span>bold<span class="hljs-tag">&lt;/<span class="hljs-name">b</span>&gt;</span> text.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>This is <b>bold</b> text.</p>


<p>In this case, the word "bold" will be visually emphasized, but the <code>&lt;b&gt;</code> tag doesn't provide any additional information about why the text is bolded. Because of this, it's crucial to use the <code>&lt;b&gt;</code> tag judiciously, especially when conveying meaningful emphasis or importance in your HTML document.</p>
<h2 id="heading-what-is-the-strong-tag-in-html">What is the <code>strong</code> Tag in HTML?</h2>
<p>The <code>&lt;strong&gt;</code> tag is an HTML element used to denote text with strong importance, emphasis, or relevance. It is one of the semantic markup elements in HTML designed to convey meaning beyond mere presentation. </p>
<p>When you enclose text within <code>&lt;strong&gt;</code> tags, it tells web browsers and assistive technologies that the enclosed text should be treated as having strong importance or emphasis.</p>
<p>Unlike the <code>&lt;b&gt;</code> tag, which is primarily used for stylistic purposes to apply bold formatting, the <code>&lt;strong&gt;</code> tag carries semantic meaning. While browsers typically render text within <code>&lt;strong&gt;</code> tags in a bold font, the primary purpose of the tag is to provide additional context about the significance of the enclosed text.</p>
<p>For example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is <span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span>important<span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span> text.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>This is <strong>important</strong> text.</p>


<p>In this case, the word "important" is not only visually emphasized with a bold font but also marked as having strong importance or emphasis within the document structure. </p>
<p>This semantic meaning can be beneficial for accessibility purposes, as screen readers and other assistive technologies can interpret the significance of the text and convey it to users who may not be able to see the visual styling.</p>
<h2 id="heading-purpose-of-bold-text-formatting">Purpose of Bold Text Formatting</h2>
<p>The purpose of bold text formatting in HTML is primarily to visually emphasize certain words or phrases within a block of text. When text is formatted in bold, it stands out more prominently compared to the surrounding text, drawing the reader's attention to it. </p>
<p>This emphasis can serve various purposes, such as indicating importance, highlighting key points, or distinguishing headings and subheadings from body text.</p>
<p>Bold text formatting can be particularly useful for:</p>
<ul>
<li><strong>Highlighting Important Information:</strong> Bold text is often used to emphasize critical information or key concepts within a paragraph or document, making it easier for readers to identify and comprehend essential points.</li>
<li><strong>Improving Readability:</strong> By visually separating important elements from the rest of the text, bold formatting can enhance the overall readability of the content, especially in lengthy passages.</li>
<li><strong>Creating Visual Hierarchy:</strong> Bold text can help establish a hierarchy of information within a document, with headings and subheadings appearing bolder than regular text, thus guiding readers through the structure of the content.</li>
<li><strong>Emphasizing Call-to-Action:</strong> In web design, bold text is frequently used to draw attention to call-to-action (CTA) buttons or links, prompting users to take specific actions such as making a purchase, signing up for a newsletter, or navigating to another page.</li>
</ul>
<h2 id="heading-can-browser-styles-override">Can Browser Styles Override?</h2>
<p>Yes, browser styles can override the default rendering of HTML elements, including the <code>&lt;b&gt;</code> and <code>&lt;strong&gt;</code> tags.</p>
<p>Web browsers have their own default stylesheets (user agent stylesheets) that define how HTML elements should be displayed if no specific styles are provided by the webpage itself. These default stylesheets may specify the font size, font family, color, and other visual properties for various HTML elements.</p>
<p>When you use the <code>&lt;b&gt;</code> or <code>&lt;strong&gt;</code> tags without providing custom styles, browsers will typically apply their default styles for bold text. But these default styles can be overridden by CSS styles defined within the webpage's stylesheet or inline styles applied directly to the elements.</p>
<p>For example, if you have the following HTML:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is <span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span>important<span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span> text.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>And you apply custom CSS styles to override the default bold formatting:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">strong</span> {
    <span class="hljs-attribute">font-weight</span>: normal; <span class="hljs-comment">/* Override bold font weight */</span>
    <span class="hljs-attribute">color</span>: red; <span class="hljs-comment">/* Change text color */</span>
}
</code></pre>
<p>
</p>
<p></p>
<p>This is <strong>important</strong> text.</p>


<p>The text within the <code>&lt;strong&gt;</code> tag will no longer appear bold and will be displayed in red, as specified by the CSS rules.</p>
<p>Similarly, you can override the default styles for the <code>&lt;b&gt;</code> tag using CSS, although it's less common to do so since the <code>&lt;b&gt;</code> tag is typically used for purely presentational purposes without conveying semantic meaning.</p>
<p>Screen readers interpret the <code>&lt;strong&gt;</code> tag as indicating text with strong importance or emphasis. When encountering content enclosed within <code>&lt;strong&gt;</code> tags, screen reader software will typically announce the text with additional emphasis, indicating to users that the enclosed content is particularly important or relevant within the context of the document.</p>
<p>This semantic markup is crucial for accessibility purposes, as it enables users who rely on screen readers to understand the significance of the text without relying solely on visual cues. By conveying the importance or emphasis of the text through semantic markup like <code>&lt;strong&gt;</code>, screen readers can provide a more accurate and informative representation of the content to users who may be visually impaired or otherwise unable to view the visual styling of the webpage.</p>
<p>For example, if a screen reader encounters the following HTML:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is <span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span>important<span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span> text.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>It would announce the text "important" with additional emphasis, such as by adjusting the speech rate or volume, to indicate to the user that this particular text is of heightened significance within the document.</p>
<h2 id="heading-potential-issues-with">Potential Issues with <code>&lt;b&gt;</code></h2>
<p>Using the <code>&lt;b&gt;</code> tag can lead to several potential issues, particularly in terms of accessibility and semantic markup:</p>
<p><strong>Lack of Semantic Meaning:</strong> The <code>&lt;b&gt;</code> tag is purely presentational and does not convey any specific semantic meaning about the enclosed text. This can be problematic for users who rely on assistive technologies like screen readers to access web content, as the bold formatting provided by the <code>&lt;b&gt;</code> tag does not provide any indication of the importance or emphasis of the text.</p>
<p><strong>Accessibility Concerns:</strong> Screen readers may not interpret text enclosed within <code>&lt;b&gt;</code> tags as being more important or relevant than surrounding text, potentially leading to a loss of context or understanding for users with disabilities. Without semantic markup to convey the significance of the text, users may struggle to understand the intended meaning of the content.</p>
<p><strong>SEO Impact:</strong> Search engines may not give as much weight to content styled with the <code>&lt;b&gt;</code> tag compared to content marked up with semantic elements like <code>&lt;strong&gt;</code>. This could potentially affect search engine rankings, as search engines rely on semantic markup to understand the relevance and importance of content on webpages.</p>
<p><strong>Maintenance Challenges:</strong> Overuse of the <code>&lt;b&gt;</code> tag for purely presentational purposes can lead to maintenance challenges, as it may be difficult to distinguish between text that is bolded for stylistic reasons and text that is genuinely important or emphasized within the document. This lack of clarity can make it harder for developers to maintain and update the content in the future.</p>
<p>Overall, while the <code>&lt;b&gt;</code> tag can be useful for adding bold formatting to text, it's important to use it judiciously and consider the potential implications for accessibility, SEO, and document structure</p>
<h2 id="heading-does-impact-seo">Does <code>&lt;strong&gt;</code> Impact SEO?</h2>
<p>Yes, the <code>&lt;strong&gt;</code> tag can indirectly impact SEO (Search Engine Optimization) in several ways, while using <code>&lt;strong&gt;</code> may indirectly impact SEO by improving content readability and accessibility, it's not a direct ranking factor.</p>
<p><strong>Semantic Markup:</strong> Search engines like Google aim to understand the content of web pages to deliver relevant search results to users. Semantic markup, such as the <code>&lt;strong&gt;</code> tag, provides additional context and clarity about the importance or emphasis of text within a document. When you use <code>&lt;strong&gt;</code>, you're signaling to search engines that the enclosed text is of strong importance or relevance, potentially influencing how they interpret and index your content.</p>
<p><strong>Content Readability:</strong> Clear and well-structured content improves readability, which is a key factor in SEO. By using <code>&lt;strong&gt;</code> to emphasize important keywords or phrases, you can enhance the readability and comprehension of your content for both users and search engines.</p>
<p><strong>User Engagement:</strong> Content that effectively communicates key points using semantic markup like <code>&lt;strong&gt;</code> may result in increased user engagement, such as longer time spent on the page or higher click-through rates. Search engines may consider user engagement metrics as indicators of content quality, which can positively impact SEO rankings.</p>
<p><strong>Accessibility:</strong> Semantic markup improves accessibility for users with disabilities, including those using screen readers. By properly marking up important content with <code>&lt;strong&gt;</code>, you're ensuring that all users, regardless of their abilities, can understand the significance of the text. Improved accessibility can lead to better user experiences, potentially resulting in higher rankings in search engine results pages (SERPs).</p>
<h3 id="heading-when-to-use">When to Use <code>&lt;strong&gt;</code></h3>
<p>You should use the <code>&lt;strong&gt;</code> tag when you want to emphasize text that carries strong importance or relevance within the context of your document. Here are some scenarios when using <code>&lt;strong&gt;</code> would be appropriate:</p>
<ul>
<li><strong>Important Keywords:</strong> Use <code>&lt;strong&gt;</code> to highlight important keywords or phrases that are central to the topic or main point of your content. This helps both readers and search engines understand the significance of those terms.</li>
<li><strong>Key Points:</strong> Use <code>&lt;strong&gt;</code> to emphasize key points, arguments, or conclusions within your content. This draws attention to critical information and makes it more memorable for readers.</li>
<li><strong>Warnings or Notices:</strong> Use <code>&lt;strong&gt;</code> to highlight warnings, notices, or alerts that require immediate attention from your audience. This ensures that important messages stand out and are not overlooked.</li>
<li><strong>Calls to Action:</strong> Use <code>&lt;strong&gt;</code> to emphasize calls to action (CTAs) such as "Buy Now," "Sign Up," or "Learn More." This encourages user engagement and increases the likelihood of conversion.</li>
<li><strong>Headings and Subheadings:</strong> Use <code>&lt;strong&gt;</code> within headings and subheadings to give them additional emphasis and hierarchy within your document structure. This helps users quickly scan and understand the organization of your content.</li>
<li><strong>Quotations or Citations:</strong> Use <code>&lt;strong&gt;</code> to emphasize quotations or citations from authoritative sources, indicating their importance or relevance to your content.</li>
</ul>
<h3 id="heading-when-might-be-acceptable">When Might <code>&lt;b&gt;</code> Be Acceptable?</h3>
<p><code>&lt;b&gt;</code> might be acceptable for purely stylistic bold formatting when no specific semantic meaning is intended.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In conclusion, understanding the subtle yet crucial differences between <code>&lt;b&gt;</code> and <code>&lt;strong&gt;</code> is essential for crafting well-structured and semantic HTML. </p>
<p>By prioritizing the <code>&lt;strong&gt;</code> tag for conveying importance and reserving <code>&lt;b&gt;</code> for situations where emphasis is purely visual, you contribute to a clearer and more accessible web experience for all users. </p>
<p>Remember, semantic HTML not only benefits users with disabilities but can also play a role in search engine optimization. So, make a conscious choice: use <code>&lt;strong&gt;</code> to highlight what truly matters, and leverage CSS for fine-tuning the visual presentation of your bold text. </p>
<p>By embracing semantic coding practices, you'll create webpages that are not only informative but also speak a clear language to both users and search engines.</p>
<p>Connect with me on <a target="_blank" href="https://ng.linkedin.com/in/joan-ayebola">LinkedIn</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Add Media to Your HTML Email Template ]]>
                </title>
                <description>
                    <![CDATA[ In my previous article, "How to Create a Responsive HTML Email Template," we explored the fundamentals of designing and coding a simple HTML email template that adapts beautifully across different devices and email clients.  I got a couple of questio... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-add-media-to-your-html-email-template/</link>
                <guid isPermaLink="false">66ba1be1b6a437d5f189cf83</guid>
                
                    <category>
                        <![CDATA[ email ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Fanny Nyayic ]]>
                </dc:creator>
                <pubDate>Tue, 23 Apr 2024 17:40:54 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/04/Add-Media-to-Your-HTML-Email-Template.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In my previous article, "<a target="_blank" href="https://www.freecodecamp.org/news/how-to-create-a-responsive-html-email-template/">How to Create a Responsive HTML Email Template</a>," we explored the fundamentals of designing and coding a simple HTML email template that adapts beautifully across different devices and email clients. </p>
<p>I got a couple of questions about adding media to the HTML email template.</p>
<p>Building on that foundation, I'll guide you through different ways of adding media to your HTML email template. Adding media such as images, videos, and audio can significantly increase the engagement and effectiveness of your communications. </p>
<h3 id="heading-requirements">Requirements</h3>
<ul>
<li>A simple HTML email template. You can create one following <a target="_blank" href="https://www.freecodecamp.org/news/how-to-create-a-responsive-html-email-template/">this guide</a>. </li>
</ul>
<h2 id="heading-how-to-add-images-to-your-email-template">How to Add Images to Your Email Template</h2>
<p>Images are the most common type of media added to emails. Here's how to include them in your HTML email templates:</p>
<ul>
<li>Before adding an image, ensure it is properly sized and optimized for web use. A common practice is to keep the image width under 600 pixels to fit most email clients without scaling. For this particular example we have a stock image and resized it to 600 x 750 pixels as shown below.</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/600x750.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>this is the image we shall be uploading</em></p>
<ul>
<li>Upload your image to a reliable web server or content delivery network (CDN). You'll need a stable URL to reference in your email.  </li>
</ul>
<p>For this example we'll use <a target="_blank" href="https://imgbb.com/">the imgbb website</a> and upload our image. Click on "Start Uploading<em>"</em> and choose the image.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/screely-1713853483929.png" alt="Image" width="600" height="400" loading="lazy">
<em>imgbb is one of the free image hosting platforms</em></p>
<p>After choosing the image to use, select "Don't Autodelete" and click on Upload.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/screely-1713853781152.png" alt="Image" width="600" height="400" loading="lazy">
<em>Choose Don't Autodelete from the dropdown</em></p>
<p>After uploading, a URL will be generated. Click on the dropdown and choose "HTML full linked"</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/screely-1713854879006-copy-code.png" alt="Image" width="600" height="400" loading="lazy">
<em>The embed code generated</em></p>
<ul>
<li>Copy the HTML code generated and insert it within a desired section in your email template as shown.</li>
</ul>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://ibb.co/XpRp2N8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://i.ibb.co/q9Q9yX5/600x750.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"600x750"</span> <span class="hljs-attr">border</span>=<span class="hljs-string">"0"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<p>Feel free to try out other embed code options to test how your image will appear in the email template. </p>
<p>Below is the outcome of the inserted image:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/screely-1713854742721.png" alt="Image" width="600" height="400" loading="lazy">
<em>image successfully inserted to our email template</em></p>
<p><strong>Note</strong>: Always include the <code>alt</code> attribute to provide alternative text for scenarios where the image cannot be displayed.</p>
<h2 id="heading-how-to-embed-videos-in-your-email-template">How to Embed Videos in Your Email Template</h2>
<p>Direct video playback is not supported in most email clients. Instead, you can embed a clickable thumbnail that links to a video hosted online:</p>
<ul>
<li><strong>Create a Thumbnail</strong>: Capture a frame from your video or create a custom graphic that represents the video content. This will act as a placeholder. In this example, we'll use the same image as the thumbnail.</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/screely-1713855881423-thumbnail.png" alt="Image" width="600" height="400" loading="lazy"></p>
<ul>
<li>From the dropdown, choose HTML thumbnail linked. Copy the code and paste it to your email template.</li>
</ul>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://ibb.co/XpRp2N8"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://i.ibb.co/XpRp2N8/600x750.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"600x750"</span> <span class="hljs-attr">border</span>=<span class="hljs-string">"0"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<ul>
<li><strong>Link to the Video</strong>: Modify the above code to use the thumbnail as a clickable image linked to the video URL. </li>
<li>Change the URL in the <code>&lt;a href =""&gt;</code> to the video link as shown below.</li>
</ul>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://youtu.be/UG8rjxYBfFg?si=xU2zqCtQW5-2z7nw"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://i.ibb.co/XpRp2N8/600x750.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"600x750"</span> <span class="hljs-attr">border</span>=<span class="hljs-string">"0"</span>&lt;/<span class="hljs-attr">a</span>&gt;</span>
</code></pre>
<p>This HTML snippet creates a linked image without a border. And this is how it will appear in our email Template:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/screely-1713856590062-thumbnail.png" alt="Image" width="600" height="400" loading="lazy">
<em>linked thumbnail will appear like this</em></p>
<h2 id="heading-how-to-embed-youtube-videos-in-your-email-template">How to Embed YouTube Videos in Your Email Template</h2>
<p>Alternatively you can directly embed a YouTube video to your email template. Here is how:</p>
<ul>
<li>Go to YouTube and choose the video you would like to embed.</li>
<li>Click on <strong>share -&gt; embed</strong> and an <code>iframe</code> will be generated. Below is an example:</li>
</ul>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">iframe</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"560"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"315"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://www.youtube.com/embed/UG8rjxYBfFg?si=nYBBM032nvBn5tNZ"</span> <span class="hljs-attr">title</span>=<span class="hljs-string">"YouTube video player"</span> <span class="hljs-attr">frameborder</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">allow</span>=<span class="hljs-string">"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"</span> <span class="hljs-attr">referrerpolicy</span>=<span class="hljs-string">"strict-origin-when-cross-origin"</span> <span class="hljs-attr">allowfullscreen</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">iframe</span>&gt;</span>
</code></pre>
<ul>
<li>Copy the <code>iframe</code> and paste it to a <code>&lt;td&gt;</code> section of your HTML email template code. And you will have something looking like this:</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/screely-1713857296270-youtube.png" alt="Image" width="600" height="400" loading="lazy">
<em>this is an example of a youtube video within an email template</em></p>
<h2 id="heading-how-to-add-audio-to-your-email-template">How to Add Audio to Your Email Template</h2>
<p>Adding audio files directly to emails is also not supported by most email clients. Similar to videos, you can include a link to the audio file:</p>
<ul>
<li><strong>Host the Audio File</strong>: Upload your audio file to a suitable platform or server. There are a number of audio platforms out there, like Google Drive, your own website, YouTube, sound cloud, and so on.</li>
<li>For this example, we'll use a platform called <a target="_blank" href="https://audio.com/">audio.com</a>. Simply create an account by clicking  "join now for free" or sign in if you already have an account.</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/screely-1713861900834.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p> Click upload and choose your .mp3 file which will be stored in your account. Once the audio is complete, click on the share icon.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/screely-1713862121050.png" alt="Image" width="600" height="400" loading="lazy"></p>
<ul>
<li>This will bring you to a couple of options where you can copy the link or simply embed the link:</li>
</ul>
<p>Click on embed, and you will see a preview of how your audio will appear. Copy the code and paste it to your email template section.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/screely-1713862229377.png" alt="Image" width="600" height="400" loading="lazy">
<em>code generated by audio.com which can be embedded in the email template</em></p>
<p>You can also eliminate the <code>div</code> and just use the <code>iframe</code> . Also feel free to remove parts you would not want to appear in the email template and customize it to your preference. </p>
<p>Here is the code:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"height: 228px; width: 600px;"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">iframe</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://audio.com/embed/audio/1797114509131910?theme=image"</span>
                            <span class="hljs-attr">style</span>=<span class="hljs-string">"display:block; border-radius: 6px; border: none; height: 204px; width: 600px;"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">iframe</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">'https://audio.com/nyayic-fanny'</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"text-align: center; display: block; color: #A4ABB6; font-size: 12px; font-family: sans-serif; line-height: 16px; margin-top: 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"</span>&gt;</span>@nyayic-fanny<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>This is our final outcome for the above:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/screely-1713862296389.png" alt="Image" width="600" height="400" loading="lazy">
<em>our audio will appear like this in our email template</em></p>
<h3 id="heading-using-audio-tag">Using <code>audio</code> tag</h3>
<p>Besides embedding, we can use the audio tag and just add the URL  to our audio source as shown below: </p>
<pre><code class="lang-html"> <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Audio added via audio tag<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">audio</span> <span class="hljs-attr">controls</span>=<span class="hljs-string">"controls"</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">source</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://audio.com/nyayic-fanny/audio/past-life-jvna.mp3"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>? Listen: <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://audio.com/nyayic-fanny/audio/past-life-jvna.mp3"</span>&gt;</span>Audio<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span> (mp3)<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
       <span class="hljs-tag">&lt;/<span class="hljs-name">audio</span>&gt;</span>
</code></pre>
<p>Just change the URL to your <code>audio url</code> . And this is how our entire modification should look.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/final-newsletter.png" alt="Image" width="600" height="400" loading="lazy">
<em>our modified html email template</em></p>
<p><strong>Note:</strong> Hotmail and clients that don’t support HTML5 will not work!</p>
<h2 id="heading-best-practices-for-media-in-html-emails">Best Practices for Media in HTML Emails</h2>
<p>When integrating media into HTML emails, consider the following tips to optimize compatibility and user experience:</p>
<ul>
<li>Always use full, absolute URLs for images, videos, and audio to ensure they load correctly in all email clients.</li>
<li>Test Your Emails: Different email clients display HTML content in various ways. Use tools like Litmus or Email on Acid to test how your email renders across different platforms.</li>
<li>Keep Load Times in Mind: Optimize media file sizes to ensure that your emails load quickly, which is crucial for retaining the recipient's attention and improving engagement.</li>
<li>Consider Accessibility: Provide descriptive alt text for images and captions or transcripts for audio and video content.</li>
</ul>
<p>While there are limitations to what email clients can support, using linked images for videos and audio files provides a user-friendly solution that works across most platforms. </p>
<p>Always ensure you test your emails thoroughly and follow best practices to ensure a smooth and engaging user experience.</p>
<p>Happy Coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Create a Responsive HTML Email Template ]]>
                </title>
                <description>
                    <![CDATA[ In this beginner-friendly guide, you'll learn how to create a responsive email template. You'll follow step-by-step instructions with code snippets to design an email template that looks great on any device.  This project is perfect for newcomers eag... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-create-a-responsive-html-email-template/</link>
                <guid isPermaLink="false">66ba1be84067550ef786869e</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ email ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ projects ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Fanny Nyayic ]]>
                </dc:creator>
                <pubDate>Mon, 15 Apr 2024 23:11:04 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/04/create-html-email-template-from-scratch.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this beginner-friendly guide, you'll learn how to create a responsive email template. You'll follow step-by-step instructions with code snippets to design an email template that looks great on any device. </p>
<p>This project is perfect for newcomers eager to master email design basics!</p>
<h2 id="heading-step-1-set-up-the-basic-structure">Step 1: Set Up the Basic Structure</h2>
<p>To build an email template, you can start with a basic HTML structure. This includes a <code>DOCTYPE</code> declaration for emails, defining the <code>head</code> and <code>body</code> sections, and using meta tags in the <code>head</code> section to ensure proper mobile rendering and zooming.</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Responsive Email Template<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- Email content goes here --&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<h2 id="heading-step-2-create-the-email-structure">Step 2: Create the Email Structure</h2>
<p>Use tables to create the basic structure of your email. This will ensure compatibility across different email clients.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"100%"</span> <span class="hljs-attr">cellpadding</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">cellspacing</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">border</span>=<span class="hljs-string">"0"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">align</span>=<span class="hljs-string">"center"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"600"</span> <span class="hljs-attr">cellpadding</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">cellspacing</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">border</span>=<span class="hljs-string">"0"</span>&gt;</span>
                <span class="hljs-comment">&lt;!-- Email content goes here --&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
</code></pre>
<h2 id="heading-step-3-add-content-and-inline-styles">Step 3: Add Content and Inline Styles</h2>
<p>Email clients vary in how they render CSS, so it's safer to use inline styles. Here's an example of a simple email body:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">body</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"font-family: 'Poppins', Arial, sans-serif"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"100%"</span> <span class="hljs-attr">border</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">cellspacing</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">cellpadding</span>=<span class="hljs-string">"0"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">align</span>=<span class="hljs-string">"center"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"padding: 20px;"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"content"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"600"</span> <span class="hljs-attr">border</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">cellspacing</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">cellpadding</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"border-collapse: collapse; border: 1px solid #cccccc;"</span>&gt;</span>
                    <span class="hljs-comment">&lt;!-- Header --&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"header"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"background-color: #345C72; padding: 40px; text-align: center; color: white; font-size: 24px;"</span>&gt;</span>
                        Responsive Email Template
                        <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>

                    <span class="hljs-comment">&lt;!-- Body --&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"body"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"padding: 40px; text-align: left; font-size: 16px; line-height: 1.6;"</span>&gt;</span>
                        Hello, All! <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
                        Lorem odio soluta quae dolores sapiente voluptatibus recusandae aliquam fugit ipsam.
                        <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
                            Lorem ipsum dolor sit amet consectetur adipisicing elit. Veniam corporis sint eum nemo animi velit exercitationem impedit. Incidunt, officia facilis  atque? Ipsam voluptas fugiat distinctio blanditiis veritatis.            
                        <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>

                    <span class="hljs-comment">&lt;!-- Call to action Button --&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"padding: 0px 40px 0px 40px; text-align: center;"</span>&gt;</span>
                            <span class="hljs-comment">&lt;!-- CTA Button --&gt;</span>
                            <span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">cellspacing</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">cellpadding</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"margin: auto;"</span>&gt;</span>
                                <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
                                    <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">align</span>=<span class="hljs-string">"center"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"background-color: #345C72; padding: 10px 20px; border-radius: 5px;"</span>&gt;</span>
                                        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://www.yourwebsite.com"</span> <span class="hljs-attr">target</span>=<span class="hljs-string">"_blank"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"color: #ffffff; text-decoration: none; font-weight: bold;"</span>&gt;</span>Book a Free Consulatation<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
                                    <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
                                <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
                            <span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
                        <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"body"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"padding: 40px; text-align: left; font-size: 16px; line-height: 1.6;"</span>&gt;</span>
                            Lorem ipsum dolor sit amet consectetur adipisicing elit. Veniam corporis sint eum nemo animi velit exercitationem impedit.             
                        <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
                    <span class="hljs-comment">&lt;!-- Footer --&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"footer"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"background-color: #333333; padding: 40px; text-align: center; color: white; font-size: 14px;"</span>&gt;</span>
                        Copyright <span class="hljs-symbol">&amp;copy;</span> 2024 | Your brand name
                        <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre>
<p>Here's a breakdown of the main elements and their functions:</p>
<h3 id="heading-body-tag-and-font-setup">Body Tag and Font Setup</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">body</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"font-family: 'Poppins', Arial, sans-serif"</span>&gt;</span>
</code></pre>
<p>This sets the default font for the email to 'Poppins', with fallbacks to Arial and sans-serif if 'Poppins' isn't available.</p>
<h3 id="heading-table-structure">Table Structure</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"100%"</span> <span class="hljs-attr">border</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">cellspacing</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">cellpadding</span>=<span class="hljs-string">"0"</span>&gt;</span>
</code></pre>
<p>This is the outermost table that takes up 100% of the email's width. The <code>border</code>, <code>cellspacing</code>, and <code>cellpadding</code> are set to 0 to remove default styling and spacing.</p>
<p>Nested inside this table is another <code>&lt;table class="content"&gt;</code> with a fixed width of 600px, centered by its parent with <code>td align="center"</code>. </p>
<p>This inner table includes a border and specific styling, defining it as the main content area.</p>
<h3 id="heading-the-header-section">The Header Section</h3>
<p>The header is styled with a dark blue background using inline CSS (#345C72), white text color, and larger text size (24px). It’s designed to grab attention right at the beginning of the email. </p>
<p><strong>Note</strong><em><strong>:</strong></em> You can customize this section with your brand name or logo instead.</p>
<h3 id="heading-the-body-content">The Body Content</h3>
<p>The body section contains the main message of the email, set in a font size of 16px and line height of 1.6 for better readability. The content is aligned to the left, and the use of <code>&lt;br&gt;</code> tags helps in spacing out the lines.</p>
<h3 id="heading-call-to-action-cta-button">Call to Action (CTA) Button</h3>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!-- Call to action Button --&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"padding: 0px 40px 0px 40px; text-align: center;"</span>&gt;</span>
                            <span class="hljs-comment">&lt;!-- CTA Button --&gt;</span>
                            <span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">cellspacing</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">cellpadding</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"margin: auto;"</span>&gt;</span>
                                <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
                                    <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">align</span>=<span class="hljs-string">"center"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"background-color: #345C72; padding: 10px 20px; border-radius: 5px;"</span>&gt;</span>
                                        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://www.yourwebsite.com"</span> <span class="hljs-attr">target</span>=<span class="hljs-string">"_blank"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"color: #ffffff; text-decoration: none; font-weight: bold;"</span>&gt;</span>Book a Free Consulatation<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
                                    <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
                                <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
                            <span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
                        <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
</code></pre>
<p>The CTA button here is designed to stand out with a background color that matches the header, rounded corners (<code>border-radius: 5px</code>), and bold, white text. </p>
<p>The <code>&lt;a&gt;</code> tag within the button is styled to remove the default underline (<code>text-decoration: none</code>) and is linked to a webpage where recipients can "Book a Free Consultation."</p>
<h3 id="heading-footer">Footer</h3>
<p>The footer repeats the styling approach of the header but uses a darker background (#333333) and smaller font size (14px). It can contain copyright information and links or other contact details.</p>
<h3 id="heading-illustration">Illustration</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/email-template-illustration.png" alt="Image" width="600" height="400" loading="lazy">
<em>illustration of the different parts of the template: header, CTA button, and footer</em></p>
<h2 id="heading-step-4-make-it-responsive">Step 4: Make It Responsive</h2>
<p>To ensure the email looks good on mobile devices, you can use CSS media queries. While most of the styling are inline, for responsive behavior, you'll need to add a <code>&lt;style&gt;</code> block in the <code>head</code>. </p>
<p>Media queries adjust styles based on the device's width.</p>
<pre><code class="lang-css">&lt;<span class="hljs-selector-tag">style</span>&gt;
  <span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">600px</span>) {
    <span class="hljs-selector-class">.content</span> {
        <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span> <span class="hljs-meta">!important</span>;
        <span class="hljs-attribute">display</span>: block <span class="hljs-meta">!important</span>;
        <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span> <span class="hljs-meta">!important</span>;
    }
    <span class="hljs-selector-class">.header</span>, <span class="hljs-selector-class">.body</span>, <span class="hljs-selector-class">.footer</span> {
        <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span> <span class="hljs-meta">!important</span>;
    }
  }
&lt;/<span class="hljs-selector-tag">style</span>&gt;
</code></pre>
<p>Here’s a breakdown of this specific CSS snippet:</p>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">600px</span>) { ... }
</code></pre>
<p>This media query targets screens with a maximum width of 600 pixels. It applies the following styles only when the email is viewed on devices with a screen width of 600px or less, which typically includes smartphones and some smaller tablets.</p>
<p>Styles within the media query classes:</p>
<h3 id="heading-content">.content</h3>
<ul>
<li><code>width_: 100% !important;_</code> : This style changes the width of the <code>.content</code> table to use the full width of the screen instead of the 600px specified in the HTML. The <code>!important</code> rule is used to override any other conflicting styles.</li>
<li><code>display: block !important;</code>: Although <code>&lt;table&gt;</code> elements are naturally block-level elements, setting <code>display: block</code> explicitly can help in some email clients to ensure the element behaves as expected.</li>
<li><code>padding: 10px !important;</code>: Adds padding around the content within the <code>.content</code> table, reducing it from the original 40px in the HTML to make better use of the reduced screen space on smaller devices.</li>
</ul>
<h3 id="heading-header-body-footer">.header, .body, .footer</h3>
<ul>
<li><code>padding: 20px !important;</code>: This style uniformly sets the padding of the <em>header, body, and footer</em> sections to <em>20px</em> on all sides, optimizing the spacing for smaller screens. It overrides the various padding settings defined in the HTML, which include larger values in some cases.</li>
</ul>
<p>In the context of email design, the use of <strong>!important</strong> is fairly common to ensure that the styles are applied as intended, overriding both default styles and other potentially conflicting styles that might be applied by the email client itself. </p>
<h2 id="heading-step-5-test-across-email-clients">Step 5: Test Across Email Clients</h2>
<p>It's crucial to test your email template across different email clients (like Gmail, Outlook, and Apple Mail) and devices to ensure compatibility and responsiveness. Tools like Litmus or Email on Acid can help with this.</p>
<h2 id="heading-step-6-adding-google-font">Step 6: Adding Google Font</h2>
<p>Incorporating Google Fonts into an HTML email template can improve its visual appeal significantly. </p>
<p>However, it's important to note that not all email clients support web fonts. Some, like Apple Mail, do support Google Fonts, but others like Gmail do not. To ensure your email looks great to all recipients, always provide a fallback font.</p>
<p>Here's how you can add a Google Font to your email template, along with a fallback option for clients that don't support it:</p>
<h3 id="heading-choose-your-google-font">Choose Your Google Font</h3>
<p>First, visit the <a target="_blank" href="https://fonts.google.com/">Google Fonts</a> website and choose a font. For this example, let's use <em>"Poppins".</em></p>
<h3 id="heading-add-the-font-link-to-your-email-head">Add the Font Link to Your Email Head</h3>
<p>Include the link to the Google Font in the <code>&lt;head&gt;</code> of your HTML document. Since this might not be supported in all email clients, ensure you have a suitable fallback font in your styles.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"preconnect"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://fonts.googleapis.com"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"preconnect"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://fonts.gstatic.com"</span> <span class="hljs-attr">crossorigin</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&amp;display=swap"</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span>&gt;</span>
</code></pre>
<h3 id="heading-apply-the-font-in-your-styles">Apply the Font in Your Styles</h3>
<p>Use inline CSS to apply the Google Font to your HTML elements, and always include a generic fallback font. In email templates, it's safer to apply styles inline due to varying support for <code>&lt;style&gt;</code> tags across email clients. </p>
<p>Here's how to apply the font to the <code>body</code> of your email and include a fallback:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">body</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"font-family: 'Poppins', Arial, sans-serif;"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"100%"</span> <span class="hljs-attr">cellspacing</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">cellpadding</span>=<span class="hljs-string">"0"</span>&gt;</span>
        <span class="hljs-comment">&lt;!-- Email content --&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre>
<h2 id="heading-what-we-created">What We Created</h2>
<p>Below is a screenshot of the email template we designed. It features a professional layout with a header containing a logo placeholder, a main body section for your message, and a dark footer with contact and subscription management links. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/email-template.png" alt="Image" width="600" height="400" loading="lazy">
<em>screenshot of the email template</em></p>
<h2 id="heading-additional-tips">Additional Tips:</h2>
<ul>
<li>Keep your CSS inline as much as possible, because many email clients do not support <code>&lt;style&gt;</code> tags.</li>
<li>Use web-safe fonts to ensure that your text appears correctly in all email clients.</li>
<li>Always provide a plain text version of your email for clients that don't support HTML, or have HTML disabled.</li>
</ul>
<p>I hope this guide provides you with a basic framework for creating a responsive email template. As you become more comfortable with email design, you can experiment with more complex layouts and styles.  </p>
<p><em><strong>Happy Coding!</strong></em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Virtual DOM vs Shadow DOM – What's the Difference? ]]>
                </title>
                <description>
                    <![CDATA[ In web development, understanding the inner workings of the Document Object Model (DOM) is crucial. Two concepts that often come up in discussions about DOM are Virtual DOM and Shadow DOM. While they sound similar, they serve different purposes and h... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/virtual-dom-vs-shadow-dom/</link>
                <guid isPermaLink="false">66c4c417e486f65d4125b803</guid>
                
                    <category>
                        <![CDATA[ Document Object Model ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Joan Ayebola ]]>
                </dc:creator>
                <pubDate>Mon, 18 Mar 2024 08:22:16 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/03/Ivory-and-Blue-Lavender-Aesthetic-Photo-Collage-Presentation--13-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In web development, understanding the inner workings of the Document Object Model (DOM) is crucial. Two concepts that often come up in discussions about DOM are Virtual DOM and Shadow DOM.</p>
<p>While they sound similar, they serve different purposes and have distinct characteristics. </p>
<p>In this comprehensive guide, we'll delve into the intricacies of Virtual DOM and Shadow DOM, highlighting their differences with simple explanations and illustrative code snippets.</p>
<h3 id="heading-table-of-contents">Table of Contents</h3>
<ol>
<li><strong><a class="post-section-overview" href="#heading-introduction-to-dom">Introduction to DOM</a></strong></li>
<li><strong><a class="post-section-overview" href="#heading-what-is-virtual-dom">What is Virtual DOM?</a></strong><br>– <a class="post-section-overview" href="#heading-how-virtual-dom-works">How Virtual DOM Works</a></li>
<li><a class="post-section-overview" href="#what-is-shallow-dom"><strong>What is Shadow DOM?</strong></a><br>– <a class="post-section-overview" href="#understanding-shallow-dom">Understanding Shadow DOM</a></li>
<li><a class="post-section-overview" href="#differences-between-virtual-dom-and-shallow-dom"><strong>Differences Between Virtual DOM and Shadow DOM</strong></a></li>
<li><strong><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></strong></li>
</ol>
<h2 id="heading-introduction-to-dom">Introduction to DOM</h2>
<p>Before we dive into Virtual DOM and Shadow DOM, let's briefly discuss what the Document Object Model (DOM) is. </p>
<p>The DOM represents the structure of an HTML document as a tree-like structure, where each node represents an element, attribute, or text within the document. JavaScript can manipulate the DOM dynamically, enabling developers to create interactive web pages.</p>
<h2 id="heading-what-is-virtual-dom">What is Virtual DOM?</h2>
<p>The Virtual DOM is a concept used by libraries like React to improve the performance of web applications. It's essentially a lightweight copy of the actual DOM, maintained by the framework. </p>
<p>When changes are made to the application state, React creates a new Virtual DOM representation and compares it with the previous one to identify the differences (known as "diffing"). Only the necessary changes are then applied to the real DOM, resulting in efficient updates.</p>
<h3 id="heading-how-virtual-dom-works">How Virtual DOM Works</h3>
<p>Let's consider a simple example to understand how Virtual DOM works in React:</p>
<pre><code class="lang-jsx"><span class="hljs-comment">// Initial render</span>
<span class="hljs-keyword">const</span> element = <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Hello, world!<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>;
ReactDOM.render(element, <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'root'</span>));

<span class="hljs-comment">// Update</span>
<span class="hljs-keyword">const</span> updatedElement = <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Hello, world! Updated.<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>;
ReactDOM.render(updatedElement, <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'root'</span>));
</code></pre>
<p>In this example, React creates a Virtual DOM representation of the <code>element</code>. When an update occurs, it creates a new Virtual DOM representation of the <code>updatedElement</code>. </p>
<p>React then compares the two Virtual DOM representations to identify the difference (in this case, the text content change). Finally, React updates the real DOM with the necessary changes, resulting in an efficient update process.</p>
<h2 id="heading-what-is-shadow-dom">What is Shadow DOM?</h2>
<p>Shadow DOM is a term used to describe a limited or restricted view of the DOM tree. Unlike the Virtual DOM, which is a concept used to optimize performance, Shadow DOM refers to a specific structure within the DOM tree itself.</p>
<h3 id="heading-understanding-shadow-dom">Understanding Shadow DOM</h3>
<p>Consider a scenario where you have a custom web component encapsulated with Shadow DOM:</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Shadow DOM Example<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">my-custom-element</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">my-custom-element</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
    <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyCustomElement</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">HTMLElement</span> </span>{
      <span class="hljs-keyword">constructor</span>() {
        <span class="hljs-built_in">super</span>();
        <span class="hljs-keyword">const</span> shadow = <span class="hljs-built_in">this</span>.attachShadow({ <span class="hljs-attr">mode</span>: <span class="hljs-string">'open'</span> });
        <span class="hljs-keyword">const</span> span = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">'span'</span>);
        span.textContent = <span class="hljs-string">'Hello, Shadow DOM!'</span>;
        shadow.appendChild(span);
      }
    }
    customElements.define(<span class="hljs-string">'my-custom-element'</span>, MyCustomElement);
  </span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>In this example, we define a custom element <code>my-custom-element</code> that encapsulates its content within Shadow DOM using the <code>attachShadow</code> method. The content inside the shadow root is isolated from the rest of the document, creating a boundary known as the Shadow DOM.</p>
<h2 id="heading-differences-between-virtual-dom-and-shadow-dom">Differences Between Virtual DOM and Shadow DOM</h2>
<p>Now that you have a basic understanding of the Virtual DOM and Shadow DOM, let's compare them based on different aspects:</p>
<h3 id="heading-purpose">Purpose</h3>
<ul>
<li><strong>Virtual DOM</strong>: Primarily aimed at improving performance by minimizing the number of DOM manipulations required during updates.</li>
<li><strong>Shadow DOM</strong>: Focuses on encapsulating the style and behavior of web components, providing a scoped environment for CSS and JavaScript.</li>
</ul>
<h3 id="heading-implementation">Implementation</h3>
<ul>
<li><strong>Virtual DOM</strong>: Implemented by libraries/frameworks like React, Vue.js, and Angular to facilitate efficient updates of the real DOM.</li>
<li><strong>Shadow DOM</strong>: Implemented natively by web browsers to support encapsulation of web components with Shadow DOM.</li>
</ul>
<h3 id="heading-performance">Performance</h3>
<ul>
<li><strong>Virtual DOM</strong>: Offers performance benefits by reducing the number of DOM manipulations, resulting in faster updates and rendering.</li>
<li><strong>Shadow DOM</strong>: While Shadow DOM itself doesn't directly impact performance, it can enhance performance by isolating component styles and behavior.</li>
</ul>
<h3 id="heading-isolation">Isolation</h3>
<ul>
<li><strong>Virtual DOM</strong>: Doesn't provide isolation by itself but helps in minimizing unintended side effects of DOM updates through its efficient diffing algorithm.</li>
<li><strong>Shadow DOM</strong>: Provides encapsulation and isolation for the content of web components, preventing style and behavior leakage to the rest of the document.</li>
</ul>
<h3 id="heading-usage">Usage</h3>
<ul>
<li><strong>Virtual DOM</strong>: Commonly used in modern JavaScript frameworks like React, where components are re-rendered efficiently based on state changes.</li>
<li><strong>Shadow DOM</strong>: Utilized when creating custom web components with encapsulated styles and behavior, ensuring modularity and reusability.</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In conclusion, both Virtual DOM and Shadow DOM play significant roles in web development, albeit in different contexts. While Virtual DOM focuses on optimizing DOM updates for performance, Shadow DOM provides encapsulation and isolation for web components, enhancing modularity and maintainability. </p>
<p>Understanding the differences between these concepts is crucial for building efficient and scalable web applications.</p>
<p>By leveraging Virtual DOM in frameworks like React and embracing Shadow DOM for encapsulating web components, developers can create robust and maintainable web applications that offer optimal performance and scalability. </p>
<p>As web technologies continue to evolve, having a solid understanding of these concepts will remain invaluable in web development.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use HTML Forms – HTML Form Basics ]]>
                </title>
                <description>
                    <![CDATA[ By Kelechukwu Isaac Awoke HTML forms are used to get information from users. They are widely used in webpages or apps for surveys or registration processes.  HTML form basics include the common HTML elements, tags, attributes, concepts, or best pract... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-html-forms/</link>
                <guid isPermaLink="false">66d45f63264384a65d5a954a</guid>
                
                    <category>
                        <![CDATA[ Form validations ]]>
                    </category>
                
                    <category>
                        <![CDATA[ forms ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 06 Mar 2024 10:37:42 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/03/glenn-carstens-peters-RLw-UC03Gwc-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Kelechukwu Isaac Awoke</p>
<p>HTML forms are used to get information from users. They are widely used in webpages or apps for surveys or registration processes. </p>
<p>HTML form basics include the common HTML elements, tags, attributes, concepts, or best practices required for you to create good HTML forms. The collected data is sent to a server for processing.</p>
<ul>
<li><a class="post-section-overview" href="#heading-basic-structure-of-html-form">Basic Structure of HTML Form</a></li>
<li><a class="post-section-overview" href="#heading-how-to-use-html-form-elements">How to Use HTML Form Elements</a></li>
<li><a class="post-section-overview" href="#heading-how-to-use-the-html-element">How to Use the HTML  Element</a></li>
<li><a class="post-section-overview" href="#heading-how-to-use-the-html-element">How to Use the HTML  Element</a></li>
<li><a class="post-section-overview" href="#heading-how-to-use-the-html">How to Use the HTML </a></li>
<li><a class="post-section-overview" href="#heading-how-to-use-the-html-element">How to Use the HTML  Element</a></li>
<li><a class="post-section-overview" href="#heading-form-validation">Form Validation</a></li>
<li><a class="post-section-overview" href="#heading-importance-of-form-validation">Importance of Form Validation</a></li>
<li><a class="post-section-overview" href="#heading-types-of-form-validation">Types of Form Validation</a></li>
<li><a class="post-section-overview" href="#heading-common-validation-techniques">Common Validation Techniques</a></li>
<li><a class="post-section-overview" href="#heading-form-submission-and-methods">Form Submission and Methods</a></li>
<li><a class="post-section-overview" href="#heading-how-to-style-html-forms">How to Style HTML Forms</a></li>
<li><a class="post-section-overview" href="#heading-best-practices-and-accessibility">Best Practices and Accessibility</a></li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></li>
</ul>
<h2 id="heading-basic-structure-of-html-form">Basic Structure of HTML Form</h2>
<p>You can use the <code>&lt;form&gt;</code> element to create an HTML form</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">"submit_form"</span> <span class="hljs-attr">method</span>=<span class="hljs-string">" post"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"name"</span>&gt;</span>Name:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"name"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">" name"</span> <span class="hljs-attr">required</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"email"</span>&gt;</span>Email:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">required</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p> The HTML <code>&lt;form&gt;</code> element is a container for several HTML form elements. The <code>&lt;form&gt;</code> element can contain the following:</p>
<ul>
<li><code>&lt;input&gt;</code></li>
<li><code>&lt;label&gt;</code></li>
<li><code>&lt;select&gt;</code></li>
<li><code>&lt;textarea&gt;</code></li>
<li><code>&lt;button&gt;</code></li>
<li><code>&lt;fieldset&gt;</code></li>
<li><code>&lt;legend&gt;</code></li>
<li><code>&lt;datalist&gt;</code></li>
<li><code>&lt;output&gt;</code></li>
<li><code>&lt;option&gt;</code></li>
<li><code>&lt;optgroup&gt;</code></li>
</ul>
<h2 id="heading-how-to-use-html-form-elements">How to Use HTML Form Elements</h2>
<p>In this section, you'll learn how to use some of the HTML form elements.</p>
<h3 id="heading-how-to-use-the-html-element">How to Use the HTML  Element</h3>
<p>The <code>&lt;input&gt;</code> element is the most commonly used form element. The type of information an <code>&lt;input&gt;</code> element can hold depends on the <code>&lt;type&gt;</code> attribute. </p>
<p>The <code>&lt;input&gt;</code>  element can only accept a particular type of data assigned to it using the <code>&lt;type&gt;</code>  attribute.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">""</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">input</span>
        <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span>
        <span class="hljs-attr">id</span>=<span class="hljs-string">"name"</span>
        <span class="hljs-attr">name</span>=<span class="hljs-string">"username"</span>
        <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Enter your username"</span>
        <span class="hljs-attr">required</span>
      /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">input</span>
        <span class="hljs-attr">type</span>=<span class="hljs-string">"password"</span>
        <span class="hljs-attr">id</span>=<span class="hljs-string">"security"</span>
        <span class="hljs-attr">name</span>=<span class="hljs-string">"password"</span>
        <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Enter your password"</span>
        <span class="hljs-attr">required</span>
      /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Enter your email"</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"subscribe"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"yes"</span> /&gt;</span> Subscribe to the
      newsletter <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"gender"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"male"</span> /&gt;</span> Male
      <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"gender"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"female"</span> /&gt;</span> Female
      <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"submit"</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p> The following are the different  <code>&lt;type&gt;</code> attributes that can be assigned to an <code>&lt;input&gt;</code> element:</p>
<ul>
<li><code>&lt;input type="text"&gt;</code>: Allows the user to type in text.</li>
<li><code>&lt;input type="email"&gt;</code>: The user input must follow an email format.</li>
<li><code>&lt;input type="password"&gt;</code> : Accepts password from the user. The passwords are masked, usually displayed as asterisks (*) or dots, to protect the privacy of the input.</li>
<li><code>&lt;input type="checkbox"&gt;</code>: The user can select none or many of the displayed checkboxes. Checkboxes can be checked or unchecked.</li>
<li><code>&lt;input type="radio"&gt;</code>: Allows the user to select only one from the multiple-choice radio buttons.</li>
<li><code>&lt;input type="submit"&gt;</code>: Enables the user to submit the form.</li>
</ul>
<p>The following are other possible attributes found in the input element:</p>
<ul>
<li><code>&lt;input name=" "&gt;</code> : Assigns the input field a name. The assigned name identifies the input data when the form is submitted.</li>
<li><code>&lt;input id=" "&gt;</code>: The identifier creates a unique id for the input field. It is usually associated with CSS for styling and JavaScript for other manipulations.</li>
<li><code>&lt;input value=" "&gt;</code>: Used to set the initial value for the input field. The default initial value gives the user an idea of the information required.</li>
<li><code>&lt;input placeholder=" "&gt;</code>: A faint pseudo value set to the input field that disappears once the user starts typing. Gives a hint on what data to enter, similar to the value attribute.</li>
<li><code>&lt;input required&gt;</code>: Requires that the input field must be filled out before submission. Gives an error message when not filled out.</li>
<li><code>&lt;input disabled&gt;</code>: As the name implies, this prevents the user from interacting with the input field. Disables the input field from accepting input. With this attribute, the input field becomes unclickable.</li>
<li><code>&lt;input readonly&gt;</code>: The user can only read the initially set value but can't change it. Unlike the disabled attribute, the input field is clickable but can't be modified.</li>
</ul>
<p>Note that the <code>&lt;input&gt;</code> element doesn't contain a <code>for</code> attribute.</p>
<h3 id="heading-how-to-use-the-html-element-1">How to Use the HTML  Element</h3>
<p>The label element associates text with a form input, checkbox, or radio button.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">" "</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"name"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"user"</span>&gt;</span>Username:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p>The label element describes the information required in the text field.</p>
<p>The label element is important for accessibility, this makes it easier for screen-reader users to navigate the form. The assistive technologies read the label loud to users.</p>
<p>Clicking on the label focuses the corresponding input field when the <code>for</code> attribute of the label element corresponds with the id attribute of the input element, making it more convenient for users to interact with the form.</p>
<p>Label improves the overall usage of the form, providing context and guidance.</p>
<p>The following are the commonly used attributes for the <code>label</code> element:</p>
<ul>
<li><code>&lt;label for=" "&gt;&lt;/label&gt;</code>: Associates the label with the corresponding form element, usually an input element. The value of the <code>for</code> attribute is always the same as the id value of the associated form element, usually the input element.</li>
<li>id attribute <code>&lt;label id=" "&gt;&lt;/label&gt;</code>: Gives the label a unique identifier. The value is set to the same value with the <code>for</code> attribute of the corresponding form element, usually an input element. Used for selecting the label for styling in CSS or other manipulations in JavaScript.</li>
</ul>
<h3 id="heading-how-to-use-the-html">How to Use the HTML </h3>
<p>A multi-line text input field, allows users to write longer text or paragraphs. The <code>rows</code> and <code>cols</code> attributes control the initial size of the textarea box. </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">""</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"testimony"</span>&gt;</span>Testimony:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">textarea</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"testimony"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"testimony"</span> <span class="hljs-attr">cols</span>=<span class="hljs-string">"30"</span> <span class="hljs-attr">rows</span>=<span class="hljs-string">"10"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">textarea</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p>The <code>rows</code> attribute controls the height (vertical size) of the textarea box, determining the number of visible lines while the <code>cols</code> attribute controls the width (horizontal size), specifying the number of visible characters per line. </p>
<p>Note, that the <code>textarea</code> box can <em>wrap</em> to fit the entered text within its defined width.</p>
<p>Unlike the single-line input field, the <code>textarea</code> element does not have a <code>maxlength</code> attribute or <code>value</code> attribute. The content is placed within the opening and closing tags. </p>
<p>For accessibility, it's a good practice to associate label or context with the <code>textarea</code> element to assist users who use screen-readers or other assistive technologies.</p>
<h4 id="heading-how-to-use-the-html-element-2">How to Use the HTML  Element</h4>
<p>The <code>&lt;select&gt;</code> element creates a drop-down list, that allows users to select one or multiple options from the listed choices.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">""</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"numbers"</span>&gt;</span>Choose a favorite number:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">select</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"numbers"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"numbers"</span> <span class="hljs-attr">size</span>=<span class="hljs-string">"5"</span> <span class="hljs-attr">multiple</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">""</span> <span class="hljs-attr">disabled</span> <span class="hljs-attr">selected</span>&gt;</span>Select a number<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"one"</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"two"</span>&gt;</span>2<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"three"</span>&gt;</span>3<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"four"</span>&gt;</span>4<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"five"</span>&gt;</span>5<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"six"</span>&gt;</span>6<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"seven"</span>&gt;</span>7<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"eight"</span>&gt;</span>8<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"nine"</span>&gt;</span>9<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"ten"</span>&gt;</span>10<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">select</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p>The <code>&lt;option&gt;</code> element is contained within the <code>&lt;select&gt;</code> element. The <code>&lt;option&gt;</code> element holds the items to be selected. Each <code>&lt;option&gt;</code> represents one item in the drop-down list.</p>
<p>Each <code>&lt;option&gt;</code> element is expected to have a <code>&lt;value=" "&gt;</code> attribute, which holds the value to be submitted when the form containing the <code>&lt;select&gt;</code> element is submitted. If the <code>&lt;value=" "&gt;</code> attribute is omitted, the text content of the <code>&lt;option&gt;</code> element becomes the value to be submitted instead.</p>
<p>The <code>&lt;name=" "&gt;</code> attribute identifies the select control on the server side when the form is submitted. The <code>&lt;name=" "&gt;</code> is important for processing the form data on the server. </p>
<p>You can select one of the options as the default selection by including the <code>&lt;selected&gt;</code> attribute in the <code>&lt;option&gt;</code> element. If no option is selected, then the first option in the list will be selected by default.</p>
<p>The <code>&lt;size=" "&gt;</code> attribute sets the number of options you can see at once in the drop-down by setting the <code>&lt;size=" "&gt;</code> attribute on the <code>&lt;select&gt;</code>. Note that other options are seen as you scroll down. </p>
<p>Including the <code>&lt;disabled&gt;</code> attribute on the <code>&lt;select&gt;</code> element, disables the select option and prevents the users from selecting any option. The select option becomes unclickable. </p>
<p>Also, multiple options can be selected by including <code>&lt;multiple&gt;</code> attribute on the <code>&lt;select&gt;</code> element. You can hold the <code>Ctrl</code> (or Command on Mac) key to select multiple options.</p>
<p>Understanding the <code>&lt;select&gt;</code> element and using the necessary attributes can make your form convenient for users to select different options and for easy processing of the <code>&lt;select&gt;</code> element on the server side.</p>
<h2 id="heading-form-validation">Form Validation</h2>
<p>Simply put, this is the process of checking whether the data entered in the form is correct, complete, and meets the specified format.</p>
<h3 id="heading-importance-of-form-validation">Importance of Form Validation</h3>
<ul>
<li><strong>Data Accuracy:</strong>  Prevents submission of incorrect or incomplete data.</li>
<li><strong>Security:</strong> Checks the data to prevent incorrect or malicious data from being submitted, thereby reducing harmful attacks or data breaches. </li>
<li><strong>User Experience:</strong>  Makes filling out the forms less stressful by giving a quick error message if the user is entering the wrong data. Also, it can be used to suggest the expected format. </li>
<li><strong>Efficiency:</strong> Form validation before submission saves time and resources. Reduces unnecessary requests to the server, improving the overall performance of your application.</li>
</ul>
<h3 id="heading-types-of-form-validation">Types of Form Validation</h3>
<ol>
<li><strong>Client-Side Validation:</strong> The user's browser performs the checks before submission. How does the browser validate forms? Browsers use JavaScript, CSS, or HTML attributes to validate forms. The advantage of client-side validation is the quick error message the user receives when data is incorrect or incomplete. The response is quick and doesn't require validation from the server side. One of the disadvantages is that client-side validation can be bypassed by an experienced user. </li>
<li><strong>Server-Side Validation:</strong> The server checks the form data after submission. Server-side validation is more robust and secure. Performs double verification, and validates form data again, even if the client-side validation fails or is bypassed. The server-side validation is commonly done by using scripting languages like PHP or ASP.NET. </li>
</ol>
<p>Note that you can use either of the two or a combination of both.    </p>
<h3 id="heading-common-validation-techniques">Common Validation Techniques</h3>
<p>These are common HTML attributes that help you decide the pattern of form validation.</p>
<h4 id="heading-length-limits">Length Limits</h4>
<p>You can use the <code>maxlength</code> attribute to set the maximum number of characters an input field can hold.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"username"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"username"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Username"</span> <span class="hljs-attr">maxlength</span>=<span class="hljs-string">"20"</span> <span class="hljs-attr">required</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<h4 id="heading-required-fields">Required Fields</h4>
<p>Requires that certain input fields are filled before the form is submitted. The <code>&lt;required&gt;</code> attribute is used to perform this technique. An error message is displayed when the required field is not filled by the user. </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"username"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"username"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Username"</span> <span class="hljs-attr">required</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Email"</span> <span class="hljs-attr">required</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<h4 id="heading-data-format">Data Format</h4>
<p>Ensures the data entered by the user follows the required format. The <code>&lt;input type="email"&gt;</code> type attribute set to email will require the user to enter the correct email format (for example: me@example.com) before form submission. </p>
<p>The same thing happens if the type attribute is set to number <code>&lt;input type="number"&gt;</code>, the user can only put data from 0-9.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Email"</span> <span class="hljs-attr">required</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<h4 id="heading-password-strength">Password Strength</h4>
<p>The <code>&lt;pattern=""&gt;</code> attribute is used to specify password complexity such as minimum length, and the inclusion of uppercase or lowercase letters, numbers, and special characters. </p>
<p>The <code>&lt;title=""&gt;</code> attribute displays the error message when the user hovers over the input field or when the entered password does not match the specified password format. The higher the password complexity, the higher the user account is protected from unauthorized access.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"password"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"password"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"password"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Password"</span> <span class="hljs-attr">pattern</span>=<span class="hljs-string">"(?=.\d)(?=.[a-z])(?=.*[A-Z]).{8,}"</span> <span class="hljs-attr">title</span>=<span class="hljs-string">"Password must contain at least one number, one uppercase letter, one lowercase letter, and at least 8 or more characters"</span> <span class="hljs-attr">required</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<h4 id="heading-numeric-values">Numeric values</h4>
<p>You can set the range of numeric values to be entered by the user by using the <code>min</code> and <code>max</code> attributes. For example, to check if a user is within the specified age range:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"number"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"age"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"age"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Age"</span> <span class="hljs-attr">min</span>=<span class="hljs-string">"18"</span> <span class="hljs-attr">max</span>=<span class="hljs-string">"100"</span> <span class="hljs-attr">required</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p>Having a good form validation practice helps to create forms with accurate data and reduces vulnerability to malicious attacks. </p>
<h2 id="heading-form-submission-and-methods">Form Submission and Methods</h2>
<p>When the submit button is clicked after filling out a form, your information is sent to the server for processing. This is called form submission. </p>
<h3 id="heading-methods-of-form-submission">Methods of Form Submission</h3>
<p>Form data is sent to the server using the <code>method</code> attribute. There are two commonly used methods:</p>
<h4 id="heading-get-method">GET Method</h4>
<p>With the <code>get</code> method <code>&lt;method="get"&gt;</code>, the form data is sent using the URL in the browser's address bar to the server. </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">"http://example.com"</span> <span class="hljs-attr">method</span>=<span class="hljs-string">"get"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"name"</span> /&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Submit"</span> /&gt;</span>
 <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p>Using the above code sample, when the user enters a name (let's say the user's name is KC) in the input field named ''name'', and clicks the submit button, the form data will be sent to the server in the URL like this: "http://example.com?name=KC". </p>
<p>The GET method is not safe, as it is commonly used for sending small amounts of data that is not sensitive.  </p>
<h4 id="heading-post-method">POST Method</h4>
<p>The post method attribute <code>&lt;method=post&gt;</code> sends the form data in the body of the HTTP request to the server, rather than in the URL.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">"http://example.com"</span> <span class="hljs-attr">method</span>=<span class="hljs-string">"get"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"name"</span> /&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Submit"</span> /&gt;</span>
 <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p>Using the same code sample above, the POST method will send the form data to the server like this: "https://example.com/submit.php". </p>
<p>You'd should notice that the POST request does not contain the form data in the URL but rather points to the server-side script (submit.php) that will process the form data. </p>
<p>The sent form data is not visible. The POST request is used to submit sensitive information, like passwords, since the data is not visible in the URL, but rather sent in the HTTP body request.</p>
<h2 id="heading-how-to-style-html-forms">How to Style HTML Forms</h2>
<p>HTML forms can be styled using CSS, just like any other HTML element. You can do the following with CSS to match the design of your website:</p>
<ul>
<li><strong>Selectors</strong>: CSS selectors such as element selectors, class selectors, or ID selectors can be used to select specific elements in the HTML code for styling.</li>
<li><strong>Typography</strong>: Typography can be used to set the font-family, adjust the size, font-weight, and color of the text within the form element to enhance readability. </li>
<li><strong>Box Model</strong>: With the knowledge of CSS properties like padding, border, and margin, which affect the spacing and layout, you can style HTML elements.</li>
<li><strong>Colors and Backgrounds</strong>: The color of your text or background can be styled using the CSS properties like color and background-color (or background-image) respectively. </li>
<li><strong>Responsiveness</strong>: With media queries, you can make your form responsive and adapt to different screen sizes and devices. </li>
<li><strong>Layout</strong>: You can control the layout of a form to make it user-friendly with CSS properties like display, float, and positioning.</li>
</ul>
<h2 id="heading-best-practices-and-accessibility">Best Practices and Accessibility</h2>
<p>Like every other HTML document, ensure your form complies with web standards and is accessible to people with disabilities. For best practices and accessibility, take note of the following:</p>
<h3 id="heading-structures-and-semantics">Structures and Semantics</h3>
<ul>
<li>Always use proper semantic HTML elements (like  <code>&lt;form&gt;</code>, <code>&lt;input&gt;</code>, <code>&lt;label&gt;</code>, and so on) to structure not just forms but every other HTML document.</li>
<li>Nest elements properly and associate labels to their respective input field. </li>
<li>Make sure your input fields have the appropriate type attributes.</li>
</ul>
<h3 id="heading-error-handling-and-validation">Error Handling and Validation</h3>
<ul>
<li>Combine both client-side and server-side validation to avoid incorrect or incomplete data submission.</li>
<li>Use the appropriate attribute to display error messages when form submission fails or validation errors occur. </li>
</ul>
<h3 id="heading-responsive-design">Responsive Design</h3>
<ul>
<li>Your forms should be responsive and adapt to various screen sizes and devices.</li>
<li>Use CSS media queries to adjust your form layouts and styles based on the viewport size.</li>
</ul>
<h3 id="heading-design-and-contrast">Design and Contrast</h3>
<ul>
<li>Use fonts and colors that are easy to see.</li>
<li>The color contrast between text and background should ensure readability, especially for users with low vision. </li>
</ul>
<h3 id="heading-aria-roles-and-attributes">ARIA Roles and Attributes</h3>
<ul>
<li>ARIA (Accessible Rich Internet Application) roles and attributes improve accessibility for screen-reader users or other assistive technologies.</li>
<li>ARIA attributes ( <code>aria-labelledby</code>, <code>aria-describedby</code>, and <code>aria-invalid</code>) provide additional context and feedback for form elements.</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Creating good HTML forms that meet web standards improve user interaction and experience on your website. By following the best practices and accessibility, developers can create forms that are user-friendly, and effective in collecting data from users. </p>
<p>You can learn more about HTML forms and responsive web design using <a target="_blank" href="https://www.freecodecamp.org/learn/2022/responsive-web-design/">freeCodeCamp's Responsive Web Design Certification</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build a Camera App on the Web – No Plugins Required ]]>
                </title>
                <description>
                    <![CDATA[ Ever had to make a video call right on your browser with Google Meet, Zoom, or any other video chat app? Well, here’s what you might have never thought to ask—how does it work? Well, there are a number of things that make a real-time video chat appli... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/build-a-camera-app-on-the-web/</link>
                <guid isPermaLink="false">66bc54a6a085c9ae30a3c96c</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Felix Favour Chinemerem ]]>
                </dc:creator>
                <pubDate>Fri, 23 Feb 2024 00:36:03 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/02/supercharged-animations.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Ever had to make a video call right on your browser with Google Meet, Zoom, or any other video chat app? Well, here’s what you might have never thought to ask—how does it work?</p>
<p>Well, there are a number of things that make a real-time video chat application fully functional on the web. In this article, we’ll explore how you can access media content through your device’s camera. And we'll build a camera app in the course of our exploration.</p>
<p>Let’s face it, using the MediaStream API to build a camera application does not tell the whole story. But here’s what I can promise you: we are taking the first step in the right direction.</p>
<p>Before we begin, have a peek at what you should be able to create by the end of this article <a target="_blank" href="https://camera-demo-rho.vercel.app/">here</a>. Now that you are all geared up, let’s get to work!</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>Before we dive in, let's be sure of a few things. This article is designed to be for beginners, but having the right resources will ensure a seamless experience. Here's what you'll need:</p>
<ul>
<li>A very basic understanding of HTML, CSS, and JavaScript — beginner level knowledge is absolutely fine.</li>
<li>A basic understanding of the <a target="_blank" href="https://www.freecodecamp.org/news/javascript-dom/">Document Object Model</a> in JavaScript.</li>
<li>Last but not the least, some good background music — I’ll let you choose this one yourself, <a target="_blank" href="https://coderadio.freecodecamp.org/">but there's always freeCodeCamp radio</a>.</li>
</ul>
<p>Ok, now we're all set.</p>
<h2 id="heading-what-is-the-mediastream-api">What is the MediaStream API?</h2>
<p>The MediaStream Recording API helps the browser capture audio-visual data streams. It's important for our use case, because any image we capture has to be stored in a <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/MediaStream">MediaStream</a> object.</p>
<p>The MediaStream API does more than capture photos and videos. It also helps process and analyze the MediaStream data right on the browser. As complex as all of this might seem, it’ll interest you to know that the MediaStream API is surprisingly easy to work with.</p>
<p>Our camera app makes it even easier.</p>
<h2 id="heading-components-of-our-camera-app">Components of Our Camera App</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/supercharged-animations--3-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Our camera app has a very simple user interface — heavily inspired by the Samsung Camera UI. Some notable components/features of the camera are:</p>
<ul>
<li>Camera Preview</li>
<li>Camera mode options</li>
<li>Photo Gallery</li>
</ul>
<p>For the sake of this tutorial, only a few actions on the browser are enabled — the “photo” camera mode, the camera shutter button, and the photo gallery button just to the right of the shutter button.</p>
<h2 id="heading-step-1-simple-html-for-our-camera-app">Step 1: Simple HTML for Our Camera app</h2>
<p>To begin, we'll lay the foundation for our camera application with some simple markup. Understanding the structure of our camera app is crucial as it comprises four major sections, each playing a vital role in its overall functionality:</p>
<ol>
<li><code>&lt;video&gt;</code> section</li>
<li>Snapshot <code>&lt;button&gt;</code> section</li>
<li><code>&lt;canvas&gt;</code> section</li>
<li>Snapshot <code>&lt;img&gt;</code> section</li>
</ol>
<h3 id="heading-1-section">1. <code>&lt;video&gt;</code> section</h3>
<p>Our camera app must include a <code>&lt;video&gt;</code> tag for streaming the visual media from our webcam to our browser’s display. Let’s give it an <code>id</code> of <code>camera-stream</code>.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">video</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"camera-stream"</span> <span class="hljs-attr">autoplay</span> <span class="hljs-attr">loop</span> <span class="hljs-attr">muted</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">source</span> <span class="hljs-attr">src</span>=<span class="hljs-string">""</span> &gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">video</span>&gt;</span>
</code></pre>
<h3 id="heading-2-snapshot-section">2. Snapshot <code>&lt;button&gt;</code> section</h3>
<p>We'll also need a button to trigger the capture of the visual media when it is clicked. This will act as the shutter button. Let’s give it an <code>id</code> of <code>shutter</code>.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"shutter-ctn"</span>&gt;</span>
  ...
  <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"shutter"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"shutter"</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
  ...
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h3 id="heading-3-section">3. <code>&lt;canvas&gt;</code> section</h3>
<p>A canvas tag helps us capture the image data from the video stream, while being able to export the data as an image that can be saved. The <code>&lt;canvas&gt;</code> element does not need to be visible to the user, but it must be accessible by the DOM. Let’s give it an <code>id</code> of <code>canvas</code>.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">canvas</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"canvas"</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">canvas</span>&gt;</span>
</code></pre>
<h3 id="heading-4-snapshot-section">4. Snapshot <code>&lt;img&gt;</code> section</h3>
<p>For the final HTML section, we need a view to see all images that have been captured. Let’s identify this with an id of  <code>gallery-view</code>.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"gallery-view"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"prev"</span>&gt;</span>
    PREV
  <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">data-index</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">""</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"current viewed image"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"next"</span>&gt;</span>
    NEXT
  <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
  ...
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h2 id="heading-step-2-beautiful-css-styles-to-make-our-app-pop">Step 2: Beautiful CSS Styles to Make Our App Pop</h2>
<p>Adding styles to the HTML of our camera app greatly improves its user-friendliness. Don't hesitate to get creative while adding these styles, and feel free to skip this section to Step 3 if you would rather add your own styles.</p>
<p>First, lets add some global styles to ensure that each component fits perfectly when they are layered.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">max-height</span>: <span class="hljs-number">100vh</span>;
  <span class="hljs-attribute">overflow</span>: hidden;
}
<span class="hljs-selector-tag">canvas</span> {
  <span class="hljs-attribute">display</span>: none;
}
<span class="hljs-selector-tag">button</span> {
  <span class="hljs-attribute">border</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">outline</span>: none;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#00000070</span>;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#FFFFFF</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">4px</span> <span class="hljs-number">8px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">30px</span>;
  <span class="hljs-attribute">min-width</span>: <span class="hljs-number">30px</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">24px</span>;
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">place-items</span>: center;
  <span class="hljs-attribute">cursor</span>: pointer;
}
</code></pre>
<p>Afterwards, we'll apply styling to the <code>&lt;video&gt;</code> element, which displays a preview of the shot to be captured.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.camera-ctn</span> {
  <span class="hljs-attribute">position</span>: relative;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#000000</span>;
}
<span class="hljs-selector-class">.camera-view</span> <span class="hljs-selector-tag">video</span> {
  <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100vw</span>;
  <span class="hljs-attribute">object-fit</span>: cover;
  <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">scaleX</span>(-<span class="hljs-number">1</span>);
}
</code></pre>
<p>Lastly, the styling task left for us involves customizing the bottom section of our camera interface — the section typically housing the shutter button.</p>
<pre><code class="lang-css"><span class="hljs-comment">/* CAMERA BOTTOM */</span>
<span class="hljs-selector-class">.camera-bottom</span> {
  <span class="hljs-attribute">height</span>: <span class="hljs-number">250px</span>;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#00000050</span>;
  <span class="hljs-attribute">position</span>: absolute;
  <span class="hljs-attribute">inset</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">top</span>: auto;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span> <span class="hljs-number">5%</span>;
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">place-items</span>: center;
}
<span class="hljs-selector-class">.camera-bottom</span> &gt; <span class="hljs-selector-class">.inner</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">place-items</span>: center;
  <span class="hljs-attribute">max-width</span>: <span class="hljs-number">500px</span>;
}

<span class="hljs-comment">/* SHUTTER CONTAINER */</span>
<span class="hljs-selector-class">.shutter-ctn</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: center;
  <span class="hljs-attribute">justify-content</span>: space-around;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
}
<span class="hljs-selector-class">.shutter</span> {
  <span class="hljs-attribute">height</span>: <span class="hljs-number">80px</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">80px</span>;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#FFFFFF</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
}
<span class="hljs-selector-class">.shutter</span><span class="hljs-selector-pseudo">:active</span> {
  <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">scale</span>(<span class="hljs-number">0.8</span>);
}
<span class="hljs-selector-class">.switch-device</span> {
  <span class="hljs-attribute">height</span>: <span class="hljs-number">55px</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">55px</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
}
</code></pre>
<p>To have a full view of the CSS styles originally used on this project, have a look at them <a target="_blank" href="https://github.com/felixfavour/camera-demo/blob/master/assets/styles/main.css">here</a>.</p>
<h2 id="heading-step-3-javascript-code-to-make-our-app-fully-functional">Step 3: JavaScript Code to Make Our App Fully Functional</h2>
<p>Finally, after laying a solid foundation with our HTML structure and improving the usability of our camera app with some CSS styles, our focus now shifts to ensuring our camera app does what it’s supposed to do — take pictures.</p>
<p>We do this by heavily relying on the MediaStream API in JavaScript while following these three steps:</p>
<ol>
<li>Linking our HTML elements to JS.</li>
<li>Connecting the webcam to JS code.</li>
<li>Capturing and saving media from the webcam.</li>
</ol>
<h3 id="heading-1-linking-html-elements-to-js">1. Linking HTML elements to JS</h3>
<p>As we proceed with adding functionality to our HTML, we must link these elements to our JavaScript code via the DOM. Recall that we assigned IDs to the primary elements we defined in the HTML step.</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">const</span> cameraVideoStream = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'camera-stream'</span>)
<span class="hljs-keyword">const</span> shutterButton = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'shutter'</span>)
<span class="hljs-keyword">const</span> canvas = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'canvas'</span>)
...
</code></pre>
<h3 id="heading-2-connecting-the-webcam-to-javascript-code">2. Connecting the webcam to JavaScript code</h3>
<p>Upon linking our HTML elements to our JS code, we can now establish the connection to our webcam. This involves initially verifying whether the user’s browser supports this operation using the <code>navigator.mediaDevices</code> boolean expression.</p>
<p>If the expression returns a truthy value, we can invoke <code>getUserMedia()</code> and specify the video option by passing <code>{video: true}</code> as a function argument like below:</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">if</span> (navigator.mediaDevices &amp;&amp; navigator.mediaDevices.getUserMedia({ <span class="hljs-attr">video</span>: <span class="hljs-literal">true</span> })) {
  navigator.mediaDevices
    .getUserMedia({ <span class="hljs-attr">video</span>: <span class="hljs-literal">true</span> })
    .then (<span class="hljs-function">(<span class="hljs-params">stream</span>) =&gt;</span> {
            cameraVideoStream.srcObject = stream
            cameraVideoStream.play()
    })
}
</code></pre>
<p>The <code>getUserMedia()</code> function invokes an asynchronous operation, which means it doesn't return a response immediately. Also, it might encounter failures — this could happen if the user denies permission for us to access their webcam or if their device lacks a webcam altogether. </p>
<p>If the operation is successful, the video stream is collected and transferred to the <code>video</code> element that was earlier created.</p>
<p>But the video does not start playing immediately. A brief delay occurs to allow for a buffer — this delay is often unnoticed. We have to create a <code>streaming</code> variable in conjunction with the <code>canplay</code> event of the <code>&lt;video&gt;</code> element to know when a portion of the video is buffered and ready to play. We can do that like below:</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">let</span> width = <span class="hljs-built_in">window</span>.innerWidth
<span class="hljs-keyword">let</span> height = <span class="hljs-number">0</span>
<span class="hljs-keyword">let</span> streaming = <span class="hljs-literal">false</span>

cameraVideoStream.addEventListener(
  <span class="hljs-string">"canplay"</span>,
  <span class="hljs-function">(<span class="hljs-params">ev</span>) =&gt;</span> {
    <span class="hljs-keyword">if</span> (!streaming) {
      height = cameraVideoStream.videoHeight / (cameraVideoStream.videoWidth / width);

      canvas.setAttribute(<span class="hljs-string">"width"</span>, width);
      canvas.setAttribute(<span class="hljs-string">"height"</span>, height);
      cameraVideoStream.setAttribute(<span class="hljs-string">"width"</span>, width);
      cameraVideoStream.setAttribute(<span class="hljs-string">"height"</span>, height);
      streaming = <span class="hljs-literal">true</span>;
    }
  },
  <span class="hljs-literal">false</span>
);
</code></pre>
<p>Notice that before <code>streaming</code> is set to true, the <code>&lt;video&gt;</code> element and the <code>&lt;canvas&gt;</code> height are set to match the <code>height</code> value (which might be a fraction of the <code>width</code> based on the desired dimensions). This adjustment helps prevent any glitches, particularly when capturing the image.</p>
<h3 id="heading-3-capture-and-save-media-from-the-webcam">3. Capture and save media from the webcam</h3>
<p>Now, the hardest work is complete. All that is left is to capture snapshots from the video stream and store them in an array as images.</p>
<p>To accomplish this, we use the context of the <code>&lt;canvas&gt;</code> element defined earlier, accessed through <code>canvas.getContext('2d')</code>. Afterwards, we transfer the current frame of data from the video stream to compose an image using the <code>canvasContext.drawImage()</code> function just like below.</p>
<pre><code class="lang-jsx"><span class="hljs-comment">// Capture snapshots using HTML Canvas</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">captureImage</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> canvasContext = canvas.getContext(<span class="hljs-string">'2d'</span>)
  canvas.width = width
  canvas.height = height
  canvasContext.drawImage(cameraVideoStream, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, width, height)

  <span class="hljs-comment">// Convert captured data to image (base64)</span>
  <span class="hljs-keyword">const</span> data = canvas.toDataURL(<span class="hljs-string">'image/png'</span>)
  currentImageElement.src = data
}

<span class="hljs-comment">// Add click listener to shutter button to capture image</span>
shutterButton.addEventListener(<span class="hljs-string">'click'</span>, <span class="hljs-function">() =&gt;</span> captureImage())
</code></pre>
<p>With the data now captured as an image, the absolute final step is to convert the image to a transferable format suitable for the <code>&lt;img&gt;</code> tag or any other image viewing resource. One of the many transferable formats is base64, and fortunately, the <code>&lt;canvas&gt;</code> element enables us to achieve this effortlessly with <code>canvas.toDataURL('image/png')</code>.</p>
<p>And voilà! You've successfully constructed your own camera app. Well done, genius!</p>
<p>As soon as we are done implementing these three steps, all that’s left is to say “cheese” and take some nice pictures.</p>
<p>If you mixed up a few instructions, feel free to take a look at the complete JS code <a target="_blank" href="https://github.com/felixfavour/camera-demo">here</a>. If that does not help much, I’m always happy to assist personally when you <a target="_blank" href="https://favourfelix.com">send a message</a>.</p>
<h2 id="heading-the-fun-doesnt-stop-here">The Fun Doesn't Stop Here</h2>
<p>Wanna have fun building more features for the camera app? You can pick up where I left off on GitHub. Whether it’s your own gallery, or a quick photo editing tool in the gallery view, or a timer feature, or even if you wish to extend this to a video recorder – go for it!</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://github.com/felixfavour/camera-demo">https://github.com/felixfavour/camera-demo</a></div>
<p>If you found this article helpful, feel free to connect on <a target="_blank" href="http://favourfelix.com/">favourfelix.com</a> to see what else I'm up to.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Draw with JavaScript on an HTML Canvas Element – Gorilla Example ]]>
                </title>
                <description>
                    <![CDATA[ Drawing from code can be fun for many reasons. You can generate art that follows a certain logic. You can create animations by moving only parts of an image. And you can even build up a whole game as I covered in this tutorial. In my last article, we... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-draw-a-gorilla-with-javascript-on-html-canvas/</link>
                <guid isPermaLink="false">66c4c80829f446a67a4197ec</guid>
                
                    <category>
                        <![CDATA[ canvas ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Hunor Márton Borbély ]]>
                </dc:creator>
                <pubDate>Thu, 15 Feb 2024 16:30:12 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/02/Thumbnail.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Drawing from code can be fun for many reasons. You can generate art that follows a certain logic. You can create animations by moving only parts of an image. And you can even build up a whole game as I covered in <a target="_blank" href="https://www.freecodecamp.org/news/gorillas-game-in-javascript/">this tutorial</a>.</p>
<p>In my last article, we focused on the <a target="_blank" href="https://www.freecodecamp.org/news/drawing-on-a-canvas-element-with-javascript/">basics of drawing</a>. Now, let's see a concrete example and explore how to use JavaScript to draw a Gorilla. </p>
<p>You don't need to have any prerequisites for this tutorial. Even if you missed the basics, you can start right away. We are only going to have some simple HTML and a plain JavaScript file that you can run directly in the browser.</p>
<p>By the end, you'll know how to draw a gorilla with JS.‌</p>
<h2 id="heading-table-of-contents">Table of Contents:</h2>
<ol>
<li><a class="post-section-overview" href="#heading-how-to-define-a-canvas">How to Define a Canvas</a></li>
<li><a class="post-section-overview" href="#heading-how-to-turn-the-coordinate-system-upside-down">How to Turn the Coordinate System Upside Down</a></li>
<li><a class="post-section-overview" href="#heading-how-to-draw-the-legs-of-the-gorilla">How to Draw the Body of the Gorilla</a></li>
<li><a class="post-section-overview" href="#heading-how-to-draw-the-arms-of-the-gorilla">How to Draw the Legs of the gorilla</a></li>
<li><a class="post-section-overview" href="#heading-how-to-draw-the-face-of-the-gorilla">How to Draw the Arms of the Gorilla</a></li>
<li><a class="post-section-overview" href="#heading-how-to-draw-the-face-of-the-gorilla">How to Draw the Face of the Gorilla</a></li>
<li><a class="post-section-overview" href="#heading-next-steps">Next Steps</a></li>
</ol>
<h2 id="heading-how-to-define-a-canvas">How to Define a Canvas</h2>
<p>To draw our gorilla, first let's define a simple HTML file with a Canvas element. Then we'll see how to access it from JavaScript. </p>
<p>In the HTML file, in the header, we'll add our JavaScript file. Note that I’m using the <code>defer</code> keyword to make sure the script only executes once the rest of the document is parsed.</p>
<p>In the body, we'll add a <code>canvas</code> element. We set its size to 500 x 500 and set an ID.</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"utf-8"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Gorilla<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"index.js"</span> <span class="hljs-attr">defer</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">canvas</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"gorilla"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"500"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"500"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">canvas</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>Then, let's create a JavaScript file. In this file, we'll first get the canvas element by ID. Then, we'll get the rendering context of the canvas element. This is a built-in API with many methods and properties that we can use to draw on the canvas.</p>
<pre><code class="lang-js"><span class="hljs-comment">// The canvas element and its drawing context </span>
<span class="hljs-keyword">const</span> canvas = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"gorilla"</span>); 
<span class="hljs-keyword">const</span> ctx = canvas.getContext(<span class="hljs-string">"2d"</span>);

. . .
</code></pre>
<p>Before we get to drawing, first let's make our life easier by turning the coordinate system upside down.</p>
<h2 id="heading-how-to-turn-the-coordinate-system-upside-down">How to Turn the Coordinate System Upside Down</h2>
<p>When we use canvas, we have a coordinate system with the origin at the top-left corner of the canvas that grows to the right and downwards. This is aligned with how websites work in general. Things go from left to right and top to bottom. </p>
<p>This is the default, but we can change it.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/08/gorilla-with-and-without-transforming-and-scaling.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>The gorilla with and without transforming and scaling the coordinate system</em></p>
<p>In our case, it is more convenient to go from the bottom to the top. Then the gorilla can stand at the bottom, and we don’t have to figure out where the bottom of the canvas is.</p>
<p>We can use the <code>translate</code> method to shift the entire coordinate system to the bottom-middle of the canvas. We'll move the coordinate system down along the Y-axis by the size of the canvas, and to the right along the X-axis by half the size of the canvas.</p>
<p>Once we do this, the Y-coordinate is still growing downwards. We can flip it using the <code>scale</code> method. Setting a negative number for the vertical direction will flip the entire coordinate system upside down.</p>
<pre><code class="lang-js"><span class="hljs-comment">// The canvas element and its drawing context </span>
<span class="hljs-keyword">const</span> canvas = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"gorilla"</span>); 
<span class="hljs-keyword">const</span> ctx = canvas.getContext(<span class="hljs-string">"2d"</span>);

ctx.translate(<span class="hljs-number">250</span>, <span class="hljs-number">500</span>);
ctx.scale(<span class="hljs-number">1</span>, <span class="hljs-number">-1</span>);

. . .
</code></pre>
<p>‌We have to do this before we paint anything on the canvas because the <code>translate</code> and <code>scale</code> methods do not actually move anything that's already on the canvas. But anything we paint after these method calls will be painted according to this new coordinate system.</p>
<h2 id="heading-how-to-draw-the-gorilla">How to Draw the Gorilla</h2>
<p>Now let's look into drawing the gorilla. We'll break this down into multiple steps. First, we'll draw the body, then the legs, the arms, and finally the face of the gorilla.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/08/drawing-gorilla-steps.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>We'll draw the gorilla in multiple steps</em></p>
<h3 id="heading-how-to-draw-the-body-of-the-gorilla">How to draw the body of the gorilla</h3>
<p>We'll draw the body of the gorilla as a path. Paths start with the <code>beginPath</code> method and end with either calling the <code>fill</code> or the <code>stroke</code> method – or both. </p>
<p>In between, we'll build the path by calling path-building methods. In this case, to build up the body of the gorilla we'll use the <code>moveTo</code> and a bunch of <code>lineTo</code> methods.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/Screenshot-2024-02-12-at-23.53.57.png" alt="Image" width="600" height="400" loading="lazy">
<em>The body of the gorilla. The image shows the path we're filling.</em></p>
<p>We'll set the fill style to black, and then we'll begin a path. Move to a starting position and then draw straight lines to draw the silhouette of the gorilla. Once we're finished, we'll fill the shape with the <code>fill</code> method.</p>
<pre><code class="lang-js">. . .

ctx.fillStyle = <span class="hljs-string">"black"</span>;

<span class="hljs-comment">// Draw the Body of the Gorilla</span>
ctx.beginPath();
ctx.moveTo(<span class="hljs-number">-68</span>, <span class="hljs-number">72</span>);
ctx.lineTo(<span class="hljs-number">-80</span>, <span class="hljs-number">176</span>);

ctx.lineTo(<span class="hljs-number">-44</span>, <span class="hljs-number">308</span>);
ctx.lineTo(<span class="hljs-number">0</span>, <span class="hljs-number">336</span>);
ctx.lineTo(+<span class="hljs-number">44</span>, <span class="hljs-number">308</span>);

ctx.lineTo(+<span class="hljs-number">80</span>, <span class="hljs-number">176</span>);
ctx.lineTo(+<span class="hljs-number">68</span>, <span class="hljs-number">72</span>);
ctx.fill();

. . .
</code></pre>
<p>In case you are wondering how I came up with these coordinates, I actually started with an initial sketch with pen and paper. I tried to estimate the coordinates, tried them with code, and then adjusted them until they started getting the right shape. Of course, you might have other methods as well.</p>
<h3 id="heading-how-to-draw-the-legs-of-the-gorilla">How to draw the legs of the gorilla</h3>
<p>We'll draw the legs the same way. We could even continue the same path we used before, but it might be easier to see what's happening if we break this down into separate paths.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/Screenshot-2024-02-12-at-23.09.59.png" alt="Image" width="600" height="400" loading="lazy">
<em>Drawing the legs as two separate paths</em></p>
<pre><code class="lang-js">. . .

<span class="hljs-comment">// Draw the Left Leg</span>
ctx.beginPath();
ctx.moveTo(<span class="hljs-number">0</span>, <span class="hljs-number">72</span>);
ctx.lineTo(<span class="hljs-number">-28</span>, <span class="hljs-number">0</span>);
ctx.lineTo(<span class="hljs-number">-80</span>, <span class="hljs-number">0</span>);
ctx.lineTo(<span class="hljs-number">-68</span>, <span class="hljs-number">72</span>);
ctx.fill();

<span class="hljs-comment">// Draw the Right Leg</span>
ctx.beginPath();
ctx.moveTo(<span class="hljs-number">0</span>, <span class="hljs-number">72</span>);
ctx.lineTo(+<span class="hljs-number">28</span>, <span class="hljs-number">0</span>);
ctx.lineTo(+<span class="hljs-number">80</span>, <span class="hljs-number">0</span>);
ctx.lineTo(+<span class="hljs-number">68</span>, <span class="hljs-number">72</span>);
ctx.fill();

. . .
</code></pre>
<p>The fill color in this case is also going to be black. Why? Because that's what we set the <code>fillStyle</code> property to, the last time we set its value. Every path that follows this statement will use this color until we change its value.</p>
<h3 id="heading-how-to-draw-the-arms-of-the-gorilla">How to draw the arms of the gorilla</h3>
<p>While the body and the legs are relatively simple parts of the gorilla, the arms are a bit more complicated. We'll draw them as a curve.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/Screenshot-2024-02-12-at-23.12.03.png" alt="Image" width="600" height="400" loading="lazy">
<em>Drawing the arms as a curve</em></p>
<p>Let’s start with the left arm. The main part of this is actually only two lines of code. We'll use the <code>moveTo</code> method to move to the shoulder of the gorilla, then from there, we'll draw the arm as a quadratic curve with the <code>quadraticCurveTo</code> method.</p>
<p>A quadratic curve is a simple curve with one control point. As the curve goes from the starting point (which we'll set with <code>moveTo</code>), the curve bends towards this control point (set as the first two arguments of the <code>quadraticCurveTo</code> method) as it reaches its end position (set as the last two arguments).</p>
<pre><code class="lang-js">. . .

ctx.strokeStyle = <span class="hljs-string">"black"</span>;
ctx.lineWidth = <span class="hljs-number">70</span>;

<span class="hljs-comment">// Draw the Left Arm</span>
ctx.beginPath();
ctx.moveTo(<span class="hljs-number">-56</span>, <span class="hljs-number">200</span>);
ctx.quadraticCurveTo(<span class="hljs-number">-176</span>, <span class="hljs-number">180</span>, <span class="hljs-number">-112</span>, <span class="hljs-number">48</span>);
ctx.stroke();

<span class="hljs-comment">// Draw the Right Arm</span>
ctx.beginPath();
ctx.moveTo(+<span class="hljs-number">56</span>, <span class="hljs-number">200</span>);
ctx.quadraticCurveTo(+<span class="hljs-number">176</span>, <span class="hljs-number">180</span>, +<span class="hljs-number">112</span>, <span class="hljs-number">48</span>);
ctx.stroke();

. . .
</code></pre>
<p>We'll draw the hands as strokes. Instead of ending the path with the <code>fill</code> method, we'll use the <code>stroke</code> method.</p>
<p>We'll also set up the styling differently. Instead of using the <code>fillStyle</code> property, here we'll set the color with <code>strokeStyle</code> and give thickness to the arms with the <code>lineWidth</code> property.</p>
<p>Drawing the right arm is the same, except the horizontal coordinates are flipped. The negative numbers have a positive sign now.</p>
<p>As a result, our gorillas should start to gain shape. They still don’t have a face, but we have the whole silhouette now.</p>
<h3 id="heading-how-to-draw-the-face-of-the-gorilla">How to draw the face of the gorilla</h3>
<p>The face of the gorilla comes together from multiple different parts. First, we'll draw the facial mask with three circles.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/08/gorilla-facial-mask.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>We draw the facial mask as three circles</em></p>
<p>Unfortunately, we don’t have a simple fill circle method, as we have in the case of rectangles. We have to draw an <code>arc</code> instead.</p>
<p>An <code>arc</code> method can be called as part of a path. We'll start each circle with the <code>beginPath</code> method and end with the <code>fill</code> method.</p>
<pre><code class="lang-js">. . .

ctx.fillStyle = <span class="hljs-string">"lightgray"</span>;

<span class="hljs-comment">// Draw the Facial Mask</span>
ctx.beginPath();
ctx.arc(<span class="hljs-number">0</span>, <span class="hljs-number">252</span>, <span class="hljs-number">36</span>, <span class="hljs-number">0</span>, <span class="hljs-number">2</span> * <span class="hljs-built_in">Math</span>.PI);
ctx.fill();

ctx.beginPath();
ctx.arc(<span class="hljs-number">-14</span>, <span class="hljs-number">280</span>, <span class="hljs-number">16</span>, <span class="hljs-number">0</span>, <span class="hljs-number">2</span> * <span class="hljs-built_in">Math</span>.PI);
ctx.fill();

ctx.beginPath();
ctx.arc(+<span class="hljs-number">14</span>, <span class="hljs-number">280</span>, <span class="hljs-number">16</span>, <span class="hljs-number">0</span>, <span class="hljs-number">2</span> * <span class="hljs-built_in">Math</span>.PI);
ctx.fill();

. . .
</code></pre>
<p>The <code>arc</code> method has a lot of properties. This might look a bit scary, but we only need to focus on the first 3 when drawing circles:</p>
<ul>
<li>The first two arguments are <code>x</code> and <code>y</code>, the center coordinates of the arc.</li>
<li>The third argument is the <code>radius</code>.</li>
<li>Then the last two arguments are the <code>startAngle</code> and the <code>endAngle</code> of the arc in radians. Because here we want to have a full circle and not an arc, we'll start with 0 and end at a full circle. A full circle in radians is two times Pi.</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/Screenshot-2024-02-12-at-23.17.08.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>If these last two properties are confusing, don't worry about it. What's important is that when we draw circles, they are always <code>0</code> and <code>2 * Math.Pi</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/08/gorilla-final-steps.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>We draw the eyes, the nostrils, and the mouth</em></p>
<p>Then we draw the eyes of the gorilla as two other circles. Here the center coordinates of the circles are the same as the bigger gray circles around them. Only their radius and their fill color are different.</p>
<pre><code class="lang-js">. . .

ctx.fillStyle = <span class="hljs-string">"black"</span>;

<span class="hljs-comment">// Draw the Left Eye</span>
ctx.beginPath();
ctx.arc(<span class="hljs-number">-14</span>, <span class="hljs-number">280</span>, <span class="hljs-number">6</span>, <span class="hljs-number">0</span>, <span class="hljs-number">2</span> * <span class="hljs-built_in">Math</span>.PI);
ctx.fill();

<span class="hljs-comment">// Draw the Right Eye</span>
ctx.beginPath();
ctx.arc(+<span class="hljs-number">14</span>, <span class="hljs-number">280</span>, <span class="hljs-number">6</span>, <span class="hljs-number">0</span>, <span class="hljs-number">2</span> * <span class="hljs-built_in">Math</span>.PI);
ctx.fill();

. . .
</code></pre>
<p>Then for the nose, we'll draw two short lines as nostrils. They are part of the same path, and we'll call the <code>moveTo</code> method in between to get from one side to the other. Before calling stroke at the end of this path, we'll update the <code>lineWidth</code> property. </p>
<pre><code class="lang-js">. . .

ctx.lineWidth = <span class="hljs-number">6</span>;

<span class="hljs-comment">// Draw the Nostrils</span>
ctx.beginPath();
ctx.moveTo(<span class="hljs-number">-14</span>, <span class="hljs-number">266</span>);
ctx.lineTo(<span class="hljs-number">-6</span>, <span class="hljs-number">260</span>);

ctx.moveTo(<span class="hljs-number">14</span>, <span class="hljs-number">266</span>);
ctx.lineTo(+<span class="hljs-number">6</span>, <span class="hljs-number">260</span>);
ctx.stroke();

. . .
</code></pre>
<p>And finally, we'll also add a path for the mouth. This could be part of the same path as the nose, because it has the same line width and color, but might be clearer to have them separate.</p>
<pre><code class="lang-js">. . .

<span class="hljs-comment">// Draw the Mouth</span>
ctx.beginPath();
ctx.moveTo(<span class="hljs-number">-20</span>, <span class="hljs-number">230</span>);
ctx.quadraticCurveTo(<span class="hljs-number">0</span>, <span class="hljs-number">245</span>, <span class="hljs-number">20</span>, <span class="hljs-number">230</span>);
ctx.stroke();
</code></pre>
<p>Let's draw another quadratic curve. This is similar to the one we used for the arms. The start and endpoint of this curve are on the same level, but the control point is a bit higher so the middle of the mouth is higher than the two sides.</p>
<h2 id="heading-next-steps">Next Steps</h2>
<p>Now that we have a basic gorilla, what can we do with it? We can build a whole game around it. In this <a target="_blank" href="https://www.freecodecamp.org/news/gorillas-game-in-javascript/">JavaScript Game Tutorial</a> we rebuild the 1991 classic game, Gorillas.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/Screenshot-2024-01-19-at-23.49.34.png" alt="Image" width="600" height="400" loading="lazy">
<em>Screenshot from the JavaScript Game Tutorial</em></p>
<p>For a deep dive, read the <a target="_blank" href="https://www.freecodecamp.org/news/gorillas-game-in-javascript/">full tutorial</a> where we build up a complete game with plain JavaScript. In this tutorial, we not only cover how to draw the gorillas and the city skyline but also implement the whole game logic. From event handling, through the animation loop, to hit detection.</p>
<p>For even more, you can also watch the <a target="_blank" href="https://www.youtube.com/watch?v=2q5EufbUEQk">extended tutorial on YouTube</a>. In the YouTube version, we also cover how to make the buildings destructible, how to animate the hand of the gorilla to follow the drag movement while aiming, have nicer graphics, and we add AI logic, so you can play against the computer.</p>
<p>Check it out to learn more:</p>
<p><a target="_blank" href="https://www.youtube.com/embed/2q5EufbUEQk?feature=oembed">Embedded content</a></p>
<p>You can subscribe to my channel for more JavaScript game development tutorials:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/undefined" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
