<?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" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Amol Pawar on Medium]]></title>
        <description><![CDATA[Stories by Amol Pawar on Medium]]></description>
        <link>https://medium.com/@amolpawar.me?source=rss-18c7290112c7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zgHJMNu7pPe0F0xs4Lap9Q.png</url>
            <title>Stories by Amol Pawar on Medium</title>
            <link>https://medium.com/@amolpawar.me?source=rss-18c7290112c7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 11:44:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amolpawar.me/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[HTML Marquee Tag Explained: Complete Guide with Examples and Output]]></title>
            <link>https://medium.com/@amolpawar.me/html-marquee-tag-explained-complete-guide-with-examples-and-output-c96090920699?source=rss-18c7290112c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/c96090920699</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Amol Pawar]]></dc:creator>
            <pubDate>Fri, 30 Oct 2026 15:42:12 GMT</pubDate>
            <atom:updated>2026-10-30T15:42:12.518Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>Learn how the HTML marquee tag works, explore its attributes, scrolling directions, behaviors, practical examples, expected outputs, and modern CSS alternatives.</em></h4><h3>Introduction</h3><p>Have you ever visited a website where text or images continuously move from one side of the screen to another?</p><p>For example:</p><ul><li>Breaking news scrolling across a webpage.</li><li>Announcements moving horizontally.</li><li>Text moving from left to right.</li><li>Images continuously scrolling across a section.</li></ul><p>In older HTML websites, developers commonly used the <strong>&lt;marquee&gt; tag</strong> to create these scrolling effects.</p><p>Although the &lt;marquee&gt; tag is easy to understand, it is obsolete and non-standard in modern HTML. Today, CSS animations are recommended for creating scrolling effects.</p><p>In this article, we will learn the marquee tag from basics to advanced concepts, including its syntax, important attributes, scrolling directions, practical examples with expected outputs, limitations, and modern CSS alternatives.</p><h3>1. What Is the HTML Marquee Tag?</h3><p>The HTML &lt;marquee&gt; tag was used to create automatically scrolling text, images, or other content inside a webpage.</p><p>It could move content horizontally or vertically.</p><p><strong>Syntax:</strong></p><pre>&lt;marquee&gt;<br>    Your scrolling content here<br>&lt;/marquee&gt;</pre><p><strong>Example:</strong></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Marquee Example&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h2&gt;HTML Marquee Example&lt;/h2&gt;</pre><pre>    &lt;marquee&gt;<br>        Welcome to My Website!<br>    &lt;/marquee&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Expected Output:</strong></p><p>The text “Welcome to My Website!” continuously scrolls across the webpage from right to left using the browser’s traditional marquee behavior.</p><p><strong>Important:</strong> The &lt;marquee&gt; element is obsolete and non-standard. It should not be used in new projects. Use CSS animations instead.</p><h3>2. Why Do We Use the Marquee Tag?</h3><p>The marquee tag was commonly used to display moving content without requiring JavaScript.</p><p>Some common use cases included:</p><ul><li><strong>Breaking news:</strong> Display scrolling news headlines.</li><li><strong>Announcements:</strong> Show important messages on websites.</li><li><strong>Scrolling text:</strong> Move text horizontally or vertically.</li><li><strong>Scrolling images:</strong> Display multiple images in a moving sequence.</li><li><strong>Promotional content:</strong> Display offers and advertisements.</li></ul><p>Although these were common historical use cases, modern developers generally use CSS animations to achieve similar results.</p><h3>3. Important Attributes of the Marquee Tag</h3><p>The traditional marquee element supported several attributes to control scrolling direction, speed, behavior, and appearance.</p><p>Let’s understand them one by one.</p><h3>3.1. direction Attribute</h3><p>The direction attribute specifies the direction in which the content moves.</p><p>It supports four commonly used values:</p><ul><li>left – Moves content from right to left.</li><li>right – Moves content from left to right.</li><li>up – Moves content from bottom to top.</li><li>down – Moves content from top to bottom.</li></ul><p><strong>Example 1: Direction Left</strong></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Marquee Left&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h2&gt;Direction Left&lt;/h2&gt;</pre><pre>    &lt;marquee direction=&quot;left&quot;&gt;<br>        Welcome to HTML!<br>    &lt;/marquee&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Expected Output:</strong></p><p>The text moves horizontally from right to left.</p><p><strong>Example 2: Direction Right</strong></p><pre>&lt;marquee direction=&quot;right&quot;&gt;<br>    Welcome to HTML!<br>&lt;/marquee&gt;</pre><p><strong>Expected Output:</strong></p><p>The text moves horizontally from left to right.</p><p><strong>Example 3: Direction Up</strong></p><pre>&lt;marquee direction=&quot;up&quot; height=&quot;150&quot;&gt;<br>    Welcome to HTML!<br>&lt;/marquee&gt;</pre><p><strong>Expected Output:</strong></p><p>The text moves vertically from bottom to top inside the marquee area.</p><p><strong>Example 4: Direction Down</strong></p><pre>&lt;marquee direction=&quot;down&quot; height=&quot;150&quot;&gt;<br>    Welcome to HTML!<br>&lt;/marquee&gt;</pre><p><strong>Expected Output:</strong></p><p>The text moves vertically from top to bottom inside the marquee area.</p><h3>3.2. behavior Attribute</h3><p>The behavior attribute specifies how the scrolling content behaves.</p><p>It supports three traditional values:</p><ul><li>scroll – Content continuously moves in the specified direction.</li><li>slide – Content moves in the specified direction and stops when it reaches the end.</li><li>alternate – Content moves back and forth between the boundaries.</li></ul><p><strong>Example 1: Scroll</strong></p><pre>&lt;marquee behavior=&quot;scroll&quot;&gt;<br>    This is scrolling text.<br>&lt;/marquee&gt;</pre><p><strong>Expected Output:</strong></p><p>The text continuously moves across the marquee area.</p><p><strong>Example 2: Slide</strong></p><pre>&lt;marquee behavior=&quot;slide&quot;&gt;<br>    This is sliding text.<br>&lt;/marquee&gt;</pre><p><strong>Expected Output:</strong></p><p>The text moves across the marquee area and stops at the end.</p><p><strong>Example 3: Alternate</strong></p><pre>&lt;marquee behavior=&quot;alternate&quot;&gt;<br>    This is alternate text.<br>&lt;/marquee&gt;</pre><p><strong>Expected Output:</strong></p><p>The text moves back and forth between the left and right boundaries.</p><h3>3.3. scrollamount Attribute</h3><p>The scrollamount attribute specifies how many pixels the content moves in each scrolling step.</p><p>A larger value generally makes the content move faster.</p><p><strong>Example:</strong></p><pre>&lt;marquee scrollamount=&quot;10&quot;&gt;<br>    Fast Scrolling Text<br>&lt;/marquee&gt;</pre><p><strong>Expected Output:</strong></p><p>The text scrolls faster than it would with a smaller scrollamount value.</p><p><strong>Comparison:</strong></p><pre>&lt;marquee scrollamount=&quot;2&quot;&gt;<br>    Slow Scrolling Text<br>&lt;/marquee&gt;</pre><pre>&lt;br&gt;&lt;br&gt;</pre><pre>&lt;marquee scrollamount=&quot;10&quot;&gt;<br>    Fast Scrolling Text<br>&lt;/marquee&gt;</pre><p><strong>Expected Output:</strong></p><ul><li>The first text moves slowly.</li><li>The second text moves faster.</li></ul><h3>3.4. scrolldelay Attribute</h3><p>The scrolldelay attribute specifies the delay, in milliseconds, between scrolling steps.</p><p>A larger delay generally makes the scrolling slower.</p><p><strong>Example:</strong></p><pre>&lt;marquee scrolldelay=&quot;200&quot;&gt;<br>    Delayed Scrolling Text<br>&lt;/marquee&gt;</pre><p><strong>Expected Output:</strong></p><p>The text moves with a longer delay between scrolling steps.</p><p><strong>Comparison:</strong></p><pre>&lt;marquee scrolldelay=&quot;50&quot;&gt;<br>    Normal Scrolling<br>&lt;/marquee&gt;</pre><pre>&lt;br&gt;&lt;br&gt;</pre><pre>&lt;marquee scrolldelay=&quot;300&quot;&gt;<br>    Slow Scrolling<br>&lt;/marquee&gt;</pre><p><strong>Expected Output:</strong></p><ul><li>The first text moves with shorter delays.</li><li>The second text moves with longer delays.</li></ul><p><strong>Important:</strong> scrolldelay controls the delay between steps, whereas scrollamount controls the distance moved per step.</p><h3>3.5. loop Attribute</h3><p>The loop attribute specifies how many times the marquee animation repeats.</p><p><strong>Example:</strong></p><pre>&lt;marquee loop=&quot;3&quot;&gt;<br>    This text scrolls three times.<br>&lt;/marquee&gt;</pre><p><strong>Expected Output:</strong></p><p>The marquee animation repeats three times and then stops.</p><p><strong>Another Example:</strong></p><pre>&lt;marquee loop=&quot;5&quot;&gt;<br>    Welcome to My Website!<br>&lt;/marquee&gt;</pre><p><strong>Expected Output:</strong></p><p>The scrolling animation repeats five times.</p><h3>3.6. width Attribute</h3><p>The width attribute specifies the width of the marquee area.</p><p><strong>Example:</strong></p><pre>&lt;marquee width=&quot;500&quot;&gt;<br>    Welcome to HTML!<br>&lt;/marquee&gt;</pre><p><strong>Expected Output:</strong></p><p>The scrolling content moves inside a marquee area with a width of 500 pixels.</p><h3>3.7. height Attribute</h3><p>The height attribute specifies the height of the marquee area.</p><p><strong>Example:</strong></p><pre>&lt;marquee direction=&quot;up&quot; height=&quot;200&quot;&gt;<br>    Welcome to HTML!<br>&lt;/marquee&gt;</pre><p><strong>Expected Output:</strong></p><p>The marquee area has a height of 200 pixels, and the text moves upward.</p><h3>3.8. bgcolor Attribute</h3><p>The bgcolor attribute specifies the background color of the marquee area.</p><p><strong>Example:</strong></p><pre>&lt;marquee bgcolor=&quot;yellow&quot;&gt;<br>    Welcome to HTML!<br>&lt;/marquee&gt;</pre><p><strong>Expected Output:</strong></p><p>The marquee area displays a yellow background while the text scrolls.</p><p><strong>Note:</strong> bgcolor is an obsolete presentation attribute. Use CSS background-color in modern HTML.</p><h3>3.9. hspace Attribute</h3><p>The hspace attribute specifies horizontal space around the marquee.</p><p><strong>Example:</strong></p><pre>&lt;marquee hspace=&quot;50&quot;&gt;<br>    Welcome to HTML!<br>&lt;/marquee&gt;</pre><p><strong>Expected Output:</strong></p><p>The marquee has horizontal spacing around it in browsers that support this legacy attribute.</p><h3>3.10. vspace Attribute</h3><p>The vspace attribute specifies vertical space around the marquee.</p><p><strong>Example:</strong></p><pre>&lt;marquee vspace=&quot;30&quot;&gt;<br>    Welcome to HTML!<br>&lt;/marquee&gt;</pre><p><strong>Expected Output:</strong></p><p>The marquee has vertical spacing around it in browsers that support this legacy attribute.</p><p><strong>Note:</strong> hspace and vspace are obsolete. Use CSS margin and padding instead.</p><h3>4. Complete Example Using Marquee Attributes</h3><p>Let’s combine multiple marquee attributes in a single HTML program.</p><p><strong>Example:</strong></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Marquee Attributes&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h2&gt;HTML Marquee Attributes&lt;/h2&gt;</pre><pre>    &lt;marquee<br>        direction=&quot;left&quot;<br>        behavior=&quot;alternate&quot;<br>        scrollamount=&quot;8&quot;<br>        scrolldelay=&quot;100&quot;<br>        width=&quot;600&quot;<br>        height=&quot;50&quot;<br>        bgcolor=&quot;lightyellow&quot;<br>        loop=&quot;3&quot;&gt;</pre><pre>        Welcome to HTML Marquee!</pre><pre>    &lt;/marquee&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Expected Output:</strong></p><ul><li>The marquee area has a width of 600 pixels.</li><li>The marquee area has a height of 50 pixels.</li><li>The background color is light yellow.</li><li>The text moves from side to side.</li><li>The scrolling speed is controlled by scrollamount.</li><li>The delay is controlled by scrolldelay.</li><li>The animation repeats three times.</li></ul><p><strong>Note:</strong> The exact scrolling appearance and timing can vary between browsers.</p><h3>5. Scrolling Images Using the Marquee Tag</h3><p>The marquee element was also commonly used to scroll images.</p><p><strong>Example:</strong></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Scrolling Images&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h2&gt;Scrolling Images&lt;/h2&gt;</pre><pre>    &lt;marquee direction=&quot;left&quot;&gt;</pre><pre>        &lt;img src=&quot;image1.jpg&quot; width=&quot;150&quot; alt=&quot;Image 1&quot;&gt;</pre><pre>        &lt;img src=&quot;image2.jpg&quot; width=&quot;150&quot; alt=&quot;Image 2&quot;&gt;</pre><pre>        &lt;img src=&quot;image3.jpg&quot; width=&quot;150&quot; alt=&quot;Image 3&quot;&gt;</pre><pre>    &lt;/marquee&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Expected Output:</strong></p><p>Three images move continuously from right to left.</p><p><strong>Important:</strong> Replace image1.jpg, image2.jpg, and image3.jpg with valid image paths.</p><h3>6. Difference Between Scroll, Slide, and Alternate</h3><p>The behavior attribute supports three traditional scrolling behaviors.</p><p>BehaviorDescriptionscrollContent continuously moves in one direction.slideContent moves and stops at the end.alternateContent moves back and forth.</p><p><strong>Example:</strong></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Marquee Behavior&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h3&gt;Scroll Behavior&lt;/h3&gt;<br>    &lt;marquee behavior=&quot;scroll&quot;&gt;<br>        Scroll Example<br>    &lt;/marquee&gt;</pre><pre>    &lt;h3&gt;Slide Behavior&lt;/h3&gt;<br>    &lt;marquee behavior=&quot;slide&quot;&gt;<br>        Slide Example<br>    &lt;/marquee&gt;</pre><pre>    &lt;h3&gt;Alternate Behavior&lt;/h3&gt;<br>    &lt;marquee behavior=&quot;alternate&quot;&gt;<br>        Alternate Example<br>    &lt;/marquee&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Expected Output:</strong></p><ul><li>Scroll: Text continuously moves in one direction.</li><li>Slide: Text moves and stops at the end.</li><li>Alternate: Text moves back and forth.</li></ul><h3>7. Important Limitations of the Marquee Tag</h3><p>Although the marquee tag was useful in older websites, it has several limitations.</p><ul><li>It is obsolete and non-standard in modern HTML.</li><li>Its behavior and appearance can vary between browsers.</li><li>It provides limited control over animation.</li><li>Continuously moving content can be difficult for some users to read.</li><li>It can create accessibility problems for users with motion sensitivity.</li><li>Its legacy attributes are not suitable for modern web development.</li></ul><p><strong>Recommendation:</strong> Avoid using the &lt;marquee&gt; tag in new projects. Use CSS animations instead.</p><h3>8. Modern Alternative to the Marquee Tag Using CSS</h3><p>Today, developers use CSS animations to create scrolling text and other moving content.</p><p>CSS provides better control over animation speed, direction, timing, and appearance.</p><h3>Example 1: Scrolling Text from Right to Left</h3><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;CSS Scrolling Text&lt;/title&gt;</pre><pre>    &lt;style&gt;<br>        .marquee {<br>            width: 100%;<br>            overflow: hidden;<br>            white-space: nowrap;<br>            background-color: lightyellow;<br>        }</pre><pre>        .marquee-text {<br>            display: inline-block;<br>            animation: scroll 8s linear infinite;<br>        }</pre><pre>        @keyframes scroll {<br>            from {<br>                transform: translateX(100%);<br>            }</pre><pre>            to {<br>                transform: translateX(-100%);<br>            }<br>        }<br>    &lt;/style&gt;</pre><pre>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h2&gt;CSS Marquee Example&lt;/h2&gt;</pre><pre>    &lt;div class=&quot;marquee&quot;&gt;<br>        &lt;div class=&quot;marquee-text&quot;&gt;<br>            Welcome to Modern Web Development!<br>        &lt;/div&gt;<br>    &lt;/div&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Expected Output:</strong></p><p>The text continuously moves from right to left inside a light-yellow container.</p><h3>Example 2: Scrolling Text from Left to Right</h3><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Left to Right Animation&lt;/title&gt;</pre><pre>    &lt;style&gt;<br>        .marquee {<br>            width: 100%;<br>            overflow: hidden;<br>            white-space: nowrap;<br>        }</pre><pre>        .marquee-text {<br>            display: inline-block;<br>            animation: moveRight 8s linear infinite;<br>        }</pre><pre>        @keyframes moveRight {<br>            from {<br>                transform: translateX(-100%);<br>            }</pre><pre>            to {<br>                transform: translateX(100%);<br>            }<br>        }<br>    &lt;/style&gt;</pre><pre>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h2&gt;Left to Right Scrolling&lt;/h2&gt;</pre><pre>    &lt;div class=&quot;marquee&quot;&gt;<br>        &lt;div class=&quot;marquee-text&quot;&gt;<br>            Welcome to HTML and CSS!<br>        &lt;/div&gt;<br>    &lt;/div&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Expected Output:</strong></p><p>The text continuously moves from left to right.</p><h3>Example 3: Pausing Animation on Hover</h3><p>We can also pause the scrolling animation when the user moves the mouse over the text.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Pause on Hover&lt;/title&gt;</pre><pre>    &lt;style&gt;<br>        .marquee {<br>            width: 100%;<br>            overflow: hidden;<br>            white-space: nowrap;<br>            background-color: lightblue;<br>        }</pre><pre>        .marquee-text {<br>            display: inline-block;<br>            padding: 10px;<br>            animation: scroll 8s linear infinite;<br>        }</pre><pre>        .marquee:hover .marquee-text {<br>            animation-play-state: paused;<br>        }</pre><pre>        @keyframes scroll {<br>            from {<br>                transform: translateX(100%);<br>            }</pre><pre>            to {<br>                transform: translateX(-100%);<br>            }<br>        }<br>    &lt;/style&gt;</pre><pre>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h2&gt;Pause Animation on Hover&lt;/h2&gt;</pre><pre>    &lt;div class=&quot;marquee&quot;&gt;<br>        &lt;div class=&quot;marquee-text&quot;&gt;<br>            Move your mouse over this text to pause!<br>        &lt;/div&gt;<br>    &lt;/div&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Expected Output:</strong></p><ul><li>The text continuously moves from right to left.</li><li>When the mouse moves over the scrolling area, the animation pauses.</li><li>When the mouse leaves the area, the animation continues.</li></ul><p><strong>Accessibility Tip:</strong> Consider respecting the user’s reduced-motion preference with the prefers-reduced-motion media query. Avoid forcing continuous motion on users who prefer reduced animation.</p><h3>9. Important Marquee Attributes Summary</h3><p>AttributeDescriptiondirectionSpecifies the scrolling direction.behaviorSpecifies the scrolling behavior.scrollamountControls the distance moved per scrolling step.scrolldelayControls the delay between scrolling steps.loopSpecifies how many times the animation repeats.widthSpecifies the marquee width.heightSpecifies the marquee height.bgcolorSpecifies the background color.hspaceSpecifies horizontal spacing.vspaceSpecifies vertical spacing.</p><p><strong>Remember:</strong> These are legacy marquee attributes. They are useful to understand when studying older HTML code, but modern projects should use CSS.</p><h3>10. Best Practices</h3><ul><li>Avoid using the obsolete &lt;marquee&gt; tag in new projects.</li><li>Use CSS animations for scrolling effects.</li><li>Keep moving content readable.</li><li>Avoid unnecessary continuous animations.</li><li>Provide a way to pause animations when appropriate.</li><li>Respect the prefers-reduced-motion accessibility preference.</li><li>Use semantic HTML elements where appropriate.</li><li>Test animations on desktop and mobile devices.</li></ul><h3>11. Frequently Asked Interview Questions</h3><p><strong>Q1. What is the marquee tag in HTML?</strong></p><p>The &lt;marquee&gt; tag was used to create scrolling text, images, and other content on a webpage.</p><p><strong>Q2. Is marquee an abbreviation?</strong></p><p>No. Marquee is not an abbreviation. It is the name of the HTML element used for scrolling content.</p><p><strong>Q3. Which attribute controls the scrolling direction?</strong></p><p>The direction attribute controls the scrolling direction.</p><p><strong>Q4. What are the values of the direction attribute?</strong></p><p>The traditional values are left, right, up, and down.</p><p><strong>Q5. What is the difference between scroll and alternate behavior?</strong></p><ul><li>scroll continuously moves content in one direction.</li><li>alternate moves content back and forth.</li></ul><p><strong>Q6. Which attribute controls scrolling speed?</strong></p><p>The scrollamount attribute controls the distance moved per scrolling step. A larger value generally makes the content move faster.</p><p><strong>Q7. What is the purpose of the loop attribute?</strong></p><p>The loop attribute specifies how many times the marquee animation repeats.</p><p><strong>Q8. Is the marquee tag recommended in modern HTML?</strong></p><p>No. The marquee element is obsolete and non-standard. CSS animations are recommended for modern websites.</p><p><strong>Q9. What is the modern alternative to the marquee tag?</strong></p><p>CSS animations using @keyframes and the animation property are modern alternatives.</p><p><strong>Q10. Can we scroll images using the marquee tag?</strong></p><p>Yes. Images could be placed inside the marquee element to create scrolling image effects.</p><h3>Conclusion</h3><p>The HTML &lt;marquee&gt; tag was traditionally used to create scrolling text and images on webpages.</p><p>It supported different scrolling directions, behaviors, speeds, delays, and repetition settings through its attributes.</p><p>However, the marquee element is obsolete and should not be used in modern web development.</p><p>Today, CSS animations provide a better and more flexible way to create scrolling effects.</p><p>Understanding the marquee tag is still useful when learning HTML and working with older websites. However, for modern projects, always prefer CSS-based animations.</p><p><strong>Keep Learning. Keep Building. Keep Coding! 🚀</strong></p><h3>About the Author</h3><p><strong>Amol Pawar</strong></p><p>Web Developer | HTML | CSS | JavaScript | React | MERN Stack</p><p>I share beginner-friendly articles about web development, programming concepts, and practical coding examples.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c96090920699" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTML Iframe Tag Explained: Complete Guide with Examples and Output]]></title>
            <link>https://medium.com/@amolpawar.me/html-iframe-tag-explained-complete-guide-with-examples-and-output-55a07a0a4c95?source=rss-18c7290112c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/55a07a0a4c95</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[htm]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Amol Pawar]]></dc:creator>
            <pubDate>Fri, 30 Oct 2026 15:37:42 GMT</pubDate>
            <atom:updated>2026-10-30T15:37:42.106Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>Learn how to embed websites, YouTube videos, Google Maps, and other external content in HTML using the </em><em>&lt;iframe&gt; tag.</em></h4><h3>Introduction</h3><p>HTML provides many elements for displaying content on a webpage. Sometimes, we need to display content from another webpage or an external service inside our own webpage.</p><p>For example:</p><ul><li>Display a YouTube video on a website.</li><li>Embed a Google Map showing a location.</li><li>Display another webpage inside the current webpage.</li><li>Embed documents or other external content.</li></ul><p>HTML provides the <strong>&lt;iframe&gt; tag</strong> to perform these tasks.</p><p>An iframe (Inline Frame) allows us to embed another HTML document or external content within the current webpage.</p><p>In this article, we will learn the HTML iframe tag from basics to advanced concepts, including its syntax, attributes, practical examples, output, responsive design, and security considerations.</p><h3>1. What Is the HTML Iframe Tag?</h3><p>The HTML &lt;iframe&gt; tag is used to embed another webpage or external resource inside the current webpage.</p><p><strong>Syntax:</strong></p><pre>&lt;iframe src=&quot;URL&quot;&gt;&lt;/iframe&gt;</pre><p><strong>Example:</strong></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Iframe Example&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h2&gt;My First Iframe&lt;/h2&gt;</pre><pre>    &lt;iframe<br>        src=&quot;https://example.com&quot;<br>        width=&quot;600&quot;<br>        height=&quot;300&quot;&gt;<br>    &lt;/iframe&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Output:</strong></p><p>The browser displays the content of https://example.com inside a rectangular frame on the current webpage, if that website allows embedding.</p><h3>2. Why Do We Use the Iframe Tag?</h3><p>The iframe tag is useful when we want to display external content without navigating the user away from our webpage.</p><p>Common use cases include:</p><ul><li><strong>YouTube videos:</strong> Embed videos directly into a webpage.</li><li><strong>Google Maps:</strong> Display maps and locations.</li><li><strong>External websites:</strong> Display another webpage inside a page when embedding is permitted.</li><li><strong>Documents:</strong> Embed supported documents or viewers.</li><li><strong>Third-party content:</strong> Display content provided by external services.</li></ul><h3>3. Important Attributes of the Iframe Tag</h3><p>The &lt;iframe&gt; tag supports several attributes that control its source, dimensions, permissions, loading behavior, and security.</p><h3>3.1. src Attribute</h3><p>The src attribute specifies the URL of the webpage or resource to display inside the iframe.</p><p><strong>Example:</strong></p><pre>&lt;iframe src=&quot;https://example.com&quot;&gt;&lt;/iframe&gt;</pre><p><strong>Output:</strong></p><p>The browser attempts to display the Example Domain webpage inside the iframe.</p><h3>3.2. width Attribute</h3><p>The width attribute specifies the width of the iframe.</p><p><strong>Example:</strong></p><pre>&lt;iframe<br>    src=&quot;https://example.com&quot;<br>    width=&quot;500&quot;&gt;<br>&lt;/iframe&gt;</pre><p><strong>Output:</strong></p><p>The iframe is displayed with a width of 500 pixels.</p><h3>3.3. height Attribute</h3><p>The height attribute specifies the height of the iframe.</p><p><strong>Example:</strong></p><pre>&lt;iframe<br>    src=&quot;https://example.com&quot;<br>    width=&quot;500&quot;<br>    height=&quot;300&quot;&gt;<br>&lt;/iframe&gt;</pre><p><strong>Output:</strong></p><p>The iframe is displayed with a width of 500 pixels and a height of 300 pixels.</p><h3>3.4. title Attribute</h3><p>The title attribute provides an accessible description of the iframe.</p><p>It helps screen-reader users understand the purpose of the embedded content.</p><p><strong>Example:</strong></p><pre>&lt;iframe<br>    src=&quot;https://example.com&quot;<br>    title=&quot;Example website&quot;&gt;<br>&lt;/iframe&gt;</pre><p><strong>Output:</strong></p><p>The iframe displays the embedded webpage. The title provides an accessible description.</p><p><strong>Important:</strong> Always provide a meaningful title attribute for iframes.</p><h3>3.5. name Attribute</h3><p>The name attribute gives the iframe a name. This name can be used as a target for links and forms.</p><p><strong>Example:</strong></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;body&gt;</pre><pre>    &lt;h2&gt;Iframe Name Example&lt;/h2&gt;</pre><pre>    &lt;iframe<br>        name=&quot;myFrame&quot;<br>        width=&quot;500&quot;<br>        height=&quot;250&quot;&gt;<br>    &lt;/iframe&gt;</pre><pre>    &lt;br&gt;&lt;br&gt;</pre><pre>    &lt;a href=&quot;https://example.com&quot; target=&quot;myFrame&quot;&gt;<br>        Open Example Website<br>    &lt;/a&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Output:</strong></p><p>When the user clicks the link, the Example Domain webpage opens inside the iframe instead of replacing the entire page.</p><h3>3.6. loading Attribute</h3><p>The loading attribute controls when the browser loads the iframe.</p><p>It supports two commonly used values:</p><ul><li>eager – Loads the iframe immediately.</li><li>lazy – Delays loading until the iframe is near the visible area of the page.</li></ul><p><strong>Example:</strong></p><pre>&lt;iframe<br>    src=&quot;https://example.com&quot;<br>    width=&quot;500&quot;<br>    height=&quot;300&quot;<br>    loading=&quot;lazy&quot;<br>    title=&quot;Example website&quot;&gt;<br>&lt;/iframe&gt;</pre><p><strong>Output:</strong></p><p>The browser delays loading the iframe until it is close to entering the visible area.</p><p><strong>Benefit:</strong> Lazy loading can improve page performance when a webpage contains multiple embedded resources.</p><h3>3.7. allow Attribute</h3><p>The allow attribute specifies which browser features or capabilities the iframe is permitted to use.</p><p><strong>Example:</strong></p><pre>&lt;iframe<br>    src=&quot;https://www.youtube.com/embed/VIDEO_ID&quot;<br>    allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot;<br>    title=&quot;YouTube video&quot;&gt;<br>&lt;/iframe&gt;</pre><p><strong>Output:</strong></p><p>The embedded YouTube player can use the specified browser features, subject to browser permissions and the embedding service’s rules.</p><h3>3.8. allowfullscreen Attribute</h3><p>The allowfullscreen attribute allows embedded content to enter fullscreen mode when supported.</p><p><strong>Example:</strong></p><pre>&lt;iframe<br>    src=&quot;https://www.youtube.com/embed/VIDEO_ID&quot;<br>    width=&quot;560&quot;<br>    height=&quot;315&quot;<br>    allowfullscreen<br>    title=&quot;YouTube video&quot;&gt;<br>&lt;/iframe&gt;</pre><p><strong>Output:</strong></p><p>The embedded video can provide a fullscreen option.</p><h3>3.9. sandbox Attribute</h3><p>The sandbox attribute applies additional restrictions to the content loaded inside an iframe.</p><p>It is useful when embedding content that should have limited access to browser capabilities.</p><p><strong>Example:</strong></p><pre>&lt;iframe<br>    src=&quot;https://example.com&quot;<br>    width=&quot;500&quot;<br>    height=&quot;300&quot;<br>    sandbox<br>    title=&quot;Restricted embedded page&quot;&gt;<br>&lt;/iframe&gt;</pre><p><strong>Output:</strong></p><p>The browser loads the embedded page with sandbox restrictions.</p><p>Some scripts, forms, pop-ups, and other capabilities may be blocked.</p><p>You can selectively allow certain capabilities using sandbox tokens.</p><p>For example:</p><pre>&lt;iframe<br>    src=&quot;https://example.com&quot;<br>    sandbox=&quot;allow-scripts&quot;<br>    title=&quot;Embedded page&quot;&gt;<br>&lt;/iframe&gt;</pre><p>This allows scripts to run inside the sandbox while keeping other sandbox restrictions in place.</p><p><strong>Important:</strong> Avoid combining allow-scripts and allow-same-origin for untrusted content from the same origin as the parent page. This combination can weaken the protection provided by sandboxing.</p><h3>3.10. referrerpolicy Attribute</h3><p>The referrerpolicy attribute controls how much referrer information the browser sends when requesting the iframe resource.</p><p><strong>Example:</strong></p><pre>&lt;iframe<br>    src=&quot;https://example.com&quot;<br>    referrerpolicy=&quot;no-referrer&quot;<br>    title=&quot;Example website&quot;&gt;<br>&lt;/iframe&gt;</pre><p><strong>Output:</strong></p><p>The browser does not send referrer information with the iframe request.</p><h3>4. Embedding a Website Using Iframe</h3><p>We can display an external website inside our webpage using the src attribute.</p><p><strong>Example:</strong></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Website Embedding&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h2&gt;Embedded Website&lt;/h2&gt;</pre><pre>    &lt;iframe<br>        src=&quot;https://example.com&quot;<br>        width=&quot;700&quot;<br>        height=&quot;400&quot;<br>        title=&quot;Example website&quot;&gt;<br>    &lt;/iframe&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Output:</strong></p><p>A frame appears on the webpage and displays the Example Domain website, provided the website permits embedding.</p><p><strong>Note:</strong> Some websites block iframe embedding using security policies such as X-Frame-Options or Content Security Policy (frame-ancestors). In that case, the browser will not display the website inside the iframe.</p><h3>5. Embedding a YouTube Video Using Iframe</h3><p>One of the most common uses of the iframe tag is embedding YouTube videos.</p><p>YouTube provides an embed option that generates iframe code for a video.</p><p><strong>Example:</strong></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;YouTube Video&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h2&gt;My YouTube Video&lt;/h2&gt;</pre><pre>    &lt;iframe<br>        width=&quot;560&quot;<br>        height=&quot;315&quot;<br>        src=&quot;https://www.youtube.com/embed/VIDEO_ID&quot;<br>        title=&quot;YouTube video player&quot;<br>        allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot;<br>        allowfullscreen&gt;<br>    &lt;/iframe&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Output:</strong></p><p>A YouTube video player appears on the webpage.</p><p><strong>Important:</strong> Replace VIDEO_ID with the actual YouTube video ID.</p><p>For example, if a video URL is:</p><pre>https://www.youtube.com/watch?v=abc123xyz</pre><p>The video ID is:</p><pre>abc123xyz</pre><p>The embed URL becomes:</p><pre>https://www.youtube.com/embed/abc123xyz</pre><h3>6. Embedding Google Maps Using Iframe</h3><p>We can also display Google Maps on a webpage using an iframe.</p><p>Google Maps provides an embed feature that generates the required iframe code.</p><p><strong>Example:</strong></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Google Maps&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h2&gt;Our Location&lt;/h2&gt;</pre><pre>    &lt;iframe<br>        src=&quot;YOUR_GOOGLE_MAPS_EMBED_URL&quot;<br>        width=&quot;600&quot;<br>        height=&quot;450&quot;<br>        style=&quot;border:0;&quot;<br>        allowfullscreen<br>        loading=&quot;lazy&quot;<br>        referrerpolicy=&quot;no-referrer-when-downgrade&quot;<br>        title=&quot;Google Maps location&quot;&gt;<br>    &lt;/iframe&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Output:</strong></p><p>Google Maps appears inside the webpage and displays the selected location.</p><p><strong>How to get the embed URL:</strong></p><ul><li>Open Google Maps.</li><li>Search for the required location.</li><li>Click <strong>Share</strong>.</li><li>Select <strong>Embed a map</strong>.</li><li>Copy the generated iframe code.</li><li>Paste it into your HTML file.</li></ul><h3>7. Using the srcdoc Attribute</h3><p>The srcdoc attribute allows us to specify HTML content directly inside an iframe instead of loading an external URL.</p><p><strong>Example:</strong></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Srcdoc Example&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h2&gt;Iframe srcdoc Example&lt;/h2&gt;</pre><pre>    &lt;iframe<br>        width=&quot;400&quot;<br>        height=&quot;200&quot;<br>        srcdoc=&quot;&lt;h2&gt;Hello World!&lt;/h2&gt;&lt;p&gt;This content is inside an iframe.&lt;/p&gt;&quot;<br>        title=&quot;Inline HTML content&quot;&gt;<br>    &lt;/iframe&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Output:</strong></p><p>The iframe displays:</p><pre>Hello World!</pre><pre>This content is inside an iframe.</pre><p><strong>Important:</strong> When both src and srcdoc are provided, srcdoc takes precedence in modern browsers.</p><h3>8. Making an Iframe Responsive</h3><p>A fixed-width iframe may not fit properly on mobile devices.</p><p>We can use CSS to make an iframe responsive.</p><p><strong>Example:</strong></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Responsive Iframe&lt;/title&gt;</pre><pre>    &lt;style&gt;<br>        .iframe-container {<br>            width: 100%;<br>            aspect-ratio: 16 / 9;<br>        }</pre><pre>        .iframe-container iframe {<br>            width: 100%;<br>            height: 100%;<br>            border: none;<br>        }<br>    &lt;/style&gt;</pre><pre>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h2&gt;Responsive YouTube Video&lt;/h2&gt;</pre><pre>    &lt;div class=&quot;iframe-container&quot;&gt;<br>        &lt;iframe<br>            src=&quot;https://www.youtube.com/embed/VIDEO_ID&quot;<br>            title=&quot;Responsive YouTube video&quot;<br>            allowfullscreen&gt;<br>        &lt;/iframe&gt;<br>    &lt;/div&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Output:</strong></p><p>The iframe adjusts to the width of its parent container while maintaining a 16:9 aspect ratio.</p><p><strong>Benefits:</strong></p><ul><li>Works on desktop screens.</li><li>Adjusts to mobile screen sizes.</li><li>Maintains the video aspect ratio.</li><li>Avoids unnecessary horizontal scrolling.</li></ul><h3>9. Important Security Considerations</h3><p>When using iframes, security should always be considered.</p><h3>Use the sandbox Attribute</h3><p>Use sandbox restrictions when embedding untrusted content.</p><pre>&lt;iframe<br>    src=&quot;https://example.com&quot;<br>    sandbox<br>    title=&quot;Restricted content&quot;&gt;<br>&lt;/iframe&gt;</pre><h3>Embed Trusted Websites</h3><p>Only embed content from websites and services you trust.</p><h3>Use HTTPS</h3><p>Prefer secure HTTPS URLs when embedding external content.</p><h3>Understand the Same-Origin Policy</h3><p>Browsers restrict how documents from different origins can access each other’s content.</p><p>For example, JavaScript running on your website generally cannot directly read the contents of an iframe loaded from a different origin.</p><h3>Use postMessage() for Cross-Origin Communication</h3><p>When two documents need to communicate across different origins, the browser provides the postMessage() API.</p><p>Always validate the message origin before trusting received data.</p><h3>10. Difference Between Iframe and Object Tags</h3><p>Both &lt;iframe&gt; and &lt;object&gt; can embed external resources, but they serve different purposes.</p><p>IframeObjectEmbeds another HTML browsing context.Embeds an external resource.Commonly used for websites, videos, and maps.Commonly used for resources such as PDFs and other embedded content.Uses the src attribute.Uses the data attribute.Creates a separate browsing context.Does not necessarily create a browsing context.</p><p><strong>Iframe example:</strong></p><pre>&lt;iframe<br>    src=&quot;https://example.com&quot;<br>    width=&quot;500&quot;<br>    height=&quot;300&quot;<br>    title=&quot;Example website&quot;&gt;<br>&lt;/iframe&gt;</pre><p><strong>Object example:</strong></p><pre>&lt;object<br>    data=&quot;document.pdf&quot;<br>    type=&quot;application/pdf&quot;<br>    width=&quot;500&quot;<br>    height=&quot;300&quot;&gt;<br>&lt;/object&gt;</pre><h3>11. Important Iframe Attributes Summary</h3><p>AttributeDescriptionsrcSpecifies the URL of the embedded resource.widthSpecifies the iframe width.heightSpecifies the iframe height.titleProvides an accessible description.nameGives the iframe a browsing-context name.loadingControls iframe loading behavior.allowControls permitted browser features.allowfullscreenAllows fullscreen presentation.sandboxApplies security restrictions.referrerpolicyControls referrer information.srcdocProvides inline HTML content.</p><h3>12. Best Practices When Using Iframes</h3><ul><li>Always provide a meaningful title attribute.</li><li>Use loading=&quot;lazy&quot; for off-screen iframe content when appropriate.</li><li>Make iframes responsive using CSS.</li><li>Embed content only from trusted sources.</li><li>Use the sandbox attribute when appropriate.</li><li>Avoid unnecessary iframe usage because embedded resources can affect page performance.</li><li>Prefer HTTPS URLs.</li><li>Use the correct embed URL provided by services such as YouTube and Google Maps.</li><li>Do not assume every external website allows iframe embedding.</li></ul><h3>13. Frequently Asked Interview Questions</h3><p><strong>Q1. What is an iframe in HTML?</strong></p><p>An iframe (Inline Frame) is an HTML element used to embed another HTML document or external resource inside the current webpage.</p><p><strong>Q2. Which HTML tag is used to create an iframe?</strong></p><p>The &lt;iframe&gt; tag is used to create an inline frame.</p><p><strong>Q3. What is the purpose of the </strong><strong>src attribute?</strong></p><p>The src attribute specifies the URL of the resource to display inside the iframe.</p><p><strong>Q4. Can we embed a YouTube video using an iframe?</strong></p><p>Yes. YouTube provides an embed URL that can be used with the iframe tag.</p><p><strong>Q5. What is the purpose of the </strong><strong>sandbox attribute?</strong></p><p>The sandbox attribute applies additional restrictions to the content loaded inside an iframe.</p><p><strong>Q6. What is the purpose of the </strong><strong>loading=&quot;lazy&quot; attribute?</strong></p><p>It delays loading the iframe until it is near the visible area of the webpage.</p><p><strong>Q7. Why do we use the </strong><strong>title attribute?</strong></p><p>It provides an accessible description of the iframe for users of assistive technologies.</p><p><strong>Q8. Can we make an iframe responsive?</strong></p><p>Yes. We can use CSS properties such as width: 100% and aspect-ratio to make an iframe responsive.</p><p><strong>Q9. Why might an external website not load inside an iframe?</strong></p><p>The website may block embedding through security policies such as X-Frame-Options or Content Security Policy.</p><p><strong>Q10. What is the difference between </strong><strong>src and </strong><strong>srcdoc?</strong></p><ul><li>src loads content from an external URL.</li><li>srcdoc provides HTML content directly inside the iframe.</li></ul><h3>Conclusion</h3><p>The HTML &lt;iframe&gt; tag is an important element for embedding external content inside webpages.</p><p>It allows developers to integrate YouTube videos, Google Maps, external webpages, and other resources without redirecting users away from the current page.</p><p>Understanding iframe attributes such as src, width, height, title, loading, allow, and sandbox helps developers create accessible, responsive, and secure webpages.</p><p>If you are learning HTML, practice these examples in your own HTML files to understand how iframes work in real-world web development.</p><p><strong>Happy Coding! 🚀</strong></p><p><em>Author: Amol Pawar</em></p><p><em>Web Developer | JavaScript | React | MERN Stack</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55a07a0a4c95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTML Forms Explained: The Complete Guide to Form Tags, Input Types, Attributes & Validation]]></title>
            <link>https://medium.com/@amolpawar.me/html-forms-explained-the-complete-guide-to-form-tags-input-types-attributes-validation-37c011fea824?source=rss-18c7290112c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/37c011fea824</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Amol Pawar]]></dc:creator>
            <pubDate>Fri, 30 Oct 2026 15:35:02 GMT</pubDate>
            <atom:updated>2026-10-30T15:35:02.435Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>Learn HTML Forms from Beginner to Advanced Level with Practical Examples, Code, and Expected Outputs.</em></h4><h3>Introduction</h3><p>HTML (HyperText Markup Language) is the foundation of web development. It provides various elements and tags to structure web pages and create interactive user interfaces.</p><p>One of the most important concepts in HTML is <strong>HTML Forms</strong>.</p><p>HTML Forms allow websites to collect information from users and submit that information for further processing.</p><p>For example, whenever you:</p><ul><li>Create an account on a website.</li><li>Log in using your email and password.</li><li>Submit a contact form.</li><li>Apply for a job.</li><li>Upload a profile picture.</li><li>Make an online payment.</li></ul><p>You are interacting with an HTML Form.</p><p>In this article, we will understand HTML Forms step by step, covering all important form tags, input types, attributes, validation, and practical examples.</p><p>By the end, you will be able to create your own HTML forms confidently.</p><h3>1. What Are HTML Forms?</h3><p>An HTML Form is a section of a webpage used to collect information from users.</p><p>HTML provides the &lt;form&gt; element to create forms and different form controls to collect user information.</p><p><strong>Syntax:</strong></p><pre>&lt;form&gt;<br>    &lt;!-- Form elements --&gt;<br>&lt;/form&gt;</pre><p><strong>Example:</strong></p><pre>&lt;form&gt;<br>    &lt;label&gt;Name:&lt;/label&gt;<br>    &lt;input type=&quot;text&quot;&gt;</pre><pre>    &lt;br&gt;&lt;br&gt;</pre><pre>    &lt;label&gt;Email:&lt;/label&gt;<br>    &lt;input type=&quot;email&quot;&gt;</pre><pre>    &lt;br&gt;&lt;br&gt;</pre><pre>    &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;<br>&lt;/form&gt;</pre><p><strong>Expected Output:</strong></p><pre>Name:  [________________]</pre><pre>Email: [________________]</pre><pre>       [ Submit ]</pre><h3>2. Important HTML Form Tags</h3><p>HTML provides different tags to create and organize form controls.</p><p>TagDescription&lt;form&gt;Defines an HTML form.&lt;label&gt;Defines a label for a form control.&lt;input&gt;Creates an input field.&lt;textarea&gt;Creates a multiline input field.&lt;button&gt;Creates a clickable button.&lt;select&gt;Creates a dropdown list.&lt;option&gt;Defines a dropdown option.&lt;optgroup&gt;Groups related dropdown options.&lt;fieldset&gt;Groups related form controls.&lt;legend&gt;Defines a caption for a fieldset.&lt;datalist&gt;Provides predefined input suggestions.&lt;output&gt;Displays a calculation result.&lt;progress&gt;Displays task progress.&lt;meter&gt;Displays a measurement within a range.</p><p>Let’s understand these tags with examples.</p><h3>3. The &lt;form&gt; Tag</h3><p>The &lt;form&gt; tag is used to create an HTML form.</p><p>It acts as a container for different form elements such as input fields, labels, buttons, and dropdowns.</p><p><strong>Syntax:</strong></p><pre>&lt;form action=&quot;/register&quot; method=&quot;POST&quot;&gt;<br>    &lt;!-- Form controls --&gt;<br>&lt;/form&gt;</pre><h3>Important Attributes</h3><p><strong>1. action</strong></p><p>Specifies where the form data should be submitted.</p><pre>&lt;form action=&quot;/register&quot;&gt;<br>    &lt;input type=&quot;text&quot; name=&quot;username&quot;&gt;<br>    &lt;button type=&quot;submit&quot;&gt;Register&lt;/button&gt;<br>&lt;/form&gt;</pre><p><strong>2. method</strong></p><p>Specifies how form data is submitted.</p><p>The two commonly used methods are GET and POST.</p><p><strong>GET Method</strong></p><p>GET sends form data through URL query parameters.</p><pre>&lt;form action=&quot;/search&quot; method=&quot;GET&quot;&gt;<br>    &lt;input type=&quot;text&quot; name=&quot;search&quot;&gt;<br>    &lt;button type=&quot;submit&quot;&gt;Search&lt;/button&gt;<br>&lt;/form&gt;</pre><p>Example URL:</p><pre>/search?search=javascript</pre><p>Important points:</p><ul><li>Data is visible in the URL.</li><li>Commonly used for searching and filtering.</li><li>URLs can be bookmarked.</li><li>Not suitable for sensitive information.</li></ul><p><strong>POST Method</strong></p><p>POST sends form data in the HTTP request body.</p><pre>&lt;form action=&quot;/register&quot; method=&quot;POST&quot;&gt;<br>    &lt;input type=&quot;text&quot; name=&quot;username&quot;&gt;<br>    &lt;input type=&quot;password&quot; name=&quot;password&quot;&gt;<br>    &lt;button type=&quot;submit&quot;&gt;Register&lt;/button&gt;<br>&lt;/form&gt;</pre><p>Important points:</p><ul><li>Data is sent in the request body.</li><li>Commonly used for registration and login submissions.</li><li>Submitted data does not appear in URL query parameters.</li><li>HTTPS is necessary to protect information during transmission.</li></ul><p><strong>GET vs POST</strong></p><p>GETPOSTData is sent through URL parameters.Data is sent through the request body.Data is visible in the URL.Data is not displayed in the URL.Used for searching.Used for submitting information.Can be bookmarked with query parameters.Submitted body data cannot be bookmarked.</p><p><strong>3. autocomplete</strong></p><p>Controls whether the browser can suggest previously entered information.</p><pre>&lt;form autocomplete=&quot;on&quot;&gt;<br>    &lt;input type=&quot;text&quot; name=&quot;username&quot;&gt;<br>    &lt;input type=&quot;email&quot; name=&quot;email&quot;&gt;<br>&lt;/form&gt;</pre><p>Values: on and off.</p><p><strong>4. target</strong></p><p>Specifies where to display the response after form submission.</p><p>Common values:</p><ul><li>_self</li><li>_blank</li><li>_parent</li><li>_top</li></ul><p><strong>5. enctype</strong></p><p>Specifies how form data is encoded when using POST.</p><p>Common values:</p><ul><li>application/x-www-form-urlencoded</li><li>multipart/form-data</li><li>text/plain</li></ul><p>For file uploads, use:</p><pre>&lt;form method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot;&gt;<br>    &lt;input type=&quot;file&quot; name=&quot;document&quot;&gt;<br>    &lt;button type=&quot;submit&quot;&gt;Upload&lt;/button&gt;<br>&lt;/form&gt;</pre><h3>4. The &lt;label&gt; Tag</h3><p>The &lt;label&gt; tag defines a label for a form control.</p><p>It tells users what information they should enter.</p><p><strong>Example:</strong></p><pre>&lt;form&gt;<br>    &lt;label for=&quot;username&quot;&gt;Username:&lt;/label&gt;</pre><pre>    &lt;input<br>        type=&quot;text&quot;<br>        id=&quot;username&quot;<br>        name=&quot;username&quot;<br>    &gt;<br>&lt;/form&gt;</pre><p><strong>Output:</strong></p><pre>Username: [________________]</pre><p><strong>Important points:</strong></p><ul><li>Improves form accessibility.</li><li>Helps screen readers identify form controls.</li><li>Clicking the label focuses or activates its associated control.</li><li>The for attribute must match the input&#39;s id.</li></ul><h3>5. The &lt;input&gt; Tag</h3><p>The &lt;input&gt; tag is one of the most important HTML form elements.</p><p>It is used to create different types of input controls.</p><p>The type attribute determines the input&#39;s behavior and appearance.</p><p><strong>Syntax:</strong></p><pre>&lt;input type=&quot;text&quot;&gt;</pre><p>The input element is a void element, so it does not require a closing tag.</p><h3>Different Types of HTML Input</h3><p><strong>1. Text Input</strong></p><p>Used to collect single-line text.</p><pre>&lt;input type=&quot;text&quot; placeholder=&quot;Enter your name&quot;&gt;</pre><p>Output:</p><pre>[________________]</pre><p><strong>2. Password Input</strong></p><p>Used to collect passwords. Entered characters are visually masked.</p><pre>&lt;input type=&quot;password&quot; placeholder=&quot;Enter password&quot;&gt;</pre><p>Output:</p><pre>[••••••••••••]</pre><p><strong>3. Email Input</strong></p><p>Used to collect email addresses and perform basic browser format validation.</p><pre>&lt;input type=&quot;email&quot; placeholder=&quot;Enter email&quot;&gt;</pre><p><strong>4. Number Input</strong></p><p>Used to collect numeric values.</p><pre>&lt;input type=&quot;number&quot; min=&quot;18&quot; max=&quot;60&quot;&gt;</pre><p><strong>5. Telephone Input</strong></p><p>Used to collect telephone numbers.</p><pre>&lt;input type=&quot;tel&quot; placeholder=&quot;Enter mobile number&quot;&gt;</pre><p>Note: tel does not automatically validate a phone number&#39;s format.</p><p><strong>6. URL Input</strong></p><p>Used to collect website addresses.</p><pre>&lt;input type=&quot;url&quot; placeholder=&quot;Enter website URL&quot;&gt;</pre><p><strong>7. Search Input</strong></p><p>Used to create a search field.</p><pre>&lt;input type=&quot;search&quot; placeholder=&quot;Search here&quot;&gt;</pre><p><strong>8. Date Input</strong></p><p>Allows users to select a date.</p><pre>&lt;input type=&quot;date&quot;&gt;</pre><p><strong>9. Time Input</strong></p><p>Allows users to select a time.</p><pre>&lt;input type=&quot;time&quot;&gt;</pre><p><strong>10. Datetime-local Input</strong></p><p>Allows users to select a date and time without a timezone.</p><pre>&lt;input type=&quot;datetime-local&quot;&gt;</pre><p><strong>11. Month Input</strong></p><p>Allows users to select a month and year.</p><pre>&lt;input type=&quot;month&quot;&gt;</pre><p><strong>12. Week Input</strong></p><p>Allows users to select a week and year.</p><pre>&lt;input type=&quot;week&quot;&gt;</pre><p><strong>13. Color Input</strong></p><p>Displays a color picker.</p><pre>&lt;input type=&quot;color&quot;&gt;</pre><p><strong>14. File Input</strong></p><p>Allows users to select files from their device.</p><pre>&lt;input type=&quot;file&quot;&gt;</pre><p>To accept only images:</p><pre>&lt;input type=&quot;file&quot; accept=&quot;image/*&quot;&gt;</pre><p>To select multiple files:</p><pre>&lt;input type=&quot;file&quot; multiple&gt;</pre><p><strong>15. Radio Input</strong></p><p>Allows users to select one option from a group.</p><pre>&lt;input type=&quot;radio&quot; name=&quot;gender&quot; value=&quot;male&quot;&gt;<br>&lt;label&gt;Male&lt;/label&gt;</pre><pre>&lt;input type=&quot;radio&quot; name=&quot;gender&quot; value=&quot;female&quot;&gt;<br>&lt;label&gt;Female&lt;/label&gt;</pre><pre>&lt;input type=&quot;radio&quot; name=&quot;gender&quot; value=&quot;other&quot;&gt;<br>&lt;label&gt;Other&lt;/label&gt;</pre><p>Output:</p><pre>( ) Male<br>( ) Female<br>( ) Other</pre><p>Important: Radio buttons must share the same name to belong to the same group.</p><p><strong>16. Checkbox Input</strong></p><p>Allows users to select one or multiple options.</p><pre>&lt;input type=&quot;checkbox&quot; name=&quot;skills&quot; value=&quot;html&quot;&gt;<br>&lt;label&gt;HTML&lt;/label&gt;</pre><pre>&lt;input type=&quot;checkbox&quot; name=&quot;skills&quot; value=&quot;css&quot;&gt;<br>&lt;label&gt;CSS&lt;/label&gt;</pre><pre>&lt;input type=&quot;checkbox&quot; name=&quot;skills&quot; value=&quot;javascript&quot;&gt;<br>&lt;label&gt;JavaScript&lt;/label&gt;</pre><p>Output:</p><pre>[ ] HTML<br>[ ] CSS<br>[ ] JavaScript</pre><p><strong>17. Range Input</strong></p><p>Creates a slider for selecting a numeric value.</p><pre>&lt;input type=&quot;range&quot; min=&quot;0&quot; max=&quot;100&quot;&gt;</pre><p>Output:</p><pre>0  --------●--------  100</pre><p><strong>18. Hidden Input</strong></p><p>Stores a value that is not displayed as a visible control.</p><pre>&lt;input type=&quot;hidden&quot; name=&quot;userId&quot; value=&quot;101&quot;&gt;</pre><p>Important: Hidden inputs are not secure storage. Their values can be inspected and modified.</p><p><strong>19. Submit Input</strong></p><p>Creates a button that submits the form.</p><pre>&lt;input type=&quot;submit&quot; value=&quot;Submit&quot;&gt;</pre><p><strong>20. Reset Input</strong></p><p>Creates a button that resets form controls to their initial values.</p><pre>&lt;input type=&quot;reset&quot; value=&quot;Reset&quot;&gt;</pre><p><strong>21. Button Input</strong></p><p>Creates a generic button without a default action.</p><pre>&lt;input type=&quot;button&quot; value=&quot;Click Me&quot;&gt;</pre><h3>Input Types Summary</h3><p>TypePurposetextSingle-line textpasswordPasswordemailEmail addressnumberNumeric valuetelTelephone numberurlWebsite addresssearchSearchdateDatetimeTimedatetime-localDate and timemonthMonth and yearweekWeek and yearcolorColor selectionfileFile selectionradioSingle selectioncheckboxMultiple selectionsrangeSliderhiddenHidden valuesubmitForm submissionresetForm resetbuttonGeneric button</p><h3>6. Important Input Attributes</h3><p>HTML input elements support different attributes that control their behavior.</p><p><strong>1. name</strong></p><p>Specifies the field name used when submitting form data.</p><pre>&lt;input type=&quot;text&quot; name=&quot;username&quot;&gt;</pre><p><strong>2. id</strong></p><p>Provides a unique identifier for an element.</p><pre>&lt;input type=&quot;text&quot; id=&quot;username&quot;&gt;</pre><p><strong>3. value</strong></p><p>Specifies the initial value.</p><pre>&lt;input type=&quot;text&quot; value=&quot;Amol&quot;&gt;</pre><p><strong>4. placeholder</strong></p><p>Displays a hint inside an empty input field.</p><pre>&lt;input type=&quot;text&quot; placeholder=&quot;Enter your name&quot;&gt;</pre><p><strong>5. required</strong></p><p>Makes a field mandatory.</p><pre>&lt;input type=&quot;email&quot; required&gt;</pre><p><strong>6. readonly</strong></p><p>Prevents users from modifying the field value while allowing it to be submitted.</p><pre>&lt;input type=&quot;text&quot; value=&quot;Amol&quot; readonly&gt;</pre><p><strong>7. disabled</strong></p><p>Disables the input. Disabled controls are not submitted with the form.</p><pre>&lt;input type=&quot;text&quot; value=&quot;Amol&quot; disabled&gt;</pre><p><strong>8. maxlength</strong></p><p>Specifies the maximum number of characters.</p><pre>&lt;input type=&quot;text&quot; maxlength=&quot;20&quot;&gt;</pre><p><strong>9. minlength</strong></p><p>Specifies the minimum number of characters.</p><pre>&lt;input type=&quot;text&quot; minlength=&quot;3&quot;&gt;</pre><p><strong>10. min and max</strong></p><p>Specify the minimum and maximum allowed values.</p><pre>&lt;input type=&quot;number&quot; min=&quot;18&quot; max=&quot;60&quot;&gt;</pre><p><strong>11. step</strong></p><p>Specifies the valid increment.</p><pre>&lt;input type=&quot;number&quot; min=&quot;0&quot; max=&quot;100&quot; step=&quot;5&quot;&gt;</pre><p><strong>12. pattern</strong></p><p>Specifies a regular expression that the input must match.</p><pre>&lt;input type=&quot;text&quot; pattern=&quot;[A-Za-z]{3,}&quot;&gt;</pre><p><strong>13. autocomplete</strong></p><p>Controls browser autofill suggestions.</p><pre>&lt;input type=&quot;email&quot; autocomplete=&quot;email&quot;&gt;</pre><p><strong>14. autofocus</strong></p><p>Automatically focuses an input when the page loads.</p><pre>&lt;input type=&quot;text&quot; autofocus&gt;</pre><p><strong>15. checked</strong></p><p>Selects a checkbox or radio button by default.</p><pre>&lt;input type=&quot;checkbox&quot; checked&gt;</pre><p><strong>16. multiple</strong></p><p>Allows multiple values where supported.</p><pre>&lt;input type=&quot;file&quot; multiple&gt;</pre><p><strong>17. accept</strong></p><p>Specifies the expected file types.</p><pre>&lt;input type=&quot;file&quot; accept=&quot;.pdf,.doc,.docx&quot;&gt;</pre><h3>7. The &lt;textarea&gt; Tag</h3><p>The &lt;textarea&gt; tag creates a multiline text input field.</p><p>It is useful for collecting addresses, messages, comments, and feedback.</p><p><strong>Example:</strong></p><pre>&lt;label&gt;Address:&lt;/label&gt;</pre><pre>&lt;textarea<br>    rows=&quot;4&quot;<br>    cols=&quot;30&quot;<br>    placeholder=&quot;Enter your address&quot;&gt;<br>&lt;/textarea&gt;</pre><p>Output:</p><pre>Address:</pre><pre>[                         ]<br>[                         ]<br>[                         ]<br>[                         ]</pre><p>Important attributes:</p><ul><li>rows – Specifies the visible number of lines.</li><li>cols – Specifies the visible width.</li><li>placeholder – Displays a hint.</li><li>maxlength – Specifies the maximum character count.</li><li>required – Makes the field mandatory.</li><li>readonly – Prevents editing.</li></ul><p>Unlike &lt;input&gt;, &lt;textarea&gt; requires an opening and closing tag.</p><h3>8. The &lt;button&gt; Tag</h3><p>The &lt;button&gt; tag creates clickable buttons.</p><p>It supports three important types.</p><p><strong>Submit:</strong></p><pre>&lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;</pre><p>Submits the form.</p><p><strong>Reset:</strong></p><pre>&lt;button type=&quot;reset&quot;&gt;Reset&lt;/button&gt;</pre><p>Resets the form controls.</p><p><strong>Button:</strong></p><pre>&lt;button type=&quot;button&quot;&gt;Click Me&lt;/button&gt;</pre><p>Creates a normal button without submitting the form by default.</p><p>Important: Always specify the button type inside forms to avoid unexpected submissions.</p><h3>9. The &lt;select&gt; and &lt;option&gt; Tags</h3><p>The &lt;select&gt; tag creates a dropdown list, while &lt;option&gt; defines individual options.</p><p><strong>Example:</strong></p><pre>&lt;label&gt;Select City:&lt;/label&gt;</pre><pre>&lt;select name=&quot;city&quot;&gt;<br>    &lt;option value=&quot;&quot;&gt;Select City&lt;/option&gt;<br>    &lt;option value=&quot;pune&quot;&gt;Pune&lt;/option&gt;<br>    &lt;option value=&quot;mumbai&quot;&gt;Mumbai&lt;/option&gt;<br>    &lt;option value=&quot;solapur&quot;&gt;Solapur&lt;/option&gt;<br>    &lt;option value=&quot;nashik&quot;&gt;Nashik&lt;/option&gt;<br>&lt;/select&gt;</pre><p>Output:</p><pre>Select City: [Select City ▼]</pre><p>Important attributes:</p><ul><li>name – Specifies the submitted field name.</li><li>required – Makes selection mandatory.</li><li>multiple – Allows multiple selections.</li><li>size – Specifies visible options.</li><li>disabled – Disables the dropdown.</li></ul><h3>The selected Attribute</h3><p>The selected attribute specifies the default selected option.</p><pre>&lt;select name=&quot;course&quot;&gt;<br>    &lt;option value=&quot;html&quot;&gt;HTML&lt;/option&gt;<br>    &lt;option value=&quot;css&quot; selected&gt;CSS&lt;/option&gt;<br>    &lt;option value=&quot;javascript&quot;&gt;JavaScript&lt;/option&gt;<br>&lt;/select&gt;</pre><h3>10. The &lt;optgroup&gt; Tag</h3><p>The &lt;optgroup&gt; tag groups related options inside a dropdown.</p><p><strong>Example:</strong></p><pre>&lt;select name=&quot;course&quot;&gt;</pre><pre>    &lt;optgroup label=&quot;Frontend&quot;&gt;<br>        &lt;option&gt;HTML&lt;/option&gt;<br>        &lt;option&gt;CSS&lt;/option&gt;<br>        &lt;option&gt;JavaScript&lt;/option&gt;<br>    &lt;/optgroup&gt;</pre><pre>    &lt;optgroup label=&quot;Backend&quot;&gt;<br>        &lt;option&gt;Node.js&lt;/option&gt;<br>        &lt;option&gt;Java&lt;/option&gt;<br>        &lt;option&gt;Python&lt;/option&gt;<br>    &lt;/optgroup&gt;</pre><pre>&lt;/select&gt;</pre><p>This makes long dropdown lists easier to organize.</p><h3>11. The &lt;fieldset&gt; and &lt;legend&gt; Tags</h3><p>The &lt;fieldset&gt; tag groups related form controls.</p><p>The &lt;legend&gt; tag defines a title for that group.</p><p><strong>Example:</strong></p><pre>&lt;form&gt;</pre><pre>    &lt;fieldset&gt;</pre><pre>        &lt;legend&gt;Personal Information&lt;/legend&gt;</pre><pre>        &lt;label&gt;Name:&lt;/label&gt;<br>        &lt;input type=&quot;text&quot;&gt;</pre><pre>        &lt;br&gt;&lt;br&gt;</pre><pre>        &lt;label&gt;Email:&lt;/label&gt;<br>        &lt;input type=&quot;email&quot;&gt;</pre><pre>    &lt;/fieldset&gt;</pre><pre>&lt;/form&gt;</pre><p>Output:</p><pre>+----- Personal Information ------+<br>|                                  |<br>| Name:  [________________]        |<br>|                                  |<br>| Email: [________________]        |<br>|                                  |<br>+----------------------------------+</pre><p>These elements help organize large forms and improve accessibility.</p><h3>12. The &lt;datalist&gt; Tag</h3><p>The &lt;datalist&gt; tag provides predefined suggestions for an input field.</p><p>Users can select a suggestion or type their own value.</p><p><strong>Example:</strong></p><pre>&lt;label&gt;Select Browser:&lt;/label&gt;</pre><pre>&lt;input type=&quot;text&quot; list=&quot;browsers&quot;&gt;</pre><pre>&lt;datalist id=&quot;browsers&quot;&gt;<br>    &lt;option value=&quot;Chrome&quot;&gt;<br>    &lt;option value=&quot;Firefox&quot;&gt;<br>    &lt;option value=&quot;Edge&quot;&gt;<br>    &lt;option value=&quot;Safari&quot;&gt;<br>&lt;/datalist&gt;</pre><p>Important: The input’s list attribute must match the datalist&#39;s id.</p><p><strong>Select vs Datalist</strong></p><p>SelectDatalistCreates a dropdown.Provides suggestions.Users select from available options.Users can type their own values.Uses option elements.Uses option elements inside datalist.</p><h3>13. The &lt;output&gt; Tag</h3><p>The &lt;output&gt; tag displays the result of a calculation or user action.</p><p><strong>Example:</strong></p><pre>&lt;form oninput=&quot;result.value = Number(a.value) + Number(b.value)&quot;&gt;</pre><pre>    &lt;input type=&quot;number&quot; id=&quot;a&quot; value=&quot;10&quot;&gt;</pre><pre>    +</pre><pre>    &lt;input type=&quot;number&quot; id=&quot;b&quot; value=&quot;20&quot;&gt;</pre><pre>    =</pre><pre>    &lt;output name=&quot;result&quot;&gt;30&lt;/output&gt;</pre><pre>&lt;/form&gt;</pre><p>Output:</p><pre>10 + 20 = 30</pre><p>When the values change, the result updates automatically.</p><h3>14. The &lt;progress&gt; Tag</h3><p>The &lt;progress&gt; tag represents the completion progress of a task.</p><p><strong>Example:</strong></p><pre>&lt;label&gt;Downloading:&lt;/label&gt;</pre><pre>&lt;progress value=&quot;70&quot; max=&quot;100&quot;&gt;&lt;/progress&gt;</pre><p>Output:</p><pre>Downloading: 70%</pre><p>Important attributes:</p><ul><li>value – Current progress.</li><li>max – Maximum progress value.</li></ul><p>If the value attribute is omitted, the progress is indeterminate.</p><h3>15. The &lt;meter&gt; Tag</h3><p>The &lt;meter&gt; tag represents a measurement within a known range.</p><p>Examples include storage usage, ratings, and battery levels.</p><p><strong>Example:</strong></p><pre>&lt;label&gt;Storage Usage:&lt;/label&gt;</pre><pre>&lt;meter value=&quot;70&quot; min=&quot;0&quot; max=&quot;100&quot;&gt;&lt;/meter&gt;</pre><p>Output:</p><pre>Storage Usage: 70%</pre><p>Important attributes:</p><ul><li>value – Current measurement.</li><li>min – Minimum value.</li><li>max – Maximum value.</li><li>low – Low range boundary.</li><li>high – High range boundary.</li><li>optimum – Optimal value.</li></ul><p><strong>Progress vs Meter</strong></p><p>ProgressMeterRepresents task completion.Represents a measurement.Used for downloads and uploads.Used for ratings and storage.Indicates progress.Indicates a value within a range.</p><h3>16. HTML Form Validation</h3><p>Form validation checks whether the information entered by users is valid before submission.</p><p>HTML provides built-in validation through different attributes.</p><p><strong>Required:</strong></p><pre>&lt;input type=&quot;text&quot; required&gt;</pre><p>Makes the field mandatory.</p><p><strong>Minlength:</strong></p><pre>&lt;input type=&quot;text&quot; minlength=&quot;3&quot;&gt;</pre><p>Specifies the minimum character count.</p><p><strong>Maxlength:</strong></p><pre>&lt;input type=&quot;text&quot; maxlength=&quot;20&quot;&gt;</pre><p>Specifies the maximum character count.</p><p><strong>Min and Max:</strong></p><pre>&lt;input type=&quot;number&quot; min=&quot;18&quot; max=&quot;60&quot;&gt;</pre><p>Defines the permitted numeric range.</p><p><strong>Pattern:</strong></p><pre>&lt;input type=&quot;text&quot; pattern=&quot;[0-9]{10}&quot;&gt;</pre><p>Requires exactly 10 digits.</p><p><strong>Type Validation:</strong></p><pre>&lt;input type=&quot;email&quot; required&gt;</pre><p>Performs basic email-format validation.</p><h3>Complete Validation Example</h3><pre>&lt;form&gt;</pre><pre>    &lt;label&gt;Username:&lt;/label&gt;<br>    &lt;input<br>        type=&quot;text&quot;<br>        minlength=&quot;3&quot;<br>        maxlength=&quot;15&quot;<br>        required<br>    &gt;</pre><pre>    &lt;br&gt;&lt;br&gt;</pre><pre>    &lt;label&gt;Email:&lt;/label&gt;<br>    &lt;input type=&quot;email&quot; required&gt;</pre><pre>    &lt;br&gt;&lt;br&gt;</pre><pre>    &lt;label&gt;Age:&lt;/label&gt;<br>    &lt;input<br>        type=&quot;number&quot;<br>        min=&quot;18&quot;<br>        max=&quot;60&quot;<br>        required<br>    &gt;</pre><pre>    &lt;br&gt;&lt;br&gt;</pre><pre>    &lt;button type=&quot;submit&quot;&gt;Register&lt;/button&gt;</pre><pre>&lt;/form&gt;</pre><p><strong>Expected Behavior:</strong></p><ul><li>Empty required fields prevent submission.</li><li>Invalid email formats prevent submission.</li><li>Usernames shorter than three characters fail validation.</li><li>Age values outside the specified range fail validation.</li></ul><p><strong>Important:</strong> Frontend validation is not enough for security. Always validate submitted information on the backend.</p><h3>17. Complete Practical Example: Student Registration Form</h3><p>Now let’s combine the important HTML form tags and attributes to create a complete student registration form.</p><h3>Complete HTML Code</h3><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;</pre><pre>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;</pre><pre>    &lt;title&gt;Student Registration Form&lt;/title&gt;<br>&lt;/head&gt;</pre><pre>&lt;body&gt;</pre><pre>    &lt;h1&gt;Student Registration Form&lt;/h1&gt;</pre><pre>    &lt;form action=&quot;/register&quot; method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot;&gt;</pre><pre>        &lt;fieldset&gt;</pre><pre>            &lt;legend&gt;Personal Information&lt;/legend&gt;</pre><pre>            &lt;label for=&quot;fname&quot;&gt;First Name:&lt;/label&gt;<br>            &lt;input type=&quot;text&quot; id=&quot;fname&quot; name=&quot;firstName&quot; required&gt;</pre><pre>            &lt;br&gt;&lt;br&gt;</pre><pre>            &lt;label for=&quot;lname&quot;&gt;Last Name:&lt;/label&gt;<br>            &lt;input type=&quot;text&quot; id=&quot;lname&quot; name=&quot;lastName&quot; required&gt;</pre><pre>            &lt;br&gt;&lt;br&gt;</pre><pre>            &lt;label for=&quot;email&quot;&gt;Email:&lt;/label&gt;<br>            &lt;input type=&quot;email&quot; id=&quot;email&quot; name=&quot;email&quot; required&gt;</pre><pre>            &lt;br&gt;&lt;br&gt;</pre><pre>            &lt;label for=&quot;mobile&quot;&gt;Mobile:&lt;/label&gt;<br>            &lt;input type=&quot;tel&quot; id=&quot;mobile&quot; name=&quot;mobile&quot;<br>                   pattern=&quot;[0-9]{10}&quot; required&gt;</pre><pre>            &lt;br&gt;&lt;br&gt;</pre><pre>            &lt;label for=&quot;password&quot;&gt;Password:&lt;/label&gt;<br>            &lt;input type=&quot;password&quot; id=&quot;password&quot; name=&quot;password&quot;<br>                   minlength=&quot;8&quot; required&gt;</pre><pre>            &lt;br&gt;&lt;br&gt;</pre><pre>            &lt;label for=&quot;dob&quot;&gt;Date of Birth:&lt;/label&gt;<br>            &lt;input type=&quot;date&quot; id=&quot;dob&quot; name=&quot;dob&quot; required&gt;</pre><pre>            &lt;br&gt;&lt;br&gt;</pre><pre>            &lt;label&gt;Gender:&lt;/label&gt;</pre><pre>            &lt;input type=&quot;radio&quot; id=&quot;male&quot; name=&quot;gender&quot; value=&quot;male&quot; required&gt;<br>            &lt;label for=&quot;male&quot;&gt;Male&lt;/label&gt;</pre><pre>            &lt;input type=&quot;radio&quot; id=&quot;female&quot; name=&quot;gender&quot; value=&quot;female&quot;&gt;<br>            &lt;label for=&quot;female&quot;&gt;Female&lt;/label&gt;</pre><pre>            &lt;input type=&quot;radio&quot; id=&quot;other&quot; name=&quot;gender&quot; value=&quot;other&quot;&gt;<br>            &lt;label for=&quot;other&quot;&gt;Other&lt;/label&gt;</pre><pre>        &lt;/fieldset&gt;</pre><pre>        &lt;br&gt;</pre><pre>        &lt;fieldset&gt;</pre><pre>            &lt;legend&gt;Educational Information&lt;/legend&gt;</pre><pre>            &lt;label for=&quot;course&quot;&gt;Select Course:&lt;/label&gt;</pre><pre>            &lt;select id=&quot;course&quot; name=&quot;course&quot; required&gt;<br>                &lt;option value=&quot;&quot;&gt;Select Course&lt;/option&gt;<br>                &lt;option value=&quot;bca&quot;&gt;BCA&lt;/option&gt;<br>                &lt;option value=&quot;bsc&quot;&gt;BSc&lt;/option&gt;<br>                &lt;option value=&quot;bcom&quot;&gt;BCom&lt;/option&gt;<br>                &lt;option value=&quot;btech&quot;&gt;BTech&lt;/option&gt;<br>            &lt;/select&gt;</pre><pre>            &lt;br&gt;&lt;br&gt;</pre><pre>            &lt;label&gt;Skills:&lt;/label&gt;</pre><pre>            &lt;input type=&quot;checkbox&quot; id=&quot;html&quot; name=&quot;skills&quot; value=&quot;HTML&quot;&gt;<br>            &lt;label for=&quot;html&quot;&gt;HTML&lt;/label&gt;</pre><pre>            &lt;input type=&quot;checkbox&quot; id=&quot;css&quot; name=&quot;skills&quot; value=&quot;CSS&quot;&gt;<br>            &lt;label for=&quot;css&quot;&gt;CSS&lt;/label&gt;</pre><pre>            &lt;input type=&quot;checkbox&quot; id=&quot;js&quot; name=&quot;skills&quot; value=&quot;JavaScript&quot;&gt;<br>            &lt;label for=&quot;js&quot;&gt;JavaScript&lt;/label&gt;</pre><pre>            &lt;br&gt;&lt;br&gt;</pre><pre>            &lt;label for=&quot;address&quot;&gt;Address:&lt;/label&gt;</pre><pre>            &lt;br&gt;</pre><pre>            &lt;textarea id=&quot;address&quot; name=&quot;address&quot;<br>                      rows=&quot;4&quot; cols=&quot;40&quot;<br>                      placeholder=&quot;Enter your address&quot;<br>                      required&gt;&lt;/textarea&gt;</pre><pre>        &lt;/fieldset&gt;</pre><pre>        &lt;br&gt;</pre><pre>        &lt;fieldset&gt;</pre><pre>            &lt;legend&gt;Additional Information&lt;/legend&gt;</pre><pre>            &lt;label for=&quot;photo&quot;&gt;Upload Photo:&lt;/label&gt;</pre><pre>            &lt;input type=&quot;file&quot; id=&quot;photo&quot; name=&quot;photo&quot;<br>                   accept=&quot;image/*&quot;&gt;</pre><pre>            &lt;br&gt;&lt;br&gt;</pre><pre>            &lt;label for=&quot;browser&quot;&gt;Preferred Browser:&lt;/label&gt;</pre><pre>            &lt;input type=&quot;text&quot; id=&quot;browser&quot; name=&quot;browser&quot; list=&quot;browsers&quot;&gt;</pre><pre>            &lt;datalist id=&quot;browsers&quot;&gt;<br>                &lt;option value=&quot;Chrome&quot;&gt;<br>                &lt;option value=&quot;Firefox&quot;&gt;<br>                &lt;option value=&quot;Edge&quot;&gt;<br>                &lt;option value=&quot;Safari&quot;&gt;<br>            &lt;/datalist&gt;</pre><pre>        &lt;/fieldset&gt;</pre><pre>        &lt;br&gt;</pre><pre>        &lt;input type=&quot;checkbox&quot; id=&quot;terms&quot; name=&quot;terms&quot;<br>               value=&quot;accepted&quot; required&gt;</pre><pre>        &lt;label for=&quot;terms&quot;&gt;<br>            I agree to the terms and conditions.<br>        &lt;/label&gt;</pre><pre>        &lt;br&gt;&lt;br&gt;</pre><pre>        &lt;button type=&quot;submit&quot;&gt;Register&lt;/button&gt;<br>        &lt;button type=&quot;reset&quot;&gt;Reset&lt;/button&gt;</pre><pre>    &lt;/form&gt;</pre><pre>&lt;/body&gt;</pre><pre>&lt;/html&gt;</pre><h3>Expected Browser Output</h3><pre>STUDENT REGISTRATION FORM</pre><pre>Personal Information<br>--------------------------------</pre><pre>First Name: [________________]</pre><pre>Last Name:  [________________]</pre><pre>Email:      [________________]</pre><pre>Mobile:     [________________]</pre><pre>Password:   [________________]</pre><pre>Date of Birth: [Date Picker]</pre><pre>Gender:<br>( ) Male  ( ) Female  ( ) Other<br></pre><pre>Educational Information<br>--------------------------------</pre><pre>Select Course: [Select Course ▼]</pre><pre>Skills:<br>[ ] HTML  [ ] CSS  [ ] JavaScript</pre><pre>Address:<br>[____________________________]<br>[____________________________]<br>[____________________________]<br></pre><pre>Additional Information<br>--------------------------------</pre><pre>Upload Photo: [Choose File]</pre><pre>Preferred Browser: [__________]<br></pre><pre>[ ] I agree to the terms and conditions.<br></pre><pre>[ Register ]  [ Reset ]</pre><h3>Understanding the Example</h3><ul><li>&lt;form&gt; creates the registration form.</li><li>&lt;fieldset&gt; groups related information.</li><li>&lt;legend&gt; defines the group title.</li><li>&lt;label&gt; describes each input.</li><li>&lt;input&gt; collects user information.</li><li>Radio buttons allow one gender selection.</li><li>Checkboxes allow multiple skill selections.</li><li>&lt;select&gt; provides a course dropdown.</li><li>&lt;textarea&gt; collects a multiline address.</li><li>File input allows photo selection.</li><li>&lt;datalist&gt; provides browser suggestions.</li><li>required makes important fields mandatory.</li><li>Submit attempts to send the form data.</li><li>Reset restores the initial values.</li></ul><p>Note: The /register endpoint must be implemented on a backend server to process submissions. The multipart/form-data encoding supports file uploads, but the server must also implement multipart handling.</p><h3>18. Important Differences Between Form Elements</h3><p>ElementPurposeinputCollects single-line or specialized input.textareaCollects multiline text.selectCreates a dropdown.buttonCreates a clickable button.labelDescribes a form control.fieldsetGroups related controls.legendDefines a fieldset title.datalistProvides suggestions.outputDisplays a calculation result.progressDisplays task progress.meterDisplays a measurement.</p><h3>19. Best Practices for HTML Forms</h3><p>When creating HTML Forms, follow these best practices:</p><ul><li>Always use the &lt;form&gt; tag to define a form.</li><li>Use &lt;label&gt; for form controls.</li><li>Connect labels and inputs using for and id.</li><li>Provide meaningful name attributes.</li><li>Choose appropriate input types.</li><li>Use required for mandatory fields.</li><li>Use radio buttons for single-choice selections.</li><li>Use checkboxes for multiple-choice selections.</li><li>Organize related controls using &lt;fieldset&gt; and &lt;legend&gt;.</li><li>Use POST for operations that create or modify server-side data.</li><li>Use HTTPS to protect information during transmission.</li><li>Validate information on both frontend and backend.</li><li>Never store sensitive information in hidden inputs.</li></ul><h3>20. Frequently Asked HTML Form Interview Questions</h3><p><strong>Q1. What is an HTML Form?</strong></p><p>An HTML Form is a section of a webpage used to collect information from users and submit it for processing.</p><p><strong>Q2. Which tag is used to create an HTML Form?</strong></p><p>The &lt;form&gt; tag.</p><p><strong>Q3. What is the purpose of the action attribute?</strong></p><p>It specifies the URL where form data should be submitted.</p><p><strong>Q4. What is the difference between GET and POST?</strong></p><p>GET sends data through URL query parameters, whereas POST sends data in the request body.</p><p><strong>Q5. What is the difference between radio buttons and checkboxes?</strong></p><p>Radio buttons allow one selection from a group, whereas checkboxes allow multiple selections.</p><p><strong>Q6. What is the difference between readonly and disabled?</strong></p><p>Readonly fields cannot be edited but their values are submitted. Disabled fields cannot be interacted with and are not submitted.</p><p><strong>Q7. What is the difference between placeholder and value?</strong></p><p>Placeholder displays a hint inside an empty field, whereas value specifies its initial value.</p><p><strong>Q8. What is the purpose of the label tag?</strong></p><p>It describes a form control and improves accessibility.</p><p><strong>Q9. What is the difference between input and textarea?</strong></p><p>Input is used for single-line or specialized controls, whereas textarea is used for multiline text.</p><p><strong>Q10. What is the purpose of required?</strong></p><p>It makes a form control mandatory before submission.</p><p><strong>Q11. What is the purpose of the name attribute?</strong></p><p>It identifies a form field when submitting data.</p><p><strong>Q12. What is the difference between select and datalist?</strong></p><p>Select provides predefined dropdown options, whereas datalist provides suggestions while allowing users to enter other values.</p><p><strong>Q13. What are fieldset and legend?</strong></p><p>Fieldset groups related form controls, and legend defines the group’s title.</p><p><strong>Q14. What is the difference between progress and meter?</strong></p><p>Progress represents task completion, whereas meter represents a measurement within a known range.</p><p><strong>Q15. Does HTML validation replace backend validation?</strong></p><p>No. Backend validation is essential because frontend validation can be bypassed.</p><h3>Conclusion</h3><p>HTML Forms are an essential part of web development because they allow websites to interact with users and collect information.</p><p>Understanding form elements, input types, attributes, and validation helps developers create user-friendly and accessible forms.</p><p>These concepts also provide a strong foundation for learning JavaScript form handling, React Forms, API integration, and full-stack web development.</p><p><strong>Practice is the key to learning!</strong> Try creating login forms, registration forms, contact forms, feedback forms, and job application forms using the concepts covered in this article.</p><p>Keep learning and keep building!</p><p>Happy Coding! 🚀</p><h3>References and Further Learning</h3><ul><li><a href="https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Your_first_form">MDN Web Docs — Your First Form</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/form">MDN — HTML Form Element</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input">MDN — HTML Input Element</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Form_validation">MDN — Client-Side Form Validation</a></li></ul><p><strong>About the Author</strong></p><p>I am a software developer passionate about web development, programming, and learning modern technologies. I enjoy sharing my learning journey, practical examples, and technical knowledge to help other developers strengthen their programming fundamentals.</p><p>Follow me for more articles about HTML, CSS, JavaScript, React, MERN Stack, and Full Stack Development.</p><p>#HappyCoding #HTML #WebDevelopment</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37c011fea824" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTML Tables Explained: Complete Guide to Tags, Attributes, CSS, and Examples]]></title>
            <link>https://medium.com/@amolpawar.me/html-tables-explained-complete-guide-to-tags-attributes-css-and-examples-8c2982cd09ec?source=rss-18c7290112c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c2982cd09ec</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Amol Pawar]]></dc:creator>
            <pubDate>Wed, 21 Oct 2026 15:49:29 GMT</pubDate>
            <atom:updated>2026-10-21T15:49:29.043Z</atom:updated>
            <content:encoded><![CDATA[<h3>HTML tables are used to organize and display information in rows and columns. They make structured data easier to read, compare, and understand.</h3><p>You can find tables on many websites, including student result pages, employee directories, product comparison pages, pricing tables, admin dashboards, and cricket scorecards.</p><p>HTML provides dedicated elements to create tables, define rows and columns, group headings, display data, and organize summary information.</p><p>In this article, we will explore HTML table tags from the basics to advanced concepts, including attributes, CSS properties, practical examples, expected outputs, accessibility, responsive tables, and common mistakes.</p><h3>1. What Is an HTML Table?</h3><p>An HTML table is a structure used to display related information in rows and columns.</p><ul><li><strong>Rows</strong> run horizontally.</li><li><strong>Columns</strong> run vertically.</li><li><strong>Cells</strong> contain headings or data.</li></ul><p>For example:</p><p>Student IDNameCourse101AmolHTML102RahulCSS103PriyaJavaScript</p><p>This table contains three columns and four rows, including the heading row.</p><p>HTML uses the &lt;table&gt; element as the main container for this structure.</p><h3>2. Basic HTML Table Structure</h3><p>Before exploring individual tags, let’s understand how a simple table works.</p><pre>&lt;table&gt;<br>    &lt;tr&gt;<br>        &lt;th&gt;Name&lt;/th&gt;<br>        &lt;th&gt;Course&lt;/th&gt;<br>    &lt;/tr&gt;</pre><pre>    &lt;tr&gt;<br>        &lt;td&gt;Amol&lt;/td&gt;<br>        &lt;td&gt;React&lt;/td&gt;<br>    &lt;/tr&gt;</pre><pre>    &lt;tr&gt;<br>        &lt;td&gt;Rahul&lt;/td&gt;<br>        &lt;td&gt;JavaScript&lt;/td&gt;<br>    &lt;/tr&gt;<br>&lt;/table&gt;</pre><p><strong>Output:</strong></p><p>NameCourseAmolReactRahulJavaScript</p><h3>Understanding the code</h3><ul><li>&lt;table&gt; creates the table.</li><li>&lt;tr&gt; creates a table row.</li><li>&lt;th&gt; creates a header cell.</li><li>&lt;td&gt; creates a data cell.</li></ul><p>These four elements are the foundation of HTML tables.</p><h3>3. The &lt;table&gt; Tag</h3><p>The &lt;table&gt; tag defines the entire table and contains its rows and structural elements.</p><pre>&lt;table&gt;<br>    &lt;tr&gt;<br>        &lt;td&gt;HTML&lt;/td&gt;<br>        &lt;td&gt;CSS&lt;/td&gt;<br>    &lt;/tr&gt;<br>&lt;/table&gt;</pre><p><strong>Output:</strong></p><p>HTMLCSS</p><p>The &lt;table&gt; element defines the structure, but its visual appearance depends on browser defaults and CSS.</p><p><strong>Important:</strong> Use HTML tables for tabular data, not for designing the entire layout of a webpage. Modern page layouts are generally built with CSS Flexbox or Grid.</p><h3>4. The &lt;tr&gt; Tag — Table Row</h3><p>The &lt;tr&gt; tag stands for <em>Table Row</em>. It creates a horizontal row inside a table.</p><pre>&lt;table&gt;<br>    &lt;tr&gt;<br>        &lt;td&gt;Amol&lt;/td&gt;<br>        &lt;td&gt;Developer&lt;/td&gt;<br>    &lt;/tr&gt;</pre><pre>    &lt;tr&gt;<br>        &lt;td&gt;Rahul&lt;/td&gt;<br>        &lt;td&gt;Designer&lt;/td&gt;<br>    &lt;/tr&gt;<br>&lt;/table&gt;</pre><p><strong>Output:</strong></p><p>AmolDeveloperRahulDesigner</p><p>A row can contain header cells (&lt;th&gt;) and data cells (&lt;td&gt;). The number of cells can vary when cells span multiple rows or columns.</p><h3>5. The &lt;th&gt; Tag — Table Header Cell</h3><p>The &lt;th&gt; tag defines a header cell that describes the data in a row or column.</p><pre>&lt;table&gt;<br>    &lt;tr&gt;<br>        &lt;th&gt;Name&lt;/th&gt;<br>        &lt;th&gt;Age&lt;/th&gt;<br>        &lt;th&gt;City&lt;/th&gt;<br>    &lt;/tr&gt;</pre><pre>    &lt;tr&gt;<br>        &lt;td&gt;Amol&lt;/td&gt;<br>        &lt;td&gt;24&lt;/td&gt;<br>        &lt;td&gt;Pune&lt;/td&gt;<br>    &lt;/tr&gt;<br>&lt;/table&gt;</pre><p><strong>Output:</strong></p><p>NameAgeCityAmol24Pune</p><p>Browsers commonly display header text in bold and center it by default.</p><h3>The scope attribute</h3><p>The scope attribute identifies the rows or columns associated with a header.</p><pre>&lt;table&gt;<br>    &lt;tr&gt;<br>        &lt;th scope=&quot;col&quot;&gt;Name&lt;/th&gt;<br>        &lt;th scope=&quot;col&quot;&gt;Course&lt;/th&gt;<br>    &lt;/tr&gt;</pre><pre>    &lt;tr&gt;<br>        &lt;td&gt;Amol&lt;/td&gt;<br>        &lt;td&gt;React&lt;/td&gt;<br>    &lt;/tr&gt;<br>&lt;/table&gt;</pre><p>Common values:</p><ul><li>scope=&quot;col&quot; — Header for a column.</li><li>scope=&quot;row&quot; — Header for a row.</li><li>scope=&quot;colgroup&quot; — Header for a group of columns.</li><li>scope=&quot;rowgroup&quot; — Header for a group of rows.</li></ul><p>These attributes help communicate header relationships, especially to assistive technologies.</p><h3>6. The &lt;td&gt; Tag — Table Data Cell</h3><p>The &lt;td&gt; tag stands for <em>Table Data</em>. It represents an ordinary data cell.</p><pre>&lt;table&gt;<br>    &lt;tr&gt;<br>        &lt;th&gt;Name&lt;/th&gt;<br>        &lt;th&gt;Skill&lt;/th&gt;<br>    &lt;/tr&gt;</pre><pre>    &lt;tr&gt;<br>        &lt;td&gt;Amol&lt;/td&gt;<br>        &lt;td&gt;React Native&lt;/td&gt;<br>    &lt;/tr&gt;<br>&lt;/table&gt;</pre><p><strong>Output:</strong></p><p>NameSkillAmolReact Native</p><p>A &lt;td&gt; cell can contain text, links, images, lists, and other appropriate HTML content.</p><p>It also supports attributes such as colspan and rowspan, which allow a cell to span multiple columns or rows.</p><h3>7. The &lt;caption&gt; Tag — Table Title</h3><p>The &lt;caption&gt; tag provides a title or description for a table.</p><pre>&lt;table&gt;<br>    &lt;caption&gt;Employee Information&lt;/caption&gt;</pre><pre>    &lt;tr&gt;<br>        &lt;th&gt;Name&lt;/th&gt;<br>        &lt;th&gt;Department&lt;/th&gt;<br>    &lt;/tr&gt;</pre><pre>    &lt;tr&gt;<br>        &lt;td&gt;Amol&lt;/td&gt;<br>        &lt;td&gt;Development&lt;/td&gt;<br>    &lt;/tr&gt;<br>&lt;/table&gt;</pre><p><strong>Output:</strong></p><p><em>Employee Information</em></p><p>NameDepartmentAmolDevelopment</p><p>A caption helps readers understand the table’s purpose before examining the data.</p><p>You can control its position with CSS:</p><pre>caption {<br>    caption-side: bottom;<br>}</pre><p>The caption-side property commonly accepts top or bottom.</p><h3>8. The &lt;thead&gt; Tag — Table Header Group</h3><p>The &lt;thead&gt; tag groups the header rows of a table.</p><pre>&lt;table&gt;<br>    &lt;thead&gt;<br>        &lt;tr&gt;<br>            &lt;th&gt;Name&lt;/th&gt;<br>            &lt;th&gt;Course&lt;/th&gt;<br>        &lt;/tr&gt;<br>    &lt;/thead&gt;</pre><pre>    &lt;tbody&gt;<br>        &lt;tr&gt;<br>            &lt;td&gt;Amol&lt;/td&gt;<br>            &lt;td&gt;HTML&lt;/td&gt;<br>        &lt;/tr&gt;<br>    &lt;/tbody&gt;<br>&lt;/table&gt;</pre><p><strong>Output:</strong></p><p>NameCourseAmolHTML</p><p>Using &lt;thead&gt; makes the table structure clearer and allows the header section to be styled independently.</p><pre>thead {<br>    background-color: #e2e8f0;<br>}</pre><h3>9. The &lt;tbody&gt; Tag — Table Body Group</h3><p>The &lt;tbody&gt; tag groups the main data rows of a table.</p><pre>&lt;table&gt;<br>    &lt;thead&gt;<br>        &lt;tr&gt;<br>            &lt;th&gt;Product&lt;/th&gt;<br>            &lt;th&gt;Price&lt;/th&gt;<br>        &lt;/tr&gt;<br>    &lt;/thead&gt;</pre><pre>    &lt;tbody&gt;<br>        &lt;tr&gt;<br>            &lt;td&gt;Keyboard&lt;/td&gt;<br>            &lt;td&gt;₹800&lt;/td&gt;<br>        &lt;/tr&gt;</pre><pre>        &lt;tr&gt;<br>            &lt;td&gt;Mouse&lt;/td&gt;<br>            &lt;td&gt;₹400&lt;/td&gt;<br>        &lt;/tr&gt;<br>    &lt;/tbody&gt;<br>&lt;/table&gt;</pre><p><strong>Output:</strong></p><p>ProductPriceKeyboard₹800Mouse₹400</p><p>A table can contain multiple &lt;tbody&gt; elements when it is useful to group different sets of rows.</p><p>Browsers may also create a &lt;tbody&gt; automatically when parsing certain table structures that contain &lt;tr&gt; elements directly inside &lt;table&gt;.</p><h3>10. The &lt;tfoot&gt; Tag — Table Footer Group</h3><p>The &lt;tfoot&gt; tag groups footer rows, often used for totals or summary information.</p><pre>&lt;table&gt;<br>    &lt;thead&gt;<br>        &lt;tr&gt;<br>            &lt;th&gt;Product&lt;/th&gt;<br>            &lt;th&gt;Price&lt;/th&gt;<br>        &lt;/tr&gt;<br>    &lt;/thead&gt;</pre><pre>    &lt;tbody&gt;<br>        &lt;tr&gt;<br>            &lt;td&gt;Keyboard&lt;/td&gt;<br>            &lt;td&gt;₹800&lt;/td&gt;<br>        &lt;/tr&gt;</pre><pre>        &lt;tr&gt;<br>            &lt;td&gt;Mouse&lt;/td&gt;<br>            &lt;td&gt;₹400&lt;/td&gt;<br>        &lt;/tr&gt;<br>    &lt;/tbody&gt;</pre><pre>    &lt;tfoot&gt;<br>        &lt;tr&gt;<br>            &lt;th scope=&quot;row&quot;&gt;Total&lt;/th&gt;<br>            &lt;td&gt;₹1200&lt;/td&gt;<br>        &lt;/tr&gt;<br>    &lt;/tfoot&gt;<br>&lt;/table&gt;</pre><p><strong>Output:</strong></p><p>ProductPriceKeyboard₹800Mouse₹400<strong>Total</strong>₹1200</p><p>The total is provided in the HTML. The &lt;tfoot&gt; tag does not calculate values automatically.</p><h3>11. The &lt;colgroup&gt; and &lt;col&gt; Tags</h3><p>The &lt;colgroup&gt; and &lt;col&gt; elements provide a way to apply certain styles to entire columns.</p><ul><li>&lt;colgroup&gt; groups columns.</li><li>&lt;col&gt; represents one or more columns within that group.</li></ul><h3>Example</h3><pre>&lt;table&gt;<br>    &lt;colgroup&gt;<br>        &lt;col span=&quot;1&quot; class=&quot;name-column&quot;&gt;<br>        &lt;col span=&quot;1&quot; class=&quot;course-column&quot;&gt;<br>    &lt;/colgroup&gt;</pre><pre>    &lt;tr&gt;<br>        &lt;th&gt;Name&lt;/th&gt;<br>        &lt;th&gt;Course&lt;/th&gt;<br>    &lt;/tr&gt;</pre><pre>    &lt;tr&gt;<br>        &lt;td&gt;Amol&lt;/td&gt;<br>        &lt;td&gt;React&lt;/td&gt;<br>    &lt;/tr&gt;<br>&lt;/table&gt;</pre><pre>.name-column {<br>    background-color: #dbeafe;<br>}</pre><pre>.course-column {<br>    background-color: #dcfce7;<br>}</pre><p><strong>Expected result:</strong> The first column is intended to have a light blue background and the second a light green background.</p><p>Column-level styling has limitations. Properties such as background-color can apply to columns, but properties such as padding and detailed typography should generally be applied to the individual cells.</p><p>The span attribute lets a &lt;col&gt; represent multiple columns. For example, span=&quot;2&quot; represents two columns.</p><h3>12. The colspan Attribute — Spanning Columns</h3><p>The colspan attribute allows one cell to span multiple columns horizontally.</p><pre>&lt;table&gt;<br>    &lt;tr&gt;<br>        &lt;th colspan=&quot;2&quot;&gt;Student Information&lt;/th&gt;<br>    &lt;/tr&gt;</pre><pre>    &lt;tr&gt;<br>        &lt;td&gt;Amol&lt;/td&gt;<br>        &lt;td&gt;React&lt;/td&gt;<br>    &lt;/tr&gt;<br>&lt;/table&gt;</pre><p><strong>Output:</strong></p><p>Student InformationAmolReact</p><p>The first header cell spans two columns.</p><p>Common examples include colspan=&quot;2&quot; and colspan=&quot;3&quot;.</p><p>Use colspan when a heading or value needs to cover multiple columns.</p><h3>13. The rowspan Attribute — Spanning Rows</h3><p>The rowspan attribute allows one cell to span multiple rows vertically.</p><pre>&lt;table&gt;<br>    &lt;tr&gt;<br>        &lt;th&gt;Department&lt;/th&gt;<br>        &lt;th&gt;Employee&lt;/th&gt;<br>    &lt;/tr&gt;</pre><pre>    &lt;tr&gt;<br>        &lt;td rowspan=&quot;2&quot;&gt;Development&lt;/td&gt;<br>        &lt;td&gt;Amol&lt;/td&gt;<br>    &lt;/tr&gt;</pre><pre>    &lt;tr&gt;<br>        &lt;td&gt;Rahul&lt;/td&gt;<br>    &lt;/tr&gt;<br>&lt;/table&gt;</pre><p><strong>Output:</strong></p><p>The Development cell extends vertically across both employee rows.</p><p>DepartmentEmployeeDevelopmentAmol<em>(same merged cell)</em>Rahul</p><p><strong>Remember:</strong> colspan works horizontally, while rowspan works vertically.</p><h3>14. Important HTML Table Attributes</h3><p>HTML table-related attributes define how cells span rows or columns and how headers relate to data.</p><p>AttributeCommon usePurposecolspan&lt;td&gt;, &lt;th&gt;Spans multiple columnsrowspan&lt;td&gt;, &lt;th&gt;Spans multiple rowsscope&lt;th&gt;Identifies a header&#39;s relationship to rows or columnsheaders&lt;td&gt;, &lt;th&gt;Associates a cell with header cells by IDidHTML elementsGives an element a unique identifierclassHTML elementsConnects elements to CSS rulesstyleHTML elementsApplies inline CSStitleHTML elementsProvides advisory information</p><h3>What about older table attributes?</h3><p>You may encounter attributes such as:</p><ul><li>border</li><li>cellpadding</li><li>cellspacing</li><li>align</li><li>bgcolor</li><li>width</li><li>height</li></ul><p>These are obsolete or not recommended for modern HTML styling. Use CSS instead.</p><p>For example, instead of writing:</p><pre>&lt;table border=&quot;1&quot; cellpadding=&quot;10&quot; cellspacing=&quot;0&quot;&gt;</pre><p>Write:</p><pre>&lt;table class=&quot;student-table&quot;&gt;</pre><pre>.student-table {<br>    border-collapse: collapse;<br>}</pre><pre>.student-table th,<br>.student-table td {<br>    border: 1px solid #cbd5e1;<br>    padding: 10px;<br>}</pre><p>This separates content structure from presentation.</p><h3>15. CSS Properties for Styling HTML Tables</h3><p>CSS controls the visual appearance of a table, including its borders, spacing, colors, alignment, and layout.</p><h3>border</h3><p>Adds borders around the table and its cells.</p><pre>table,<br>th,<br>td {<br>    border: 1px solid black;<br>}</pre><h3>border-collapse</h3><p>Controls whether adjacent cell borders are combined or kept separate.</p><pre>table {<br>    border-collapse: collapse;<br>}</pre><p>The main values are collapse and separate.</p><h3>border-spacing</h3><p>Controls the space between cell borders when border-collapse: separate is used.</p><pre>table {<br>    border-collapse: separate;<br>    border-spacing: 8px;<br>}</pre><h3>padding</h3><p>Adds space between cell content and its border.</p><pre>th,<br>td {<br>    padding: 12px;<br>}</pre><h3>text-align</h3><p>Controls horizontal text alignment.</p><pre>th {<br>    text-align: left;<br>}</pre><pre>td {<br>    text-align: center;<br>}</pre><p>Common values include left, center, right, and justify.</p><h3>vertical-align</h3><p>Controls the vertical alignment of content inside table cells.</p><pre>td {<br>    vertical-align: middle;<br>}</pre><p>Common values include top, middle, and bottom.</p><h3>width and height</h3><p>Control table or cell dimensions.</p><pre>table {<br>    width: 100%;<br>}</pre><p>Allowing row heights to grow naturally is usually preferable when content varies.</p><h3>background-color</h3><p>Sets the background color.</p><pre>thead {<br>    background-color: #1e293b;<br>    color: white;<br>}</pre><p>You can also create alternating row colors:</p><pre>tbody tr:nth-child(even) {<br>    background-color: #f1f5f9;<br>}</pre><p>This technique is called zebra striping.</p><h3>table-layout</h3><p>Controls how the browser determines column widths.</p><pre>table {<br>    width: 100%;<br>    table-layout: fixed;<br>}</pre><ul><li>auto — Column widths depend on content and available space.</li><li>fixed — Column sizing is based mainly on the table width and specified column widths, rather than all cell contents.</li></ul><h3>caption-side</h3><p>Positions the table caption.</p><pre>caption {<br>    caption-side: top;<br>}</pre><h3>empty-cells</h3><p>Controls whether borders and backgrounds are displayed for empty cells when separate borders are used.</p><pre>table {<br>    border-collapse: separate;<br>    empty-cells: hide;<br>}</pre><p>Common values are show and hide.</p><h3>overflow</h3><p>For wide tables, use a wrapper to handle horizontal overflow.</p><pre>.table-wrapper {<br>    overflow-x: auto;<br>}</pre><p>This allows users to scroll horizontally when the table is wider than the available space.</p><h3>16. Complete HTML Table Example with CSS</h3><p>Let’s combine the concepts into a practical student marks table.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;</pre><pre>    &lt;title&gt;Student Marks Table&lt;/title&gt;</pre><pre>    &lt;style&gt;<br>        table {<br>            width: 100%;<br>            border-collapse: collapse;<br>            font-family: Arial, sans-serif;<br>        }</pre><pre>        caption {<br>            caption-side: top;<br>            font-size: 22px;<br>            font-weight: bold;<br>            margin-bottom: 12px;<br>        }</pre><pre>        th,<br>        td {<br>            border: 1px solid #cbd5e1;<br>            padding: 12px;<br>            text-align: left;<br>        }</pre><pre>        thead {<br>            background-color: #1e293b;<br>            color: white;<br>        }</pre><pre>        tbody tr:nth-child(even) {<br>            background-color: #f1f5f9;<br>        }</pre><pre>        tfoot {<br>            background-color: #dbeafe;<br>            font-weight: bold;<br>        }<br>    &lt;/style&gt;<br>&lt;/head&gt;</pre><pre>&lt;body&gt;</pre><pre>    &lt;table&gt;<br>        &lt;caption&gt;Student Marks&lt;/caption&gt;</pre><pre>        &lt;thead&gt;<br>            &lt;tr&gt;<br>                &lt;th scope=&quot;col&quot;&gt;Student ID&lt;/th&gt;<br>                &lt;th scope=&quot;col&quot;&gt;Name&lt;/th&gt;<br>                &lt;th scope=&quot;col&quot;&gt;Marks&lt;/th&gt;<br>            &lt;/tr&gt;<br>        &lt;/thead&gt;</pre><pre>        &lt;tbody&gt;<br>            &lt;tr&gt;<br>                &lt;td&gt;101&lt;/td&gt;<br>                &lt;td&gt;Amol&lt;/td&gt;<br>                &lt;td&gt;85&lt;/td&gt;<br>            &lt;/tr&gt;</pre><pre>            &lt;tr&gt;<br>                &lt;td&gt;102&lt;/td&gt;<br>                &lt;td&gt;Rahul&lt;/td&gt;<br>                &lt;td&gt;90&lt;/td&gt;<br>            &lt;/tr&gt;</pre><pre>            &lt;tr&gt;<br>                &lt;td&gt;103&lt;/td&gt;<br>                &lt;td&gt;Priya&lt;/td&gt;<br>                &lt;td&gt;88&lt;/td&gt;<br>            &lt;/tr&gt;<br>        &lt;/tbody&gt;</pre><pre>        &lt;tfoot&gt;<br>            &lt;tr&gt;<br>                &lt;th scope=&quot;row&quot; colspan=&quot;2&quot;&gt;Average&lt;/th&gt;<br>                &lt;td&gt;87.67&lt;/td&gt;<br>            &lt;/tr&gt;<br>        &lt;/tfoot&gt;<br>    &lt;/table&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><h3>Expected output</h3><p>The browser displays a full-width table containing:</p><ul><li>A title above the table.</li><li>A dark header with white text.</li><li>Three student records.</li><li>Alternating row backgrounds.</li><li>A highlighted footer showing the average marks.</li></ul><p>The average is a fixed example value, not a dynamically calculated result.</p><h3>17. Responsive HTML Tables</h3><p>Tables with many columns may not fit on smaller screens. A scrollable wrapper is a simple way to make them usable on mobile devices.</p><pre>&lt;div class=&quot;table-wrapper&quot;&gt;<br>    &lt;table&gt;<br>        &lt;thead&gt;<br>            &lt;tr&gt;<br>                &lt;th&gt;ID&lt;/th&gt;<br>                &lt;th&gt;Name&lt;/th&gt;<br>                &lt;th&gt;Course&lt;/th&gt;<br>                &lt;th&gt;Email&lt;/th&gt;<br>                &lt;th&gt;Location&lt;/th&gt;<br>            &lt;/tr&gt;<br>        &lt;/thead&gt;</pre><pre>        &lt;tbody&gt;<br>            &lt;tr&gt;<br>                &lt;td&gt;101&lt;/td&gt;<br>                &lt;td&gt;Amol&lt;/td&gt;<br>                &lt;td&gt;React&lt;/td&gt;<br>                &lt;td&gt;amol@example.com&lt;/td&gt;<br>                &lt;td&gt;Pune&lt;/td&gt;<br>            &lt;/tr&gt;<br>        &lt;/tbody&gt;<br>    &lt;/table&gt;<br>&lt;/div&gt;</pre><pre>.table-wrapper {<br>    width: 100%;<br>    overflow-x: auto;<br>}</pre><pre>.table-wrapper table {<br>    width: 100%;<br>    min-width: 600px;<br>    border-collapse: collapse;<br>}</pre><pre>.table-wrapper th,<br>.table-wrapper td {<br>    border: 1px solid #cbd5e1;<br>    padding: 10px;<br>}</pre><p>The wrapper enables horizontal scrolling when necessary, while min-width prevents the table from becoming too narrow.</p><p>This technique is useful for reports, dashboards, employee directories, and admin panels.</p><h3>18. Accessibility Best Practices</h3><p>Accessible tables help users understand the relationship between headings and data, including people who use assistive technologies.</p><ul><li>Use &lt;th&gt; for actual row and column headings.</li><li>Add a descriptive &lt;caption&gt; when it helps explain the table.</li><li>Use scope=&quot;col&quot; and scope=&quot;row&quot; for straightforward header relationships.</li><li>Use id and headers when complex tables require explicit associations.</li><li>Keep headings clear and descriptive.</li><li>Do not use tables to create the overall layout of a webpage.</li></ul><p>For complex tables, the headers attribute can associate a data cell with multiple header cells by their IDs. For simple tables, correctly structured header cells are generally sufficient.</p><h3>19. Common HTML Table Mistakes</h3><p><strong>1. Confusing </strong><strong>&lt;th&gt; and </strong><strong>&lt;td&gt;</strong></p><p>Use &lt;th&gt; for headings and &lt;td&gt; for ordinary data.</p><p><strong>2. Using </strong><strong>colspan or </strong><strong>rowspan incorrectly</strong></p><p>These attributes change the table’s grid structure. Ensure the remaining cells are positioned correctly.</p><p><strong>3. Relying on obsolete presentation attributes</strong></p><p>Use CSS instead of attributes such as cellpadding, cellspacing, and bgcolor.</p><p><strong>4. Forgetting mobile screens</strong></p><p>Wide tables can overflow small screens. Consider a scrollable wrapper.</p><p><strong>5. Creating tables without meaningful headings</strong></p><p>Clear headings help readers understand the data.</p><p><strong>6. Expecting HTML to calculate totals</strong></p><p>HTML provides structure. Use JavaScript or a backend when values need to be calculated dynamically.</p><p><strong>7. Using tables for page layout</strong></p><p>Use Flexbox or Grid for general page layout and HTML tables for genuinely tabular information.</p><h3>20. Quick Revision: HTML Table Tags and Attributes</h3><h3>Table elements</h3><p>TagPurpose&lt;table&gt;Creates the table&lt;tr&gt;Creates a row&lt;th&gt;Creates a header cell&lt;td&gt;Creates a data cell&lt;caption&gt;Adds a table title or description&lt;thead&gt;Groups header rows&lt;tbody&gt;Groups the main data rows&lt;tfoot&gt;Groups footer or summary rows&lt;colgroup&gt;Groups columns for column-level formatting&lt;col&gt;Represents one or more columns</p><h3>Important attributes</h3><p>AttributePurposecolspanSpans multiple columnsrowspanSpans multiple rowsscopeDescribes header relationshipsheadersAssociates cells with specific headersidProvides a unique identifierclassConnects elements to CSS rules</p><h3>Important CSS properties</h3><p>PropertyPurposeborderAdds bordersborder-collapseCombines or separates bordersborder-spacingSets spacing between separate cell borderspaddingAdds space inside cellstext-alignControls horizontal alignmentvertical-alignControls vertical alignmentwidthSets widthbackground-colorSets background colortable-layoutControls column sizingcaption-sidePositions the captionempty-cellsControls the appearance of empty cellsoverflow-xHelps handle horizontal overflow in a wrapper</p><h3>Conclusion</h3><p>HTML tables are essential for presenting structured information in a clear and organized way.</p><p>Start by understanding &lt;table&gt;, &lt;tr&gt;, &lt;th&gt;, and &lt;td&gt;. Then learn how to organize larger tables using &lt;caption&gt;, &lt;thead&gt;, &lt;tbody&gt;, and &lt;tfoot&gt;. Finally, practice colspan, rowspan, CSS styling, and responsive layouts.</p><p>The best way to master HTML tables is to build practical projects such as student mark sheets, employee directories, product comparisons, and cricket scorecards.</p><p>Keep learning, keep building, and continue strengthening your HTML fundamentals.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c2982cd09ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTML Quotation Tags Explained: Complete Guide with Examples and Output]]></title>
            <link>https://medium.com/@amolpawar.me/html-quotation-tags-explained-complete-guide-with-examples-and-output-18b61c23f84f?source=rss-18c7290112c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/18b61c23f84f</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Amol Pawar]]></dc:creator>
            <pubDate>Wed, 21 Oct 2026 15:42:36 GMT</pubDate>
            <atom:updated>2026-10-21T15:42:36.053Z</atom:updated>
            <content:encoded><![CDATA[<h3>When building web pages, we often need to display quotes, highlight statements from other sources, or give credit to the original author. HTML provides special elements to represent this content in a meaningful and structured way.</h3><p>HTML quotation tags help browsers understand the purpose of quoted text. They also make your HTML more semantic and easier to maintain.</p><p>In this article, we will explore HTML quotation tags, their syntax, practical examples, expected outputs, differences, and common mistakes.</p><h3>1. What Are Quotation Tags in HTML?</h3><p>HTML quotation tags are elements used to represent quoted content and identify the sources of quotations.</p><p>The main elements related to quotations are:</p><ul><li>&lt;q&gt; — Used for short, inline quotations.</li><li>&lt;blockquote&gt; — Used for longer quotations displayed separately.</li><li>&lt;cite&gt; — Used to identify the title of a creative work.</li><li>&lt;footer&gt; — Can contain attribution or source information associated with a quotation.</li></ul><p>Let’s understand each element with examples.</p><h3>2. The &lt;q&gt; Tag — Short Quotations</h3><p>The &lt;q&gt; tag represents a short quotation within a sentence or paragraph.</p><p>Most browsers automatically add quotation marks around the text inside the element.</p><h3>Example</h3><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;title&gt;Q Tag Example&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;p&gt;<br>        My teacher always says,<br>        &lt;q&gt;Practice makes progress.&lt;/q&gt;<br>    &lt;/p&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Output:</strong></p><p>My teacher always says, “Practice makes progress.”</p><h3>Key points</h3><ul><li>&lt;q&gt; is an inline element.</li><li>It is suitable for short quotations.</li><li>Browsers typically generate quotation marks automatically.</li><li>The cite attribute can specify the source URL.</li></ul><h3>Using the cite Attribute</h3><pre>&lt;p&gt;<br>    The article states,<br>    &lt;q cite=&quot;https://example.com/article&quot;&gt;<br>        Learning is a continuous process.<br>    &lt;/q&gt;<br>&lt;/p&gt;</pre><p>The quotation marks appear around the quoted text, but the source URL is not normally displayed to the reader.</p><h3>3. The &lt;blockquote&gt; Tag — Long Quotations</h3><p>The &lt;blockquote&gt; tag represents an extended quotation presented as a separate block.</p><p>Unlike &lt;q&gt;, it is intended for quotations that stand apart from the surrounding text.</p><h3>Example</h3><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;title&gt;Blockquote Example&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h2&gt;A Thought About Learning&lt;/h2&gt;</pre><pre>    &lt;blockquote&gt;<br>        Success comes from consistent effort,<br>        patience, and a willingness to learn<br>        from mistakes.<br>    &lt;/blockquote&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Output:</strong></p><blockquote><em>Success comes from consistent effort, patience, and a willingness to learn from mistakes.</em></blockquote><h3>Key points</h3><ul><li>&lt;blockquote&gt; represents a block quotation.</li><li>Browsers commonly indent the quoted content.</li><li>It can contain paragraphs and other appropriate content.</li><li>The cite attribute can specify the source URL.</li><li>It does not usually add visible quotation marks automatically.</li></ul><h3>Using the cite Attribute</h3><pre>&lt;blockquote cite=&quot;https://example.com/learning&quot;&gt;<br>    &lt;p&gt;<br>        Every expert was once a beginner<br>        who continued learning.<br>    &lt;/p&gt;<br>&lt;/blockquote&gt;</pre><p>The browser displays the quotation, but the source URL remains part of the markup rather than appearing as a visible link.</p><h3>4. The &lt;cite&gt; Tag — Titles of Creative Works</h3><p>The &lt;cite&gt; tag identifies the title of a creative work, such as a book, movie, article, song, or research paper.</p><p>It does not represent the quotation itself.</p><h3>Example</h3><pre>&lt;p&gt;<br>    One interesting book is<br>    &lt;cite&gt;Atomic Habits&lt;/cite&gt;<br>    by James Clear.<br>&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>One interesting book is <em>Atomic Habits</em> by James Clear.</p><h3>Key points</h3><ul><li>&lt;cite&gt; identifies a creative work&#39;s title.</li><li>It is an inline element.</li><li>Browsers commonly display it in italics by default.</li><li>It does not automatically create a hyperlink.</li></ul><h3>Combining &lt;blockquote&gt; and &lt;cite&gt;</h3><pre>&lt;blockquote&gt;<br>    &lt;p&gt;<br>        Your quotation goes here.<br>    &lt;/p&gt;<br>&lt;/blockquote&gt;</pre><pre>&lt;p&gt;<br>    Source: &lt;cite&gt;Article Title&lt;/cite&gt;<br>&lt;/p&gt;</pre><p>Here, &lt;blockquote&gt; marks the quotation, while &lt;cite&gt; identifies the title of the work.</p><p><strong>Remember:</strong> Use &lt;cite&gt; for the work&#39;s title, not simply for the name of the person who said something.</p><h3>5. The &lt;footer&gt; Tag — Quotation Attribution</h3><p>The &lt;footer&gt; element represents footer information for a page or section. When used inside a quotation block, it can contain attribution or source details.</p><h3>Example</h3><pre>&lt;blockquote&gt;<br>    &lt;p&gt;<br>        Your quotation goes here.<br>    &lt;/p&gt;</pre><pre>    &lt;footer&gt;<br>        — Jane Doe<br>    &lt;/footer&gt;<br>&lt;/blockquote&gt;</pre><p><strong>Output:</strong></p><blockquote><em>Your quotation goes here.</em></blockquote><blockquote><em>— Jane Doe</em></blockquote><p>This example demonstrates how attribution can be grouped with a quotation. Replace the sample name and text with accurate information when publishing.</p><h3>Adding a Source Link</h3><pre>&lt;blockquote&gt;<br>    &lt;p&gt;<br>        Your quotation goes here.<br>    &lt;/p&gt;</pre><pre>    &lt;footer&gt;<br>        Source:<br>        &lt;cite&gt;<br>            &lt;a href=&quot;https://example.com/article&quot;&gt;<br>                Article Title<br>            &lt;/a&gt;<br>        &lt;/cite&gt;<br>    &lt;/footer&gt;<br>&lt;/blockquote&gt;</pre><p>In this example:</p><ul><li>&lt;blockquote&gt; represents the quotation.</li><li>&lt;footer&gt; groups the attribution with it.</li><li>&lt;cite&gt; identifies the title of the work.</li><li>&lt;a&gt; creates a clickable link to the source.</li></ul><p>The example URL is illustrative; use the actual source when publishing.</p><h3>6. Difference Between &lt;q&gt;, &lt;blockquote&gt;, and &lt;cite&gt;</h3><p>Although these elements are related, each has a different purpose.</p><p>Feature&lt;q&gt;&lt;blockquote&gt;&lt;cite&gt;PurposeShort quotationExtended quotationCreative work&#39;s titleDisplayInlineBlockInlineAutomatic quotation marksUsually yesUsually noNoTypical exampleA quoted sentenceA passage from an articleA book title</p><p>The main idea is simple: choose an HTML element based on the meaning of the content, not just its appearance.</p><h3>7. Difference Between the cite Attribute and &lt;cite&gt; Element</h3><p>These two features have similar names but different purposes.</p><p><strong>The </strong><strong>cite attribute</strong></p><p>It specifies a source URL for quotation elements such as &lt;q&gt; and &lt;blockquote&gt;.</p><pre>&lt;blockquote cite=&quot;https://example.com/source&quot;&gt;<br>    &lt;p&gt;This is a quoted passage.&lt;/p&gt;<br>&lt;/blockquote&gt;</pre><p>The URL is not normally displayed to the reader.</p><p><strong>The </strong><strong>&lt;cite&gt; element</strong></p><p>It identifies the title of a creative work.</p><pre>&lt;p&gt;<br>    I enjoyed reading &lt;cite&gt;Clean Code&lt;/cite&gt;.<br>&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>I enjoyed reading <em>Clean Code</em>.</p><p>In short, the cite attribute provides a source URL, whereas the &lt;cite&gt; element identifies a work&#39;s title.</p><h3>8. Common Mistakes to Avoid</h3><p><strong>1. Using </strong><strong>&lt;q&gt; for every quotation</strong></p><p>Use &lt;q&gt; for short, inline quotations and &lt;blockquote&gt; for extended quotations.</p><p><strong>2. Expecting </strong><strong>&lt;blockquote&gt; to add quotation marks</strong></p><p>Browsers typically indent block quotations. Use CSS if you want visible quotation marks.</p><p><strong>3. Using </strong><strong>&lt;cite&gt; for a person&#39;s name alone</strong></p><p>Use ordinary text for a speaker’s name. Reserve &lt;cite&gt; for the title of the relevant work.</p><p><strong>4. Assuming the </strong><strong>cite attribute creates a clickable link</strong></p><p>The attribute does not create a visible hyperlink. Use &lt;a&gt; when readers should be able to visit the source.</p><p><strong>5. Choosing quotation tags only for styling</strong></p><p>Use semantic HTML to describe the content correctly, and use CSS to control its appearance.</p><p><strong>6. Publishing inaccurate quotations</strong></p><p>Verify the wording and attribution against a reliable source whenever possible.</p><h3>9. Best Practices</h3><ul><li>Use &lt;q&gt; for short quotations within a sentence.</li><li>Use &lt;blockquote&gt; for extended quotations.</li><li>Use &lt;cite&gt; for titles of creative works.</li><li>Use &lt;footer&gt; when appropriate to group attribution with a quotation.</li><li>Use &lt;a&gt; to make source links clickable.</li><li>Use the cite attribute to provide a source URL where supported.</li><li>Use CSS to customize indentation, typography, and quotation marks.</li><li>Keep your HTML properly structured and semantically meaningful.</li><li>Verify quotations and source attributions before publishing.</li></ul><h3>Conclusion</h3><p>HTML quotation tags help developers represent quoted content and source information in a structured and meaningful way.</p><p>Here is a quick recap:</p><ul><li><strong>&lt;q&gt;</strong> represents short inline quotations.</li><li><strong>&lt;blockquote&gt;</strong> represents extended quotations.</li><li><strong>&lt;cite&gt;</strong> identifies the title of a creative work.</li><li><strong>&lt;footer&gt;</strong> can contain attribution information.</li><li><strong>The </strong><strong>cite attribute</strong> specifies the source URL of a quotation.</li></ul><p>Understanding these elements is an important step toward writing clean, semantic HTML.</p><p>If you are learning HTML, try building a simple webpage containing a short quotation, a longer passage, and a source attribution. Practicing these elements will help you understand how they work in real-world projects.</p><p><em>Keep learning, keep building, and keep improving your HTML skills.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18b61c23f84f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTML Formatting Tags Explained with Examples and Output]]></title>
            <link>https://medium.com/@amolpawar.me/html-formatting-tags-explained-with-examples-and-output-f9448675fa99?source=rss-18c7290112c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9448675fa99</guid>
            <category><![CDATA[html-tags]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Amol Pawar]]></dc:creator>
            <pubDate>Fri, 16 Oct 2026 17:25:27 GMT</pubDate>
            <atom:updated>2026-10-16T17:25:27.199Z</atom:updated>
            <content:encoded><![CDATA[<p>When learning HTML, I came across several tags used to format text, highlight important information, display code, and represent quotations.</p><p>At first, some of these tags looked similar. For example, &lt;b&gt; and &lt;strong&gt; both make text bold by default, but they have different meanings in HTML.</p><p>In this article, I’ll go through the commonly used HTML formatting tags, explain what each one does, and show examples with their expected output.</p><h3>1. What Are HTML Formatting Tags?</h3><p>HTML formatting tags help define how text should be presented or what it means.</p><p>Some tags change the default appearance of text, while others provide meaning that browsers, search engines, and assistive technologies can use.</p><p>For example:</p><pre>&lt;p&gt;This is &lt;b&gt;bold text&lt;/b&gt;.&lt;/p&gt;<br>&lt;p&gt;This is &lt;strong&gt;important text&lt;/strong&gt;.&lt;/p&gt;<br>&lt;p&gt;This is &lt;mark&gt;highlighted text&lt;/mark&gt;.&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>This is <strong>bold text</strong>.</p><p>This is <strong>important text</strong>.</p><p>This is highlighted text.</p><p>The first example draws attention to text. The second indicates importance, while the third marks text as relevant or highlighted.</p><p>Let’s look at each tag.</p><h3>2. The &lt;b&gt; Tag — Bold Text</h3><p>The &lt;b&gt; tag draws attention to text without adding extra importance.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;Welcome to &lt;b&gt;HTML Basics&lt;/b&gt;.&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>Welcome to <strong>HTML Basics</strong>.</p><p><strong>When to use it:</strong></p><ul><li>To draw attention to text without implying extra importance.</li><li>When another semantic element is not more appropriate.</li></ul><p>Use &lt;strong&gt; when the text has strong importance.</p><h3>3. The &lt;strong&gt; Tag — Important Text</h3><p>The &lt;strong&gt; tag indicates that the enclosed text has strong importance, seriousness, or urgency. Browsers usually display it in bold.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Save your work before closing the browser.&lt;/p&gt;</pre><p><strong>Output:</strong></p><p><strong>Warning:</strong> Save your work before closing the browser.</p><p><strong>Key difference:</strong></p><ul><li>&lt;b&gt; draws attention to text.</li><li>&lt;strong&gt; indicates that the text is important.</li></ul><h3>4. The &lt;i&gt; Tag — Alternate Voice or Mood</h3><p>The &lt;i&gt; tag represents text in an alternate voice or mood, or text distinguished from the surrounding content, such as a technical term or a phrase in another language.</p><p>Browsers usually display it in italics.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;The word &lt;i&gt;déjà vu&lt;/i&gt; comes from French.&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>The word <em>déjà vu</em> comes from French.</p><p><strong>When to use it:</strong> For text that needs to be distinguished from the surrounding text without conveying emphasis.</p><h3>5. The &lt;em&gt; Tag — Emphasized Text</h3><p>The &lt;em&gt; tag indicates stress emphasis. Browsers usually display it in italics.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;You &lt;em&gt;must&lt;/em&gt; check your code before submitting it.&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>You <em>must</em> check your code before submitting it.</p><p><strong>Key difference:</strong></p><ul><li>&lt;i&gt; distinguishes text from its surrounding content.</li><li>&lt;em&gt; adds stress emphasis to the text.</li></ul><h3>6. The &lt;u&gt; Tag — Annotated Text</h3><p>The &lt;u&gt; tag represents text with a non-textual annotation. Browsers usually display it with an underline.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;Check the &lt;u&gt;misspelled word&lt;/u&gt; in this sentence.&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>Check the misspelled word in this sentence.</p><p><strong>Important:</strong> Do not use &lt;u&gt; just to decorate ordinary text. CSS is usually better for visual underlining, especially for links or design elements.</p><h3>7. The &lt;mark&gt; Tag — Highlighted Text</h3><p>The &lt;mark&gt; tag identifies text that is relevant to the current context. Browsers commonly display it with a highlighted background.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;Remember to learn &lt;mark&gt;HTML fundamentals&lt;/mark&gt; first.&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>Remember to learn ==HTML fundamentals== first.</p><p><strong>When to use it:</strong></p><ul><li>To highlight a relevant phrase.</li><li>To mark a search result.</li><li>To draw attention to a specific part of a passage.</li></ul><h3>8. The &lt;small&gt; Tag — Smaller Text</h3><p>The &lt;small&gt; tag represents side comments, fine print, or similar secondary information.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;Price: ₹999 &lt;small&gt;Taxes may apply.&lt;/small&gt;&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>Price: ₹999 &lt;small&gt;Taxes may apply.&lt;/small&gt;</p><p>Browsers usually display the content inside &lt;small&gt; in a smaller font size.</p><h3>9. The &lt;del&gt; Tag — Deleted Text</h3><p>The &lt;del&gt; tag represents content that has been deleted from a document. Browsers usually display it with a strikethrough.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;Original price: &lt;del&gt;₹1500&lt;/del&gt;&lt;/p&gt;<br>&lt;p&gt;Current price: ₹999&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>Original price: ₹1500</p><p>Current price: ₹999</p><p><strong>When to use it:</strong> For showing removed content, such as an old price or a revision to a document.</p><h3>10. The &lt;ins&gt; Tag — Inserted Text</h3><p>The &lt;ins&gt; tag represents content inserted into a document, such as a revision.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;Meeting time: &lt;del&gt;10 AM&lt;/del&gt; &lt;ins&gt;11 AM&lt;/ins&gt;&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>Meeting time: 10 AM 11 AM</p><p>Browsers commonly show deleted text with a strikethrough and inserted text with an underline.</p><h3>11. The &lt;s&gt; Tag — No Longer Accurate Text</h3><p>The &lt;s&gt; tag represents content that is no longer accurate or relevant, but has not necessarily been deleted from the document.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;Old offer: &lt;s&gt;Buy one, get one free&lt;/s&gt;&lt;/p&gt;<br>&lt;p&gt;New offer: 20% discount&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>Old offer: Buy one, get one free</p><p>New offer: 20% discount</p><p><strong>Remember:</strong></p><ul><li>Use &lt;s&gt; when information is no longer accurate or relevant.</li><li>Use &lt;del&gt; when content has been deleted from a document.</li></ul><h3>12. The &lt;sub&gt; Tag — Subscript</h3><p>The &lt;sub&gt; tag displays text below the normal text baseline.</p><p>It is commonly used in chemical formulas.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;Water: H&lt;sub&gt;2&lt;/sub&gt;O&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>Water: H₂O</p><p>The number 2 appears slightly below the baseline.</p><h3>13. The &lt;sup&gt; Tag — Superscript</h3><p>The &lt;sup&gt; tag displays text above the normal text baseline.</p><p>It is often used for mathematical powers and certain annotations.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;Square of 5: 5&lt;sup&gt;2&lt;/sup&gt; = 25&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>Square of 5: ⁵² = 25</p><p>Here, 2 appears above the baseline.</p><h3>14. The &lt;code&gt; Tag — Code Text</h3><p>The &lt;code&gt; tag represents a fragment of computer code. Browsers usually display it in a monospace font.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;Use the &lt;code&gt;console.log()&lt;/code&gt; method to print a message.&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>Use the console.log() method to print a message.</p><p><strong>When to use it:</strong> For inline code, programming keywords, method names, or short code fragments.</p><h3>15. The &lt;pre&gt; Tag — Preformatted Text</h3><p>The &lt;pre&gt; tag preserves whitespace and line breaks in its content. It is useful when displaying text that depends on its formatting.</p><p><strong>Example:</strong></p><pre>&lt;pre&gt;<br>Name: Amol<br>Role: Developer<br>Skill: HTML<br>&lt;/pre&gt;</pre><p><strong>Output:</strong></p><pre>Name: Amol<br>Role: Developer<br>Skill: HTML</pre><p>The line breaks and spaces are preserved.</p><p><strong>Important:</strong> Use &lt;pre&gt; together with &lt;code&gt; when displaying a multiline code example.</p><pre>&lt;pre&gt;&lt;code&gt;<br>const message = &quot;Hello&quot;;<br>console.log(message);<br>&lt;/code&gt;&lt;/pre&gt;</pre><p>This combination represents a block of code while preserving its layout.</p><h3>16. The &lt;kbd&gt; Tag — Keyboard Input</h3><p>The &lt;kbd&gt; tag represents user input, usually entered through a keyboard.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;Press &lt;kbd&gt;Ctrl&lt;/kbd&gt; + &lt;kbd&gt;S&lt;/kbd&gt; to save your file.&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>Press Ctrl + S to save your file.</p><p>Browsers commonly render keyboard input in a monospace font. CSS can be used to make it look like a keyboard key.</p><h3>17. The &lt;samp&gt; Tag — Program Output</h3><p>The &lt;samp&gt; tag represents sample output from a computer program.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;Program output: &lt;samp&gt;Hello, World!&lt;/samp&gt;&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>Program output: Hello, World!</p><p><strong>When to use it:</strong> When documenting what a program, command, or computer system displays.</p><h3>18. The &lt;var&gt; Tag — Variables</h3><p>The &lt;var&gt; tag represents a variable in a mathematical expression or programming context.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;The area of a rectangle is &lt;var&gt;length&lt;/var&gt; × &lt;var&gt;width&lt;/var&gt;.&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>The area of a rectangle is <em>length</em> × <em>width</em>.</p><p>Browsers usually display &lt;var&gt; content in italics.</p><h3>19. The &lt;q&gt; Tag — Inline Quotation</h3><p>The &lt;q&gt; tag represents a short quotation within a sentence. Browsers generally add quotation marks automatically.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;My instructor said, &lt;q&gt;Practice makes progress.&lt;/q&gt;&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>My instructor said, “Practice makes progress.”</p><p>Avoid adding quotation marks manually unless you specifically need them, because the browser generally supplies them.</p><h3>20. The &lt;blockquote&gt; Tag — Block Quotation</h3><p>The &lt;blockquote&gt; tag represents a longer quotation from another source.</p><p><strong>Example:</strong></p><pre>&lt;blockquote&gt;<br>  Learning to write code takes practice and patience.<br>&lt;/blockquote&gt;</pre><p><strong>Output:</strong></p><blockquote><em>Learning to write code takes practice and patience.</em></blockquote><p>Browsers commonly indent block quotations. If the quotation comes from a specific source, you can use the cite attribute to provide its URL.</p><h3>21. The &lt;br&gt; Tag — Line Break</h3><p>The &lt;br&gt; tag creates a line break without starting a new paragraph.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;<br>  Amol Pawar&lt;br&gt;<br>  Full Stack Developer&lt;br&gt;<br>  India<br>&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>Amol Pawar<br>Full Stack Developer<br>India</p><p><strong>Important:</strong> &lt;br&gt; is a void element, so it does not need a closing tag. Use it for meaningful line breaks, such as addresses or poetry, rather than for creating page spacing.</p><h3>22. The &lt;wbr&gt; Tag — Optional Line Break</h3><p>The &lt;wbr&gt; tag indicates where the browser may break a long word or string if necessary.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;superlongdeveloper&lt;wbr&gt;documentation&lt;wbr&gt;example&lt;/p&gt;</pre><p><strong>Output:</strong></p><p>The text appears as one continuous string when enough space is available. If the available width is too small, the browser may break it at one of the indicated positions.</p><p>This can help prevent long strings from overflowing narrow containers.</p><h3>23. Combining HTML Formatting Tags</h3><p>You can combine formatting tags when each one serves a clear purpose.</p><p><strong>Example:</strong></p><pre>&lt;p&gt;<br>  &lt;strong&gt;Important:&lt;/strong&gt;<br>  Read the &lt;mark&gt;HTML documentation&lt;/mark&gt;<br>  before using the &lt;code&gt;form&lt;/code&gt; element.<br>&lt;/p&gt;</pre><p><strong>Output:</strong></p><p><strong>Important:</strong> Read the highlighted HTML documentation before using the form element.</p><p>Here, each element has a different purpose:</p><ul><li>&lt;strong&gt; indicates importance.</li><li>&lt;mark&gt; highlights relevant text.</li><li>&lt;code&gt; identifies a code-related term.</li></ul><p>Using the right element makes your HTML more meaningful and easier to maintain.</p><h3>24. Quick Revision Table</h3><p>TagPurpose&lt;b&gt;Draws attention to text&lt;strong&gt;Indicates strong importance&lt;i&gt;Represents alternate voice or distinguished text&lt;em&gt;Adds stress emphasis&lt;u&gt;Represents annotated text&lt;mark&gt;Highlights relevant text&lt;small&gt;Represents fine print or side comments&lt;del&gt;Represents deleted content&lt;ins&gt;Represents inserted content&lt;s&gt;Represents outdated or inaccurate content&lt;sub&gt;Displays subscript text&lt;sup&gt;Displays superscript text&lt;code&gt;Represents code&lt;pre&gt;Preserves whitespace and line breaks&lt;kbd&gt;Represents user input&lt;samp&gt;Represents program output&lt;var&gt;Represents a variable&lt;q&gt;Represents an inline quotation&lt;blockquote&gt;Represents a block quotation&lt;br&gt;Creates a line break&lt;wbr&gt;Indicates an optional line-break position</p><h3>25. Common Mistakes to Avoid</h3><p><strong>1. Using </strong><strong>&lt;b&gt; instead of </strong><strong>&lt;strong&gt; for important information</strong></p><p>Use &lt;strong&gt; when the content is genuinely important, not just because you want bold styling.</p><p><strong>2. Using </strong><strong>&lt;i&gt; and </strong><strong>&lt;em&gt; interchangeably</strong></p><p>They may look similar in the browser, but their meanings differ. Use &lt;em&gt; for stress emphasis.</p><p><strong>3. Using </strong><strong>&lt;br&gt; for spacing</strong></p><p>Do not add multiple &lt;br&gt; tags just to create empty space. Use CSS margins and padding for layout.</p><p><strong>4. Using </strong><strong>&lt;pre&gt; for every code example</strong></p><p>Use &lt;pre&gt; when whitespace and line breaks matter. For short inline snippets, &lt;code&gt; is generally sufficient.</p><p><strong>5. Choosing tags based only on appearance</strong></p><p>HTML describes the meaning and structure of content. CSS controls visual styling. Choose an element based on its purpose, then style it with CSS when needed.</p><h3>Conclusion</h3><p>HTML formatting tags are useful for presenting text and describing its meaning. Some focus on importance or emphasis, while others represent code, quotations, inserted content, or special text positioning.</p><p>The main lesson is that tags that look similar are not always interchangeable. Understanding their purpose helps you write cleaner, more meaningful HTML.</p><p>As I continue learning HTML, understanding the purpose of each element is helping me move beyond simply memorizing tags and start using them correctly.</p><h3>Further Reading</h3><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element">MDN Web Docs — Text-level semantics</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element#text_content">MDN Web Docs — HTML elements reference</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9448675fa99" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTML Elements Explained: Block-Level, Inline, Void, Semantic, and More — A Complete Beginner’s…]]></title>
            <link>https://medium.com/@amolpawar.me/html-elements-explained-a-complete-guide-to-their-types-meaning-and-usage-62b542f7d372?source=rss-18c7290112c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/62b542f7d372</guid>
            <category><![CDATA[medium]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Amol Pawar]]></dc:creator>
            <pubDate>Fri, 16 Oct 2026 17:12:57 GMT</pubDate>
            <atom:updated>2026-10-16T17:35:07.417Z</atom:updated>
            <content:encoded><![CDATA[<h3>HTML Elements Explained: Block-Level, Inline, Void, Semantic, and More — A Complete Beginner’s Guide</h3><p>When learning HTML, understanding tags is only the beginning. To write proper HTML, you also need to understand how elements behave, how they are displayed in the browser, which elements can contain other elements, and when to use each type.</p><p>For example:</p><ul><li>Why does a &lt;div&gt; start on a new line?</li><li>Why do &lt;strong&gt; and &lt;em&gt; usually appear within the same line?</li><li>Why does &lt;img&gt; not need a closing tag?</li><li>What is the difference between &lt;section&gt; and &lt;div&gt;?</li><li>Is &lt;header&gt; a block-level element or a semantic element?</li><li>What happens when you change an element’s CSS display property?</li></ul><p>These questions become easier once you understand that <strong>HTML elements can be classified in different ways, depending on their structure, default display behavior, meaning, and purpose.</strong></p><p>In this article, we will explore these concepts step by step, with examples, expected browser outputs, important rules, and practical scenarios.</p><h3>1. What Is an HTML Element?</h3><p>An HTML element is a building block of a web page. It can define a heading, paragraph, link, image, form field, section, or another part of a document.</p><p>Consider this example:</p><pre>&lt;p&gt;This is my first paragraph.&lt;/p&gt;</pre><p>The browser interprets it as a paragraph element.</p><p>Its structure contains three parts:</p><pre>&lt;p&gt;        This is my first paragraph.        &lt;/p&gt;<br> ↑                    ↑                         ↑<br>Opening tag         Content                  Closing tag</pre><p>Together, the opening tag, content, and closing tag form a complete paragraph element.</p><h3>Another example</h3><pre>&lt;h1&gt;Welcome to My Website&lt;/h1&gt;<br>&lt;p&gt;I am learning HTML.&lt;/p&gt;<br>&lt;a href=&quot;https://example.com&quot;&gt;Visit Website&lt;/a&gt;</pre><p><strong>Browser output:</strong></p><p>Welcome to My Website</p><p>I am learning HTML.</p><p>Visit Website</p><p>The heading, paragraph, and link are three different HTML elements. The browser applies its default styling and behavior to each one.</p><p><strong>Important:</strong> Not every HTML element has a closing tag or contains text. Some elements, such as &lt;img&gt; and &lt;input&gt;, are void elements.</p><h3>2. How Are HTML Elements Classified?</h3><p>There is no single classification that covers every aspect of an HTML element. Instead, elements can be understood through several different characteristics.</p><p>ClassificationWhat it describesExamplesDefault display behaviorHow an element participates in layout&lt;div&gt;, &lt;p&gt;, &lt;span&gt;, &lt;a&gt;Content structureWhether an element can contain content&lt;p&gt;, &lt;div&gt;, &lt;img&gt;, &lt;br&gt;Semantic meaningWhether an element communicates a specific purpose&lt;header&gt;, &lt;main&gt;, &lt;article&gt;Content purposeWhat an element represents or doesHeadings, lists, links, forms, tablesInteractivityWhether an element provides interactive behavior&lt;button&gt;, &lt;input&gt;, &lt;select&gt;</p><p>These characteristics are related, but they are not interchangeable.</p><p>For example, &lt;header&gt; is semantic and normally displayed as a block. &lt;img&gt; is a void element and normally behaves as an inline-level element. &lt;div&gt; is a generic, non-semantic element that normally behaves as a block.</p><p>One element can belong to multiple classifications simultaneously.</p><p>Let’s understand each classification in detail.</p><h3>3. Block-Level Elements</h3><p>Block-level elements are commonly described as elements that start on a new line and occupy the available width of their containing block by default.</p><p>This behavior makes them useful for creating the major sections and vertically arranged content of a page.</p><h3>Common examples</h3><ul><li>&lt;div&gt; — generic container</li><li>&lt;p&gt; — paragraph</li><li>&lt;h1&gt; to &lt;h6&gt; — headings</li><li>&lt;section&gt; — thematic section</li><li>&lt;article&gt; — self-contained content</li><li>&lt;header&gt; — introductory content</li><li>&lt;footer&gt; — footer content</li><li>&lt;main&gt; — primary page content</li><li>&lt;nav&gt; — navigation section</li><li>&lt;ul&gt; and &lt;ol&gt; — lists</li><li>&lt;li&gt; — list item</li><li>&lt;form&gt; — form container</li><li>&lt;table&gt; — table</li><li>&lt;hr&gt; — thematic break</li></ul><p>These elements have different meanings and content rules, even though many normally participate in block layout.</p><h3>Example 1: Multiple block elements</h3><pre>&lt;div&gt;First block&lt;/div&gt;<br>&lt;div&gt;Second block&lt;/div&gt;<br>&lt;div&gt;Third block&lt;/div&gt;</pre><p><strong>Expected browser output:</strong></p><pre>First block<br>Second block<br>Third block</pre><p>Each &lt;div&gt; normally begins on a new line.</p><h3>Example 2: Block elements with borders</h3><pre>&lt;div style=&quot;border: 2px solid blue; padding: 10px;&quot;&gt;<br>  First block<br>&lt;/div&gt;</pre><pre>&lt;div style=&quot;border: 2px solid green; padding: 10px;&quot;&gt;<br>  Second block<br>&lt;/div&gt;</pre><pre>&lt;div style=&quot;border: 2px solid red; padding: 10px;&quot;&gt;<br>  Third block<br>&lt;/div&gt;</pre><p><strong>Expected visual result:</strong></p><pre>┌─────────────────────────────────────┐<br>│ First block                         │<br>└─────────────────────────────────────┘</pre><pre>┌─────────────────────────────────────┐<br>│ Second block                        │<br>└─────────────────────────────────────┘</pre><pre>┌─────────────────────────────────────┐<br>│ Third block                         │<br>└─────────────────────────────────────┘</pre><p>The borders make the separate boxes visible. Their widths normally follow the available width of the containing block because no explicit width has been set.</p><p>The diagram is illustrative; the exact width and spacing depend on the browser window and CSS.</p><h3>Example 3: Paragraphs and headings</h3><pre>&lt;h1&gt;HTML Learning&lt;/h1&gt;<br>&lt;p&gt;HTML defines the structure of a web page.&lt;/p&gt;<br>&lt;p&gt;CSS controls its presentation.&lt;/p&gt;</pre><p><strong>Expected browser output:</strong></p><h3>HTML Learning</h3><p>HTML defines the structure of a web page.</p><p>CSS controls its presentation.</p><p>The heading and paragraphs normally appear on separate lines, with default margins applied by the browser.</p><h3>When should you use block-level elements?</h3><p>Use elements that fit the purpose of your content.</p><p>For example:</p><ul><li>Use &lt;main&gt; for the main content of a page.</li><li>Use &lt;section&gt; for a thematic section.</li><li>Use &lt;article&gt; for self-contained content.</li><li>Use &lt;p&gt; for a paragraph.</li><li>Use &lt;div&gt; when you need a generic container and no more appropriate semantic element fits.</li></ul><p><strong>Important rule:</strong> Block-level behavior does not automatically make an element semantic. A &lt;div&gt; is normally block-displayed, but it does not communicate a specific meaning.</p><p>Also, CSS can change the default display behavior. The traditional term <em>block-level element</em> is useful for beginners, but modern CSS layout is more flexible.</p><h3>4. Inline Elements</h3><p>Inline elements participate in the flow of text. They normally do not start a new line and occupy only the space their content requires.</p><p>They are useful when you need to identify, emphasize, link, or otherwise mark part of a sentence.</p><h3>Common examples</h3><ul><li>&lt;span&gt; — generic inline container</li><li>&lt;a&gt; — hyperlink</li><li>&lt;strong&gt; — strong importance</li><li>&lt;em&gt; — stress emphasis</li><li>&lt;b&gt; — attention without added importance</li><li>&lt;i&gt; — alternate voice or distinguished text</li><li>&lt;code&gt; — code fragment</li><li>&lt;small&gt; — side comments or small print</li><li>&lt;sub&gt; — subscript</li><li>&lt;sup&gt; — superscript</li><li>&lt;label&gt; — label for a form control</li></ul><p>Some other elements, such as &lt;img&gt;, also normally participate in inline-level layout.</p><h3>Example 1: Inline elements inside a sentence</h3><pre>&lt;p&gt;<br>  HTML is &lt;strong&gt;important&lt;/strong&gt; for<br>  &lt;em&gt;web development&lt;/em&gt;.<br>&lt;/p&gt;</pre><p><strong>Expected browser output:</strong></p><p>HTML is <strong>important</strong> for <em>web development</em>.</p><p>The emphasized words remain within the same paragraph. They do not normally force a new line.</p><h3>Example 2: Multiple inline elements</h3><pre>&lt;p&gt;<br>  Learn &lt;strong&gt;HTML&lt;/strong&gt;,<br>  &lt;em&gt;practice CSS&lt;/em&gt;,<br>  and explore &lt;a href=&quot;https://example.com&quot;&gt;web development&lt;/a&gt;.<br>&lt;/p&gt;</pre><p><strong>Expected browser output:</strong></p><p>Learn <strong>HTML</strong>, <em>practice CSS</em>, and explore <a href="https://example.com/">web development</a>.</p><p>The inline elements appear as parts of the same line when enough horizontal space is available. On a narrow screen, the text may wrap naturally.</p><h3>Example 3: Understanding &lt;span&gt;</h3><pre>&lt;p&gt;<br>  My favorite language is<br>  &lt;span style=&quot;color: blue;&quot;&gt;JavaScript&lt;/span&gt;.<br>&lt;/p&gt;</pre><p><strong>Expected browser output:</strong></p><p>My favorite language is &lt;span style=”color: blue;”&gt;JavaScript&lt;/span&gt;.</p><p>The word “JavaScript” appears blue in the browser. The &lt;span&gt; itself has no special semantic meaning; it provides a hook for styling or scripting.</p><h3>Do inline elements support width and height?</h3><p>For ordinary non-replaced inline elements, properties such as width and height do not work like they do on block elements.</p><p>For example:</p><pre>&lt;span style=&quot;width: 200px; height: 100px; background: yellow;&quot;&gt;<br>  Inline text<br>&lt;/span&gt;</pre><p>The yellow background follows the text, but the declared width and height do not give this ordinary inline &lt;span&gt; a 200-by-100-pixel box.</p><p>If you need a box with explicit dimensions while keeping it in the same line, you can use inline-block, which we will discuss next.</p><p><strong>Important:</strong> Inline elements can wrap across lines. Their layout is not the same as a single unbreakable box.</p><h3>5. Block-Level vs Inline Elements</h3><p>This is one of the most important distinctions for understanding HTML layout.</p><p>Consider the following example:</p><pre>&lt;div style=&quot;background: lightblue;&quot;&gt;Block One&lt;/div&gt;<br>&lt;div style=&quot;background: lightgreen;&quot;&gt;Block Two&lt;/div&gt;</pre><pre>&lt;p&gt;<br>  Learn &lt;span style=&quot;background: yellow;&quot;&gt;HTML&lt;/span&gt;<br>  and &lt;span style=&quot;background: pink;&quot;&gt;CSS&lt;/span&gt;.<br>&lt;/p&gt;</pre><p><strong>Expected visual arrangement:</strong></p><pre>┌────────────────────────────────────────┐<br>│ Block One                              │<br>└────────────────────────────────────────┘<br>┌────────────────────────────────────────┐<br>│ Block Two                              │<br>└────────────────────────────────────────┘</pre><pre>Learn [HTML] and [CSS].</pre><p>The first two &lt;div&gt; elements normally appear as separate blocks. The &lt;span&gt; elements stay within the paragraph&#39;s text flow.</p><p>FeatureBlock behaviorInline behaviorStarts on a new lineNormally yesNormally noUses available line widthNormally yesUsually only the space requiredWidth and heightGenerally applyNot in the same way for ordinary inline boxesCan contain textYesYesCan contain other elementsDepends on HTML content rulesDepends on HTML content rulesCan be changed using CSSYesYes</p><p>The last two rows are important. Display behavior does not determine which HTML children are valid. For example, a &lt;p&gt; is normally block-displayed, but it cannot contain another paragraph or other flow-content elements.</p><h3>6. Inline-Block Elements</h3><p>inline-block is a <strong>CSS </strong><strong>display value</strong>, not a separate HTML element type.</p><p>It combines two useful behaviors:</p><ul><li>Like an inline element, it can sit beside other inline-level content.</li><li>Like a block box, it can have an explicit width, height, padding, and border.</li></ul><h3>Example: Inline-block badges</h3><pre>&lt;span style=&quot;display: inline-block; width: 100px; height: 40px; background: lightblue; text-align: center; padding-top: 10px; box-sizing: border-box;&quot;&gt;<br>  HTML<br>&lt;/span&gt;</pre><pre>&lt;span style=&quot;display: inline-block; width: 100px; height: 40px; background: lightgreen; text-align: center; padding-top: 10px; box-sizing: border-box;&quot;&gt;<br>  CSS<br>&lt;/span&gt;</pre><pre>&lt;span style=&quot;display: inline-block; width: 100px; height: 40px; background: pink; text-align: center; padding-top: 10px; box-sizing: border-box;&quot;&gt;<br>  JavaScript<br>&lt;/span&gt;</pre><p><strong>Expected browser arrangement:</strong></p><pre>┌──────────┐ ┌──────────┐ ┌──────────┐<br>│   HTML   │ │   CSS    │ │JavaScript│<br>└──────────┘ └──────────┘ └──────────┘</pre><p>All three badges can sit beside one another while retaining their defined dimensions, provided sufficient horizontal space is available.</p><h3>When is inline-block useful?</h3><ul><li>Small badges and labels</li><li>Navigation items</li><li>Compact buttons</li><li>Small UI components that need explicit dimensions</li></ul><p>For modern page layouts, Flexbox and Grid are often better choices for arranging groups of components. However, inline-block is still useful for understanding CSS display behavior.</p><h3>7. Void Elements</h3><p>Void elements are HTML elements that <strong>cannot have child nodes and must not have closing tags</strong>.</p><p>They do not contain ordinary content between an opening tag and a closing tag.</p><h3>The 14 void elements in HTML</h3><p>ElementPurpose&lt;area&gt;Defines a clickable area within an image map&lt;base&gt;Sets the base URL for relative URLs in a document&lt;br&gt;Creates a line break&lt;col&gt;Defines properties for table columns&lt;embed&gt;Embeds external content&lt;hr&gt;Represents a thematic break&lt;img&gt;Embeds an image&lt;input&gt;Creates a form input control&lt;link&gt;Links an external resource, often a stylesheet&lt;meta&gt;Provides metadata about the document&lt;source&gt;Supplies media sources for elements such as &lt;audio&gt; and &lt;video&gt;&lt;track&gt;Provides timed text tracks for media&lt;wbr&gt;Indicates a possible line-break opportunity</p><h3>Example 1: Image</h3><pre>&lt;img<br>  src=&quot;profile.jpg&quot;<br>  alt=&quot;Profile photograph&quot;<br>  width=&quot;200&quot;<br>&gt;</pre><p><strong>Expected browser output:</strong></p><p>The browser displays the image at up to 200 pixels wide, depending on the image’s dimensions and layout. If the image cannot load, the alternative text may be displayed.</p><p>There is no &lt;/img&gt; tag.</p><h3>Example 2: Line break</h3><pre>&lt;p&gt;<br>  Hello,&lt;br&gt;<br>  welcome to HTML.<br>&lt;/p&gt;</pre><p><strong>Expected browser output:</strong></p><p>Hello,</p><p>welcome to HTML.</p><p>The &lt;br&gt; element moves the following text to the next line without starting a separate paragraph.</p><h3>Example 3: Horizontal rule</h3><pre>&lt;p&gt;First topic&lt;/p&gt;<br>&lt;hr&gt;<br>&lt;p&gt;Second topic&lt;/p&gt;</pre><p><strong>Expected browser output:</strong></p><p>First topic</p><p>────────────────────────</p><p>Second topic</p><p>The &lt;hr&gt; element represents a thematic break. Browsers commonly display it as a horizontal line.</p><h3>Example 4: Input field</h3><pre>&lt;label for=&quot;username&quot;&gt;Username:&lt;/label&gt;<br>&lt;input id=&quot;username&quot; type=&quot;text&quot;&gt;</pre><p><strong>Expected browser output:</strong></p><p>Username: [________________]</p><p>The input is a void element. It does not need a closing tag.</p><h3>Important rules for void elements</h3><p>Correct:</p><pre>&lt;img src=&quot;logo.png&quot; alt=&quot;Company logo&quot;&gt;<br>&lt;br&gt;<br>&lt;input type=&quot;email&quot;&gt;<br>&lt;hr&gt;</pre><p>Incorrect:</p><pre>&lt;img src=&quot;logo.png&quot; alt=&quot;Company logo&quot;&gt;&lt;/img&gt;<br>&lt;input type=&quot;text&quot;&gt;&lt;/input&gt;</pre><p>In HTML, do not add closing tags to void elements. A trailing slash, as in &lt;img src=&quot;logo.png&quot; alt=&quot;Logo&quot; /&gt;, is tolerated in HTML syntax but is not required.</p><p><strong>Remember:</strong> Void does not mean invisible. Images, input fields, and horizontal rules can all be visible in the browser.</p><h3>8. Normal Elements vs Void Elements</h3><p>Normal elements can contain permitted child content and generally use opening and closing tags. Void elements cannot contain child nodes and have no closing tags.</p><p>FeatureNormal elementVoid elementClosing tagUsually requiredNot permittedChild contentPermitted according to its content modelNot permittedExample&lt;p&gt;Hello&lt;/p&gt;&lt;br&gt;Another example&lt;div&gt;Content&lt;/div&gt;&lt;img src=&quot;photo.jpg&quot; alt=&quot;Photo&quot;&gt;</p><h3>Example</h3><pre>&lt;p&gt;This is a normal element.&lt;/p&gt;</pre><pre>&lt;img src=&quot;photo.jpg&quot; alt=&quot;A photograph&quot;&gt;</pre><p>The paragraph contains text between its tags. The image element embeds an image without surrounding child content.</p><p>Do not confuse a void element with an empty normal element:</p><pre>&lt;div&gt;&lt;/div&gt;</pre><p>This &lt;div&gt; is empty, but it is not a void element. It can contain content even though it currently contains none.</p><h3>9. Semantic HTML Elements</h3><p>Semantic elements communicate the meaning or purpose of the content they contain.</p><p>They help developers understand the document structure and can provide useful structural information to browsers and assistive technologies.</p><h3>Common semantic elements</h3><p>ElementMeaning and purpose&lt;header&gt;Introductory content for a page or section&lt;nav&gt;A major navigation section&lt;main&gt;The document&#39;s main content&lt;section&gt;A thematic grouping of content&lt;article&gt;Self-contained content&lt;aside&gt;Complementary content&lt;footer&gt;Footer information for a page or section&lt;figure&gt;Self-contained content such as an illustration&lt;figcaption&gt;Caption for a figure&lt;time&gt;Represents a date or time&lt;address&gt;Contact information for a relevant person or organization&lt;details&gt;A disclosure widget&lt;summary&gt;The label for a &lt;details&gt; disclosure widget</p><h3>Example: Semantic page structure</h3><pre>&lt;header&gt;<br>  &lt;h1&gt;Amol Codes&lt;/h1&gt;</pre><pre>  &lt;nav&gt;<br>    &lt;a href=&quot;#about&quot;&gt;About&lt;/a&gt;<br>    &lt;a href=&quot;#projects&quot;&gt;Projects&lt;/a&gt;<br>  &lt;/nav&gt;<br>&lt;/header&gt;</pre><pre>&lt;main&gt;<br>  &lt;section id=&quot;about&quot;&gt;<br>    &lt;h2&gt;About Me&lt;/h2&gt;<br>    &lt;p&gt;I am documenting my web development journey.&lt;/p&gt;<br>  &lt;/section&gt;</pre><pre>  &lt;section id=&quot;projects&quot;&gt;<br>    &lt;h2&gt;My Projects&lt;/h2&gt;</pre><pre>    &lt;article&gt;<br>      &lt;h3&gt;Portfolio Website&lt;/h3&gt;<br>      &lt;p&gt;A website showcasing my projects and experience.&lt;/p&gt;<br>    &lt;/article&gt;<br>  &lt;/section&gt;<br>&lt;/main&gt;</pre><pre>&lt;footer&gt;<br>  &lt;p&gt;Learning and building, one step at a time.&lt;/p&gt;<br>&lt;/footer&gt;</pre><p><strong>Expected page structure:</strong></p><pre>┌────────────────────────────────────┐<br>│ HEADER                             │<br>│ Amol Codes                         │<br>│ About | Projects                   │<br>├────────────────────────────────────┤<br>│ MAIN                               │<br>│                                    │<br>│  ABOUT SECTION                     │<br>│  About Me                          │<br>│  Introduction text                 │<br>│                                    │<br>│  PROJECTS SECTION                  │<br>│  My Projects                       │<br>│  ┌──────────────────────────────┐  │<br>│  │ ARTICLE                      │  │<br>│  │ Portfolio Website            │  │<br>│  │ Project description          │  │<br>│  └──────────────────────────────┘  │<br>├────────────────────────────────────┤<br>│ FOOTER                             │<br>│ Learning and building...           │<br>└────────────────────────────────────┘</pre><p>This is a conceptual representation of the page’s structure, not a guarantee of exact visual spacing. Semantic elements often have block display by default, but their semantic meaning comes from HTML, not from their appearance.</p><h3>Why should you use semantic elements?</h3><ul><li>They make the purpose of your HTML clearer.</li><li>They help other developers understand your code.</li><li>They provide useful document structure for assistive technologies.</li><li>They can help search engines interpret page content.</li><li>They encourage more meaningful and maintainable markup.</li></ul><p>Semantic HTML alone does not guarantee accessibility or better search rankings. Correct structure, accessible names, keyboard behavior, and other implementation details still matter.</p><h3>10. Non-Semantic HTML Elements</h3><p>Non-semantic elements do not communicate a specific content meaning by themselves. They are general-purpose containers.</p><p>The two most common examples are &lt;div&gt; and &lt;span&gt;.</p><h3>The &lt;div&gt; element</h3><p>&lt;div&gt; is a generic container commonly used to group larger sections of content for styling or scripting.</p><pre>&lt;div class=&quot;project-card&quot;&gt;<br>  &lt;h2&gt;Portfolio Website&lt;/h2&gt;<br>  &lt;p&gt;A personal website built with Next.js.&lt;/p&gt;<br>  &lt;a href=&quot;#project&quot;&gt;View Project&lt;/a&gt;<br>&lt;/div&gt;</pre><p><strong>Expected browser output:</strong></p><pre>Portfolio Website</pre><pre>A personal website built with Next.js.</pre><pre>View Project</pre><p>The &lt;div&gt; groups the elements, but the element itself does not tell the browser that the content represents a project card.</p><h3>The &lt;span&gt; element</h3><p>&lt;span&gt; is a generic inline container used to target a small portion of text or other permitted inline content.</p><pre>&lt;p&gt;<br>  My current focus is<br>  &lt;span style=&quot;color: purple; font-weight: bold;&quot;&gt;<br>    Full Stack Development<br>  &lt;/span&gt;.<br>&lt;/p&gt;</pre><p><strong>Expected browser output:</strong></p><p>My current focus is <strong>Full Stack Development</strong>.</p><p>The words “Full Stack Development” appear purple and bold in the browser.</p><h3>Semantic vs non-semantic</h3><p>Semantic elementNon-semantic element&lt;header&gt;&lt;div&gt;&lt;nav&gt;&lt;div&gt;&lt;main&gt;&lt;div&gt;&lt;article&gt;&lt;div&gt;&lt;section&gt;&lt;div&gt;No generic equivalent for every situation&lt;span&gt; is a generic inline container</p><p>Use a semantic element when its meaning matches the content. Use &lt;div&gt; or &lt;span&gt; when a generic container is appropriate.</p><p><strong>Important:</strong> A &lt;div&gt; can be styled to look like a header, and a &lt;span&gt; can be styled to look like a badge. Styling does not turn these generic elements into semantic elements.</p><h3>11. Semantic vs Block-Level Elements</h3><p>This distinction is especially important because these terms describe different things.</p><ul><li><strong>Block-level</strong> describes a traditional default layout behavior.</li><li><strong>Semantic</strong> describes the meaning or purpose of an element.</li></ul><p>For example:</p><p>ElementSemantic?Typical default display&lt;div&gt;No specific semantic meaningBlock&lt;span&gt;No specific semantic meaningInline&lt;header&gt;YesBlock&lt;main&gt;YesBlock&lt;section&gt;YesBlock&lt;strong&gt;Yes, indicates strong importanceInline&lt;a&gt;Yes, represents a hyperlinkInline&lt;img&gt;Represents an image; a void elementInline-level</p><p>An element can be semantic and block-displayed at the same time. These classifications are not alternatives.</p><p>For example, &lt;main&gt; communicates the purpose of the page&#39;s main content and is normally displayed as a block.</p><p>A &lt;div&gt; is normally displayed as a block, but it has no specific semantic meaning.</p><h3>12. CSS Can Change an Element’s Display Behavior</h3><p>An element’s HTML meaning and its CSS display behavior are separate.</p><p>The display property controls how an element participates in layout.</p><p>Common values include:</p><ul><li>block</li><li>inline</li><li>inline-block</li><li>flex</li><li>grid</li><li>none</li></ul><h3>Example: Changing a span to block</h3><pre>&lt;span style=&quot;display: block; background: lightblue;&quot;&gt;<br>  First item<br>&lt;/span&gt;</pre><pre>&lt;span style=&quot;display: block; background: lightgreen;&quot;&gt;<br>  Second item<br>&lt;/span&gt;</pre><p><strong>Expected browser output:</strong></p><pre>┌───────────────────────────────────┐<br>│ First item                        │<br>└───────────────────────────────────┘<br>┌───────────────────────────────────┐<br>│ Second item                       │<br>└───────────────────────────────────┘</pre><p>Although &lt;span&gt; is normally inline, CSS makes these spans participate in block layout.</p><h3>Example: Changing a div to inline</h3><pre>&lt;div style=&quot;display: inline; background: lightblue;&quot;&gt;One&lt;/div&gt;<br>&lt;div style=&quot;display: inline; background: lightgreen;&quot;&gt;Two&lt;/div&gt;</pre><p><strong>Expected browser output:</strong></p><p>One Two</p><p>The two elements can appear on the same line when space is available.</p><p>Changing display does not change the element&#39;s semantic meaning or its HTML content rules. For example, changing a &lt;span&gt; to display: block does not make it a &lt;div&gt; or permit every kind of child content.</p><h3>13. HTML Elements by Purpose</h3><p>Apart from layout and semantic meaning, HTML elements can be grouped by the jobs they perform.</p><h3>A. Document structure elements</h3><p>These organize the overall page.</p><p>ElementPurpose&lt;html&gt;Root element of an HTML document&lt;head&gt;Contains document metadata and linked resources&lt;body&gt;Contains the document&#39;s page content&lt;header&gt;Introductory content&lt;nav&gt;Navigation&lt;main&gt;Main content&lt;section&gt;Thematic section&lt;article&gt;Self-contained content&lt;aside&gt;Complementary content&lt;footer&gt;Footer content</p><p>Example:</p><pre>&lt;body&gt;<br>  &lt;header&gt;Website Header&lt;/header&gt;<br>  &lt;main&gt;<br>    &lt;h1&gt;Welcome&lt;/h1&gt;<br>    &lt;p&gt;This is the main content.&lt;/p&gt;<br>  &lt;/main&gt;<br>  &lt;footer&gt;Website Footer&lt;/footer&gt;<br>&lt;/body&gt;</pre><p><strong>Expected browser output:</strong></p><pre>Website Header</pre><pre>Welcome<br>This is the main content.</pre><pre>Website Footer</pre><h3>B. Heading and text elements</h3><p>These represent headings, paragraphs, and other text.</p><p>ElementPurpose&lt;h1&gt;Highest-level heading&lt;h2&gt;–&lt;h6&gt;Lower-level headings&lt;p&gt;Paragraph&lt;strong&gt;Strong importance&lt;em&gt;Stress emphasis&lt;b&gt;Draws attention&lt;i&gt;Alternate voice or distinguished text&lt;mark&gt;Highlighted text&lt;small&gt;Side comments or small print&lt;del&gt;Deleted text&lt;ins&gt;Inserted text&lt;sub&gt;Subscript&lt;sup&gt;Superscript&lt;blockquote&gt;Block quotation&lt;q&gt;Inline quotation&lt;code&gt;Code fragment&lt;pre&gt;Preformatted text</p><p>Example:</p><pre>&lt;h1&gt;HTML Basics&lt;/h1&gt;<br>&lt;p&gt;HTML defines the structure of a web page.&lt;/p&gt;<br>&lt;p&gt;This is &lt;mark&gt;important&lt;/mark&gt; information.&lt;/p&gt;<br>&lt;p&gt;Water is H&lt;sub&gt;2&lt;/sub&gt;O.&lt;/p&gt;<br>&lt;p&gt;Two squared is 2&lt;sup&gt;2&lt;/sup&gt;.&lt;/p&gt;</pre><p><strong>Expected browser output:</strong></p><h3>HTML Basics</h3><p>HTML defines the structure of a web page.</p><p>This is highlighted information.</p><p>Water is H₂O.</p><p>Two squared is ²².</p><h3>C. List elements</h3><p>Lists organize related items.</p><p>ElementPurpose&lt;ul&gt;Unordered list&lt;ol&gt;Ordered list&lt;li&gt;List item&lt;dl&gt;Description list&lt;dt&gt;Term or name in a description list&lt;dd&gt;Description or value</p><p>Example:</p><pre>&lt;h2&gt;Technologies I Am Learning&lt;/h2&gt;</pre><pre>&lt;ul&gt;<br>  &lt;li&gt;HTML&lt;/li&gt;<br>  &lt;li&gt;CSS&lt;/li&gt;<br>  &lt;li&gt;JavaScript&lt;/li&gt;<br>&lt;/ul&gt;</pre><p><strong>Expected browser output:</strong></p><p>Technologies I Am Learning</p><ul><li>HTML</li><li>CSS</li><li>JavaScript</li></ul><h3>D. Link elements</h3><p>The &lt;a&gt; element creates a hyperlink.</p><pre>&lt;a href=&quot;https://developer.mozilla.org/&quot;&gt;<br>  Learn HTML on MDN<br>&lt;/a&gt;</pre><p><strong>Expected browser output:</strong></p><p>Learn HTML on MDN</p><p>Clicking the link opens the specified destination.</p><p>The href attribute specifies the destination. Without a valid destination, the anchor does not function as an ordinary hyperlink in the same way.</p><h3>E. Image and multimedia elements</h3><p>ElementPurpose&lt;img&gt;Displays an image&lt;audio&gt;Embeds audio&lt;video&gt;Embeds video&lt;source&gt;Supplies a media source&lt;track&gt;Supplies timed text, such as captions&lt;picture&gt;Supports responsive or alternative image sources&lt;figure&gt;Groups self-contained content&lt;figcaption&gt;Provides a figure caption</p><p>Example:</p><pre>&lt;figure&gt;<br>  &lt;img src=&quot;html-logo.png&quot; alt=&quot;HTML logo&quot; width=&quot;120&quot;&gt;<br>  &lt;figcaption&gt;HTML logo&lt;/figcaption&gt;<br>&lt;/figure&gt;</pre><p><strong>Expected browser output:</strong></p><p>An HTML logo image appears above or beside its caption, depending on the surrounding layout and CSS.</p><p>The alt attribute provides alternative text for the image. Write it to communicate the image&#39;s purpose in context.</p><h3>F. Table elements</h3><p>ElementPurpose&lt;table&gt;Creates a table&lt;caption&gt;Provides a table caption&lt;thead&gt;Groups header rows&lt;tbody&gt;Groups body rows&lt;tfoot&gt;Groups footer rows&lt;tr&gt;Table row&lt;th&gt;Header cell&lt;td&gt;Data cell&lt;colgroup&gt;Groups columns&lt;col&gt;Defines properties for a column</p><p>Example:</p><pre>&lt;table&gt;<br>  &lt;caption&gt;Student Marks&lt;/caption&gt;<br>  &lt;thead&gt;<br>    &lt;tr&gt;<br>      &lt;th&gt;Name&lt;/th&gt;<br>      &lt;th&gt;Marks&lt;/th&gt;<br>    &lt;/tr&gt;<br>  &lt;/thead&gt;<br>  &lt;tbody&gt;<br>    &lt;tr&gt;<br>      &lt;td&gt;Amol&lt;/td&gt;<br>      &lt;td&gt;85&lt;/td&gt;<br>    &lt;/tr&gt;<br>    &lt;tr&gt;<br>      &lt;td&gt;Rahul&lt;/td&gt;<br>      &lt;td&gt;90&lt;/td&gt;<br>    &lt;/tr&gt;<br>  &lt;/tbody&gt;<br>&lt;/table&gt;</pre><p><strong>Expected browser output:</strong></p><p>NameMarksAmol85Rahul90</p><p>The browser normally displays a table structure, but visible borders depend on the default browser styling or your CSS.</p><h3>G. Form elements</h3><p>These collect information from users.</p><p>ElementPurpose&lt;form&gt;Groups form controls for submission&lt;label&gt;Labels a form control&lt;input&gt;Provides an input control&lt;textarea&gt;Provides a multiline text field&lt;button&gt;Creates a button&lt;select&gt;Creates a selection control&lt;option&gt;Defines a selectable option&lt;optgroup&gt;Groups options&lt;fieldset&gt;Groups related controls&lt;legend&gt;Labels a fieldset&lt;datalist&gt;Supplies suggested input options&lt;output&gt;Represents a calculated or resulting value&lt;progress&gt;Displays task progress&lt;meter&gt;Displays a value within a known range</p><p>Example:</p><pre>&lt;form&gt;<br>  &lt;label for=&quot;email&quot;&gt;Email:&lt;/label&gt;<br>  &lt;input id=&quot;email&quot; type=&quot;email&quot; required&gt;</pre><pre>  &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;<br>&lt;/form&gt;</pre><p><strong>Expected browser output:</strong></p><p>Email: [email input field]</p><p>[Submit]</p><p>The exact appearance of controls depends on the browser and operating system. The required attribute asks the browser to validate that the email field has a value before normal form submission.</p><h3>H. Interactive elements</h3><p>ElementPurpose&lt;button&gt;Activatable button&lt;details&gt;Expandable disclosure widget&lt;summary&gt;Label for a details widget&lt;dialog&gt;Dialog box&lt;input&gt;Interactive form control&lt;select&gt;Selection control</p><p>Example:</p><pre>&lt;details&gt;<br>  &lt;summary&gt;What is HTML?&lt;/summary&gt;<br>  &lt;p&gt;HTML defines the structure of web pages.&lt;/p&gt;<br>&lt;/details&gt;</pre><p><strong>Expected browser output:</strong></p><p>A disclosure labelled “What is HTML?” appears. Activating it expands the content.</p><p>This example demonstrates built-in interactive behavior without JavaScript.</p><h3>I. Metadata elements</h3><p>Metadata describes the document or connects it to external resources. It is usually placed inside &lt;head&gt;.</p><p>ElementPurpose&lt;title&gt;Sets the document title&lt;meta&gt;Provides metadata&lt;link&gt;Links external resources&lt;style&gt;Contains CSS&lt;script&gt;Embeds or references JavaScript&lt;base&gt;Defines the base URL for relative URLs</p><p>Example:</p><pre>&lt;head&gt;<br>  &lt;title&gt;My HTML Page&lt;/title&gt;<br>  &lt;meta charset=&quot;UTF-8&quot;&gt;<br>  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>&lt;/head&gt;</pre><p>The title usually appears in the browser tab, while the metadata configures aspects of the document. These elements are not normally displayed as page content.</p><h3>14. HTML Nesting Rules</h3><p>Nesting means placing one element inside another element.</p><p>Correct nesting helps the browser interpret the document structure and keeps the HTML valid.</p><h3>Rule 1: Close normal elements correctly</h3><p>Correct:</p><pre>&lt;p&gt;This is a paragraph.&lt;/p&gt;</pre><p>Incorrect:</p><pre>&lt;p&gt;This is a paragraph.</pre><p>Some HTML elements have optional end tags under specific conditions, but explicitly closing ordinary elements when appropriate makes code easier to understand.</p><h3>Rule 2: Nest elements in the correct order</h3><p>Correct:</p><pre>&lt;p&gt;This is &lt;strong&gt;important&lt;/strong&gt; text.&lt;/p&gt;</pre><p>Incorrect:</p><pre>&lt;p&gt;This is &lt;strong&gt;important text.&lt;/p&gt;&lt;/strong&gt;</pre><p>The inner element should be closed before the outer element.</p><h3>Rule 3: Do not place block-content elements inside a paragraph</h3><p>Incorrect:</p><pre>&lt;p&gt;<br>  This is a paragraph.<br>  &lt;div&gt;This is a div.&lt;/div&gt;<br>&lt;/p&gt;</pre><p>A &lt;p&gt; element accepts phrasing content, not a &lt;div&gt;. Browsers may automatically close the paragraph before the &lt;div&gt;, producing a structure different from what you intended.</p><p>Correct:</p><pre>&lt;p&gt;This is a paragraph.&lt;/p&gt;<br>&lt;div&gt;This is a separate container.&lt;/div&gt;</pre><h3>Rule 4: Do not nest a paragraph inside another paragraph</h3><p>Incorrect:</p><pre>&lt;p&gt;<br>  First paragraph<br>  &lt;p&gt;Second paragraph&lt;/p&gt;<br>&lt;/p&gt;</pre><p>Correct:</p><pre>&lt;p&gt;First paragraph&lt;/p&gt;<br>&lt;p&gt;Second paragraph&lt;/p&gt;</pre><h3>Rule 5: Void elements cannot contain child elements</h3><p>Incorrect:</p><pre>&lt;img&gt;<br>  &lt;span&gt;Image description&lt;/span&gt;<br>&lt;/img&gt;</pre><p>Correct:</p><pre>&lt;img src=&quot;photo.jpg&quot; alt=&quot;Person standing outdoors&quot;&gt;</pre><p>If you need a visible caption, use a suitable structure such as &lt;figure&gt; and &lt;figcaption&gt;.</p><h3>Rule 6: Follow the content model of each element</h3><p>Different elements have different rules about what they can contain.</p><p>For example:</p><ul><li>A &lt;ul&gt; normally contains &lt;li&gt; elements.</li><li>A &lt;select&gt; contains options and permitted grouping elements.</li><li>A &lt;button&gt; cannot contain interactive descendants such as another button.</li><li>An &lt;a&gt; cannot contain another &lt;a&gt; element.</li><li>A &lt;p&gt; cannot contain a &lt;div&gt;.</li></ul><p>The rule is not simply “block elements can contain block elements” or “inline elements can contain inline elements.” The HTML specification’s content models determine valid nesting.</p><h3>15. Real-World Scenario: Building a Project Card</h3><p>Imagine you are creating a portfolio website with a card for each project.</p><p>A project card might contain a heading, description, technology labels, and a link.</p><pre>&lt;article class=&quot;project-card&quot;&gt;<br>  &lt;h2&gt;BPL Official&lt;/h2&gt;</pre><pre>  &lt;p&gt;<br>    A cricket tournament website with team information,<br>    player registration, and match details.<br>  &lt;/p&gt;</pre><pre>  &lt;p&gt;<br>    Technologies:<br>    &lt;span&gt;Next.js&lt;/span&gt;<br>    &lt;span&gt;TypeScript&lt;/span&gt;<br>    &lt;span&gt;MongoDB&lt;/span&gt;<br>  &lt;/p&gt;</pre><pre>  &lt;a href=&quot;#bpl-project&quot;&gt;View Project&lt;/a&gt;<br>&lt;/article&gt;</pre><p><strong>Expected browser output:</strong></p><pre>BPL Official</pre><pre>A cricket tournament website with team information,<br>player registration, and match details.</pre><pre>Technologies: Next.js TypeScript MongoDB</pre><pre>View Project</pre><p>The exact spacing and appearance depend on browser defaults and any CSS you add.</p><h3>Why were these elements selected?</h3><p>ElementReason&lt;article&gt;Represents a self-contained project card&lt;h2&gt;Provides the card&#39;s heading&lt;p&gt;Represents the description&lt;span&gt;Groups individual technology labels without adding semantic meaning&lt;a&gt;Provides a link to the project</p><p>If these labels need to look like badges, CSS can style the spans:</p><pre>.project-card span {<br>  display: inline-block;<br>  margin: 4px;<br>  padding: 6px 10px;<br>  background: #eeeeff;<br>  border-radius: 6px;<br>}</pre><p>Now the technology names appear as compact badges rather than ordinary text.</p><p>Notice that the HTML describes the content, while CSS controls the visual presentation.</p><h3>16. Common Mistakes Beginners Should Avoid</h3><h3>Mistake 1: Assuming every semantic element is block-level</h3><p>Many semantic elements are normally block-displayed, but semantic meaning and layout behavior are different concepts.</p><h3>Mistake 2: Assuming every block element is semantic</h3><p>&lt;div&gt; is normally block-displayed but has no specific semantic meaning.</p><h3>Mistake 3: Adding closing tags to void elements</h3><p>Do not write &lt;/img&gt;, &lt;/br&gt;, or &lt;/input&gt; in HTML.</p><h3>Mistake 4: Using &lt;br&gt; to create page spacing</h3><p>Use &lt;br&gt; for a line break within content, such as an address or poem. Use CSS margins and padding for visual spacing between sections.</p><h3>Mistake 5: Using &lt;div&gt; for everything</h3><p>Prefer meaningful elements such as &lt;nav&gt;, &lt;main&gt;, &lt;article&gt;, and &lt;section&gt; when they accurately describe the content.</p><h3>Mistake 6: Believing that inline elements can never contain other elements</h3><p>Some inline elements can contain other permitted elements. The correct rule depends on the element’s content model.</p><h3>Mistake 7: Confusing &lt;b&gt; with &lt;strong&gt;</h3><p>&lt;b&gt; draws attention to text without indicating that it is more important. &lt;strong&gt; represents strong importance.</p><h3>Mistake 8: Confusing &lt;i&gt; with &lt;em&gt;</h3><p>&lt;i&gt; marks text in an alternate voice or mood, or text that is otherwise distinguished. &lt;em&gt; indicates stress emphasis.</p><h3>Mistake 9: Assuming CSS changes an element’s semantic meaning</h3><p>Setting display: block on a &lt;span&gt; changes its layout behavior, not its HTML meaning.</p><h3>Mistake 10: Using headings only to make text large</h3><p>Choose heading levels based on document structure. Use CSS to change font size or visual appearance.</p><h3>17. Quick Revision: HTML Element Classifications</h3><p>TypeMain ideaExamplesBlock-level behaviorNormally starts on a new line and uses available width&lt;div&gt;, &lt;p&gt;, &lt;section&gt;Inline behaviorNormally participates in the current text line&lt;span&gt;, &lt;a&gt;, &lt;strong&gt;Inline-blockA CSS display value combining inline flow with a boxdisplay: inline-blockVoidHas no closing tag or child content&lt;img&gt;, &lt;br&gt;, &lt;input&gt;Normal elementCan contain permitted child content&lt;div&gt;, &lt;p&gt;, &lt;section&gt;SemanticCommunicates meaning or purpose&lt;main&gt;, &lt;nav&gt;, &lt;article&gt;Non-semanticGeneric container without specific semantic meaning&lt;div&gt;, &lt;span&gt;StructuralOrganizes document sections&lt;header&gt;, &lt;main&gt;, &lt;footer&gt;TextRepresents headings, paragraphs, or text emphasis&lt;h1&gt;, &lt;p&gt;, &lt;em&gt;ListOrganizes related items&lt;ul&gt;, &lt;ol&gt;, &lt;li&gt;MultimediaEmbeds images, audio, or video&lt;img&gt;, &lt;audio&gt;, &lt;video&gt;FormCollects or represents user input&lt;form&gt;, &lt;input&gt;, &lt;textarea&gt;TableOrganizes data into rows and columns&lt;table&gt;, &lt;tr&gt;, &lt;td&gt;InteractiveProvides built-in interactive behavior&lt;button&gt;, &lt;details&gt;, &lt;dialog&gt;MetadataDescribes the document or connects resources&lt;title&gt;, &lt;meta&gt;, &lt;link&gt;</p><p>These categories can overlap. For example, &lt;img&gt; is both a void element and a multimedia element, and it normally participates in inline-level layout. &lt;header&gt; is semantic, structural, and normally block-displayed.</p><h3>18. Frequently Asked Questions</h3><h3>Are block-level and inline elements still relevant in modern HTML?</h3><p>Yes. They are useful ways to understand default layout behavior. However, modern CSS allows you to change how elements are displayed, and Flexbox and Grid provide additional layout systems.</p><h3>Is inline-block an HTML element?</h3><p>No. inline-block is a CSS value for the display property. You can apply it to elements such as &lt;span&gt; and &lt;div&gt;.</p><h3>Is &lt;img&gt; a block-level or void element?</h3><p>It is a void element because it has no closing tag and cannot contain children. By default, it normally participates in inline-level layout. These descriptions refer to different characteristics.</p><h3>Is &lt;hr&gt; a void element?</h3><p>Yes. &lt;hr&gt; is a void element and normally appears as a horizontal thematic break.</p><h3>Are &lt;div&gt; and &lt;span&gt; semantic elements?</h3><p>No. They are generic containers. Use them when a more meaningful element does not fit the situation.</p><h3>Can I change a block element into an inline element?</h3><p>Yes. CSS can change its layout behavior:</p><pre>div {<br>  display: inline;<br>}</pre><p>This does not change the element’s HTML semantics or content model.</p><h3>Does semantic HTML automatically improve SEO?</h3><p>No. Semantic HTML helps describe page structure and meaning, but it does not guarantee higher rankings. Useful content, technical quality, accessibility, and other factors also matter.</p><h3>Which element should I use for a section of my page?</h3><p>Choose based on the content:</p><ul><li>&lt;main&gt; for the main content of the page.</li><li>&lt;section&gt; for a thematic grouping.</li><li>&lt;article&gt; for self-contained content.</li><li>&lt;nav&gt; for a major navigation section.</li><li>&lt;div&gt; for a generic grouping without a suitable semantic alternative.</li></ul><h3>Conclusion</h3><p>Understanding HTML elements is about more than memorizing tag names. It means understanding how elements structure content, how browsers lay them out, which elements carry semantic meaning, and which rules determine valid HTML.</p><p>The most important concepts to remember are:</p><ul><li>Block and inline describe traditional default layout behavior.</li><li>inline-block is a CSS display value, not a separate HTML element type.</li><li>Void elements cannot contain children and do not have closing tags.</li><li>Semantic elements communicate meaning; non-semantic elements provide generic containers.</li><li>An element’s meaning, content rules, and CSS display behavior are separate concepts.</li><li>Correct nesting and choosing appropriate elements help create clear, maintainable HTML.</li></ul><p>As you continue learning HTML, try building a small page containing a header, navigation, main section, project card, image, list, and form. Inspect it in the browser, change its CSS display values, and observe how the layout changes.</p><p><strong>The best way to understand HTML is to write the markup, inspect the browser output, and experiment with it yourself.</strong></p><h3>Further Reading</h3><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements">MDN Web Docs: HTML elements reference</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_display/Block_and_inline_layout">MDN Web Docs: Block and inline layout</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Guides/Content_categories">MDN Web Docs: The content model</a></li><li><a href="https://html.spec.whatwg.org/">WHATWG HTML Living Standard</a></li></ul><p><em>This article is part of my web development learning journey, where I document concepts as I learn and practice them.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62b542f7d372" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTML Nesting: A Complete Beginner’s Guide with Examples]]></title>
            <link>https://medium.com/@amolpawar.me/html-nesting-a-complete-beginners-guide-with-examples-b0f434d2c517?source=rss-18c7290112c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0f434d2c517</guid>
            <category><![CDATA[website-design]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Amol Pawar]]></dc:creator>
            <pubDate>Wed, 14 Oct 2026 16:48:07 GMT</pubDate>
            <atom:updated>2026-10-14T16:48:07.199Z</atom:updated>
            <content:encoded><![CDATA[<h3>HTML is the foundation of every webpage. It helps us structure content such as headings, paragraphs, images, lists, forms, and navigation menus.</h3><p>When learning HTML, one of the most important concepts to understand is <strong>nesting</strong>.</p><p>Nesting allows us to place one HTML element inside another, creating a logical structure that browsers can interpret and display correctly.</p><p>In this article, we will explore HTML nesting, parent-child relationships, nesting rules, real-world examples, common mistakes, and best practices.</p><h3>What Is Nesting in HTML?</h3><p><strong>HTML nesting means placing one HTML element inside another HTML element.</strong></p><p>The element containing another element is called the <em>parent element</em>, while the element placed inside it is called the <em>child element</em>.</p><h3>Example</h3><pre>&lt;div&gt;<br>  &lt;p&gt;This is a paragraph inside a div.&lt;/p&gt;<br>&lt;/div&gt;</pre><p>In this example:</p><ul><li>&lt;div&gt; is the parent element.</li><li>&lt;p&gt; is the child element.</li><li>The paragraph is nested inside the division element.</li></ul><p>Nesting helps organize related content and create a meaningful webpage structure.</p><h3>Understanding Parent, Child, and Sibling Elements</h3><p>HTML elements form relationships based on their position in the document.</p><h3>1. Parent Element</h3><p>A parent element directly contains another element.</p><pre>&lt;div&gt;<br>  &lt;h2&gt;About HTML&lt;/h2&gt;<br>  &lt;p&gt;HTML structures web pages.&lt;/p&gt;<br>&lt;/div&gt;</pre><p>Here, the &lt;div&gt; element is the parent of both &lt;h2&gt; and &lt;p&gt;.</p><h3>2. Child Element</h3><p>A child element is directly contained inside another element.</p><pre>&lt;ul&gt;<br>  &lt;li&gt;HTML&lt;/li&gt;<br>  &lt;li&gt;CSS&lt;/li&gt;<br>  &lt;li&gt;JavaScript&lt;/li&gt;<br>&lt;/ul&gt;</pre><p>Each &lt;li&gt; element is a child of the &lt;ul&gt; element.</p><h3>3. Sibling Elements</h3><p>Sibling elements share the same direct parent.</p><pre>&lt;section&gt;<br>  &lt;h2&gt;My Skills&lt;/h2&gt;<br>  &lt;p&gt;I am learning web development.&lt;/p&gt;<br>&lt;/section&gt;</pre><p>The &lt;h2&gt; and &lt;p&gt; elements are siblings because they share the same parent.</p><h3>Rules of Correct HTML Nesting</h3><p>Following the correct nesting rules helps you write valid, readable, and maintainable HTML.</p><h3>1. Close Elements in the Correct Order</h3><p>When elements are nested, the innermost element should be closed first.</p><p><strong>Incorrect:</strong></p><pre>&lt;p&gt;This is &lt;strong&gt;important text.&lt;/p&gt;&lt;/strong&gt;</pre><p><strong>Correct:</strong></p><pre>&lt;p&gt;This is &lt;strong&gt;important text.&lt;/strong&gt;&lt;/p&gt;</pre><p>The &lt;strong&gt; element closes before the &lt;p&gt; element.</p><h3>2. Follow HTML Content Rules</h3><p>Not every HTML element can contain every other element. Each element has rules defining what content it can contain.</p><p>For example, a &lt;p&gt; element cannot contain a &lt;div&gt; element.</p><p><strong>Incorrect:</strong></p><pre>&lt;p&gt;<br>  This is a paragraph.<br>  &lt;div&gt;This is a div.&lt;/div&gt;<br>&lt;/p&gt;</pre><p><strong>Correct:</strong></p><pre>&lt;p&gt;This is a paragraph.&lt;/p&gt;</pre><pre>&lt;div&gt;This is a div.&lt;/div&gt;</pre><p>The &lt;div&gt; must be placed outside the paragraph.</p><h3>3. Void Elements Cannot Contain Children</h3><p>Void elements do not have closing tags and cannot contain child content.</p><p>Common examples include &lt;img&gt;, &lt;br&gt;, &lt;hr&gt;, &lt;input&gt;, &lt;meta&gt;, and &lt;link&gt;.</p><p><strong>Example:</strong></p><pre>&lt;div&gt;<br>  &lt;img src=&quot;profile.jpg&quot; alt=&quot;Profile picture&quot;&gt;<br>  &lt;p&gt;This is my profile.&lt;/p&gt;<br>&lt;/div&gt;</pre><p>The image and paragraph are children of the &lt;div&gt;, but the image itself cannot contain other elements.</p><h3>4. Use Proper Indentation</h3><p>Indentation makes nested structures easier to read and maintain.</p><pre>&lt;div&gt;<br>  &lt;section&gt;<br>    &lt;h2&gt;My Skills&lt;/h2&gt;<br>    &lt;ul&gt;<br>      &lt;li&gt;HTML&lt;/li&gt;<br>      &lt;li&gt;CSS&lt;/li&gt;<br>      &lt;li&gt;JavaScript&lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/section&gt;<br>&lt;/div&gt;</pre><p>Each level is indented to show its relationship with the parent element.</p><h3>Real-World Examples of HTML Nesting</h3><p>Nesting is used throughout almost every webpage.</p><h3>1. Nesting Links Inside Lists</h3><pre>&lt;ul&gt;<br>  &lt;li&gt;&lt;a href=&quot;/home&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;<br>  &lt;li&gt;&lt;a href=&quot;/about&quot;&gt;About&lt;/a&gt;&lt;/li&gt;<br>  &lt;li&gt;&lt;a href=&quot;/contact&quot;&gt;Contact&lt;/a&gt;&lt;/li&gt;<br>&lt;/ul&gt;</pre><p>Each list item contains an anchor element that creates a clickable link.</p><h3>2. Creating a Profile Card</h3><pre>&lt;div class=&quot;card&quot;&gt;<br>  &lt;img src=&quot;developer.jpg&quot; alt=&quot;Developer working&quot;&gt;</pre><pre>  &lt;div class=&quot;card-content&quot;&gt;<br>    &lt;h2&gt;Web Developer&lt;/h2&gt;<br>    &lt;p&gt;I build modern websites.&lt;/p&gt;<br>    &lt;a href=&quot;/portfolio&quot;&gt;View Portfolio&lt;/a&gt;<br>  &lt;/div&gt;<br>&lt;/div&gt;</pre><p>The outer &lt;div&gt; contains the image and content container. The inner container groups the heading, paragraph, and link.</p><p>This structure is commonly used for profile cards, product cards, and portfolio sections.</p><h3>3. Nesting Elements Inside Forms</h3><pre>&lt;form&gt;<br>  &lt;div&gt;<br>    &lt;label for=&quot;username&quot;&gt;Username:&lt;/label&gt;<br>    &lt;input type=&quot;text&quot; id=&quot;username&quot;&gt;<br>  &lt;/div&gt;</pre><pre>  &lt;div&gt;<br>    &lt;label for=&quot;email&quot;&gt;Email:&lt;/label&gt;<br>    &lt;input type=&quot;email&quot; id=&quot;email&quot;&gt;<br>  &lt;/div&gt;</pre><pre>  &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;<br>&lt;/form&gt;</pre><p>The form contains two groups of related controls and a submit button. Each &lt;div&gt; groups a label and its corresponding input.</p><h3>4. Nesting Elements Inside Tables</h3><pre>&lt;table&gt;<br>  &lt;thead&gt;<br>    &lt;tr&gt;<br>      &lt;th&gt;Name&lt;/th&gt;<br>      &lt;th&gt;Role&lt;/th&gt;<br>    &lt;/tr&gt;<br>  &lt;/thead&gt;</pre><pre>  &lt;tbody&gt;<br>    &lt;tr&gt;<br>      &lt;td&gt;Amol&lt;/td&gt;<br>      &lt;td&gt;Developer&lt;/td&gt;<br>    &lt;/tr&gt;<br>    &lt;tr&gt;<br>      &lt;td&gt;Rahul&lt;/td&gt;<br>      &lt;td&gt;Designer&lt;/td&gt;<br>    &lt;/tr&gt;<br>  &lt;/tbody&gt;<br>&lt;/table&gt;</pre><p>Here, the &lt;table&gt; contains table sections, which contain rows, and each row contains individual cells.</p><p>This demonstrates how multiple levels of nesting help organize structured information.</p><h3>What Happens When HTML Is Nested Incorrectly?</h3><p>Incorrect nesting can cause browsers to interpret and repair HTML in unexpected ways.</p><p>For example:</p><pre>&lt;p&gt;<br>  Paragraph text<br>  &lt;div&gt;Nested content&lt;/div&gt;<br>&lt;/p&gt;</pre><p>Because a &lt;div&gt; cannot be a child of a &lt;p&gt;, the browser may automatically close the paragraph before the &lt;div&gt;. The resulting DOM structure may differ from what the developer intended.</p><p>Incorrect nesting can lead to:</p><ul><li>Unexpected document structures.</li><li>Styling and layout problems.</li><li>Accessibility issues.</li><li>Confusing JavaScript behavior.</li><li>More difficult debugging and maintenance.</li></ul><p>Browsers can recover from many HTML errors, but writing valid markup is still important.</p><h3>HTML Nesting and the DOM Tree</h3><p>When a browser processes HTML, it creates a structure called the <strong>Document Object Model (DOM)</strong>.</p><p>The DOM represents the document as a tree of nodes connected through parent-child relationships.</p><p>Consider this example:</p><pre>&lt;div&gt;<br>  &lt;h1&gt;My Website&lt;/h1&gt;<br>  &lt;p&gt;Welcome to my website.&lt;/p&gt;<br>&lt;/div&gt;</pre><p>Its simplified structure looks like this:</p><pre>div<br>├── h1<br>│   └── &quot;My Website&quot;<br>└── p<br>    └── &quot;Welcome to my website.&quot;</pre><p>The &lt;div&gt; is the parent of the heading and paragraph. Each element contains its corresponding text node.</p><p>Understanding the DOM becomes especially useful when learning JavaScript because JavaScript can access, update, add, and remove elements in this tree.</p><h3>Common HTML Nesting Mistakes</h3><p>Beginners should avoid these common mistakes:</p><ul><li><strong>Incorrect closing order:</strong> Always close the innermost element first.</li><li><strong>Invalid parent-child relationships:</strong> Do not place elements inside parents that cannot contain them.</li><li><strong>Closing void elements:</strong> Elements such as &lt;img&gt; and &lt;br&gt; must not have explicit closing tags.</li><li><strong>Unnecessary nesting:</strong> Avoid adding extra containers that serve no structural or functional purpose.</li><li><strong>Poor indentation:</strong> Keep nested elements consistently formatted.</li><li><strong>Relying on browser corrections:</strong> Validate your HTML rather than assuming the browser will preserve your intended structure.</li></ul><h3>Best Practices for HTML Nesting</h3><ul><li>Follow the content rules of each HTML element.</li><li>Close elements in the correct order.</li><li>Use semantic elements such as &lt;main&gt;, &lt;nav&gt;, &lt;section&gt;, and &lt;article&gt; when appropriate.</li><li>Keep your markup simple and meaningful.</li><li>Indent nested elements consistently.</li><li>Use descriptive class names when grouping content for styling.</li><li>Validate your markup with an HTML validator.</li><li>Inspect the DOM in browser developer tools when debugging structural problems.</li></ul><h3>Conclusion</h3><p>HTML nesting is the practice of placing elements inside other elements to build a logical webpage structure.</p><p>Understanding parent, child, and sibling relationships helps you organize content correctly, avoid common markup errors, and write maintainable HTML.</p><p>Nesting is more than placing tags inside other tags. It is about creating a structure that browsers, developers, and assistive technologies can interpret correctly.</p><p><strong>Learn the structure. Follow the rules. Build better websites.</strong> 🚀</p><p>#HTML #WebDevelopment #FrontendDevelopment #Programming #LearnToCode</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0f434d2c517" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Paired and Unpaired Tags in HTML: A Complete Beginner’s Guide]]></title>
            <link>https://medium.com/@amolpawar.me/paired-and-unpaired-tags-in-html-a-complete-beginners-guide-219e126d8f27?source=rss-18c7290112c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/219e126d8f27</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Amol Pawar]]></dc:creator>
            <pubDate>Wed, 14 Oct 2026 16:28:18 GMT</pubDate>
            <atom:updated>2026-10-14T16:28:18.887Z</atom:updated>
            <content:encoded><![CDATA[<p>HTML is the foundation of every webpage. Whether you are building a personal portfolio, a business website, or a web application, understanding HTML is the first step toward becoming a web developer.</p><p>One of the basic concepts every beginner should understand is the difference between <strong>paired tags and unpaired tags</strong>.</p><p>In this article, we will explore both types, understand how they work, look at common examples, and learn the best practices for writing clean HTML.</p><h3>What Are Paired Tags in HTML?</h3><p>Paired tags are HTML tags that generally consist of an opening tag and a closing tag. The opening tag marks the beginning of an element, and the closing tag marks its end.</p><p>A closing tag contains a forward slash (/) before the tag name.</p><h3>Syntax</h3><pre>&lt;tagname&gt;Content goes here&lt;/tagname&gt;</pre><p>For example:</p><pre>&lt;p&gt;HTML is easy to learn.&lt;/p&gt;</pre><p>Here:</p><ul><li>&lt;p&gt; is the opening tag.</li><li>HTML is easy to learn. is the content.</li><li>&lt;/p&gt; is the closing tag.</li></ul><p>Together, they form a paragraph element.</p><h3>Common Examples of Paired Tags</h3><p><strong>1. Heading tags</strong></p><p>HTML provides six heading levels, from &lt;h1&gt; to &lt;h6&gt;.</p><pre>&lt;h1&gt;Main Heading&lt;/h1&gt;<br>&lt;h2&gt;Section Heading&lt;/h2&gt;<br>&lt;h3&gt;Subheading&lt;/h3&gt;</pre><p><strong>2. Paragraph tag</strong></p><p>The &lt;p&gt; element represents a paragraph.</p><pre>&lt;p&gt;This is a paragraph in HTML.&lt;/p&gt;</pre><p><strong>3. Anchor tag</strong></p><p>The &lt;a&gt; element creates hyperlinks.</p><pre>&lt;a href=&quot;https://example.com&quot;&gt;Visit Website&lt;/a&gt;</pre><p><strong>4. Formatting tags</strong></p><p>These elements communicate emphasis, importance, or other text meanings.</p><pre>&lt;strong&gt;Important text&lt;/strong&gt;<br>&lt;em&gt;Emphasized text&lt;/em&gt;<br>&lt;mark&gt;Highlighted text&lt;/mark&gt;<br>&lt;del&gt;Deleted text&lt;/del&gt;<br>&lt;sub&gt;Subscript text&lt;/sub&gt;<br>&lt;sup&gt;Superscript text&lt;/sup&gt;</pre><p><strong>5. Division and span tags</strong></p><p>The &lt;div&gt; element groups content, while &lt;span&gt; groups inline content.</p><pre>&lt;div&gt;<br>  &lt;h2&gt;About HTML&lt;/h2&gt;<br>  &lt;p&gt;HTML structures web pages.&lt;/p&gt;<br>&lt;/div&gt;</pre><pre>&lt;p&gt;Learn &lt;span&gt;HTML&lt;/span&gt; step by step.&lt;/p&gt;</pre><p><strong>6. List tags</strong></p><pre>&lt;ul&gt;<br>  &lt;li&gt;HTML&lt;/li&gt;<br>  &lt;li&gt;CSS&lt;/li&gt;<br>  &lt;li&gt;JavaScript&lt;/li&gt;<br>&lt;/ul&gt;</pre><p>The &lt;ul&gt; and &lt;li&gt; elements use opening and closing tags to create a list and its items.</p><p>Other common paired elements include &lt;html&gt;, &lt;head&gt;, &lt;title&gt;, &lt;body&gt;, &lt;main&gt;, &lt;section&gt;, &lt;article&gt;, &lt;form&gt;, &lt;button&gt;, &lt;table&gt;, &lt;script&gt;, and &lt;style&gt;.</p><h3>What Are Unpaired Tags in HTML?</h3><p>Unpaired tags are commonly called <strong>void elements</strong> in HTML. These elements do not have closing tags and cannot contain child content.</p><p>They perform specific tasks, such as displaying images, inserting line breaks, defining metadata, and loading external resources.</p><h3>Syntax</h3><pre>&lt;tagname&gt;</pre><p>For example:</p><pre>&lt;img src=&quot;photo.jpg&quot; alt=&quot;A beautiful landscape&quot;&gt;</pre><p>The &lt;img&gt; element displays an image and does not require a closing tag.</p><h3>Common Examples of Unpaired Tags</h3><p>TagPurpose&lt;img&gt;Embeds an image&lt;br&gt;Inserts a line break&lt;hr&gt;Represents a thematic break&lt;input&gt;Creates a form input&lt;meta&gt;Defines document metadata&lt;link&gt;References an external resource&lt;area&gt;Defines a clickable area in an image map&lt;base&gt;Specifies the base URL for relative URLs&lt;col&gt;Defines properties for a table column&lt;embed&gt;Embeds external content&lt;source&gt;Specifies a media resource&lt;track&gt;Specifies timed text tracks for media&lt;wbr&gt;Indicates a possible line-break position</p><p>&lt;param&gt; is another historical void element, but it is obsolete and should not be used in modern HTML.</p><h3>Examples of Unpaired Tags</h3><p><strong>1. Image tag</strong></p><pre>&lt;img src=&quot;profile.jpg&quot; alt=&quot;Profile picture&quot;&gt;</pre><p>The src attribute specifies the image location, and alt provides alternative text.</p><p><strong>2. Line break tag</strong></p><pre>&lt;p&gt;Hello!&lt;br&gt;Welcome to HTML.&lt;/p&gt;</pre><p>The &lt;br&gt; element moves the following text to a new line.</p><p><strong>3. Horizontal rule tag</strong></p><pre>&lt;p&gt;Introduction&lt;/p&gt;<br>&lt;hr&gt;<br>&lt;p&gt;Next section&lt;/p&gt;</pre><p>The &lt;hr&gt; element represents a thematic break between content.</p><p><strong>4. Input tag</strong></p><pre>&lt;input type=&quot;text&quot; placeholder=&quot;Enter your name&quot;&gt;</pre><p>The &lt;input&gt; element creates an input control.</p><p><strong>5. Metadata tag</strong></p><pre>&lt;meta charset=&quot;UTF-8&quot;&gt;</pre><p>This specifies the document’s character encoding.</p><h3>Difference Between Paired and Unpaired Tags</h3><p>FeaturePaired TagsUnpaired TagsStructureOpening and closing tagsNo closing tagContentCan contain text or child elements, depending on the elementCannot contain child contentClosing tagRequired for most elementsNot permittedPurposeStructures or groups contentPerforms a specific function or embeds a resourceExamples&lt;p&gt;, &lt;div&gt;, &lt;h1&gt;&lt;img&gt;, &lt;br&gt;, &lt;input&gt;</p><p>The main difference is simple: paired elements can contain content between their tags, whereas void elements cannot contain child content.</p><h3>Can Unpaired Tags Have Attributes?</h3><p>Yes! Void elements can have attributes just like other HTML elements.</p><pre>&lt;img src=&quot;logo.png&quot; alt=&quot;Company logo&quot; width=&quot;200&quot;&gt;</pre><pre>&lt;input type=&quot;email&quot; placeholder=&quot;Enter your email&quot; required&gt;</pre><pre>&lt;br class=&quot;line-break&quot;&gt;</pre><p>Attributes provide additional information or configure an element’s behavior.</p><p>For example, src specifies an image source, alt provides alternative text, and required makes a form field mandatory.</p><h3>Can We Use a Forward Slash in Unpaired Tags?</h3><p>You may see void elements written like this:</p><pre>&lt;img src=&quot;photo.jpg&quot; alt=&quot;Photo&quot; /&gt;<br>&lt;br /&gt;<br>&lt;hr /&gt;</pre><p>This syntax is accepted in HTML, but the trailing slash is unnecessary. It does not turn the element into an XML-style self-closing element.</p><p>The recommended HTML style is:</p><pre>&lt;img src=&quot;photo.jpg&quot; alt=&quot;Photo&quot;&gt;<br>&lt;br&gt;<br>&lt;hr&gt;</pre><p>Avoid writing explicit closing tags for void elements, such as &lt;/img&gt; or &lt;/br&gt;.</p><h3>Can Paired Tags Be Nested?</h3><p>Yes. HTML elements can contain other elements when their content rules allow it.</p><p>For example:</p><pre>&lt;div&gt;<br>  &lt;h2&gt;Web Development&lt;/h2&gt;<br>  &lt;p&gt;Learn &lt;strong&gt;HTML&lt;/strong&gt; and CSS.&lt;/p&gt;<br>&lt;/div&gt;</pre><p>Here, the &lt;div&gt; contains a heading and paragraph, while the paragraph contains a &lt;strong&gt; element.</p><p>Always close nested elements in the correct order.</p><p>Incorrect:</p><pre>&lt;p&gt;This is &lt;strong&gt;important&lt;/p&gt;&lt;/strong&gt;</pre><p>Correct:</p><pre>&lt;p&gt;This is &lt;strong&gt;important&lt;/strong&gt;&lt;/p&gt;</pre><p>Correct nesting makes your HTML easier to understand and maintain.</p><h3>Do All Paired Tags Require Closing Tags?</h3><p>Most paired elements require explicit closing tags. However, HTML defines certain elements whose closing tags can be omitted under specific conditions.</p><p>For example, list-item closing tags can be omitted in certain valid situations:</p><pre>&lt;ul&gt;<br>  &lt;li&gt;HTML<br>  &lt;li&gt;CSS<br>  &lt;li&gt;JavaScript<br>&lt;/ul&gt;</pre><p>Although this can be valid HTML, beginners should generally use explicit closing tags:</p><pre>&lt;ul&gt;<br>  &lt;li&gt;HTML&lt;/li&gt;<br>  &lt;li&gt;CSS&lt;/li&gt;<br>  &lt;li&gt;JavaScript&lt;/li&gt;<br>&lt;/ul&gt;</pre><p>This improves readability and makes the document easier to maintain.</p><h3>Common Mistakes Beginners Should Avoid</h3><p><strong>1. Adding a closing tag to a void element</strong></p><p>Incorrect:</p><pre>&lt;img src=&quot;photo.jpg&quot;&gt;&lt;/img&gt;</pre><p>Correct:</p><pre>&lt;img src=&quot;photo.jpg&quot; alt=&quot;Photo&quot;&gt;</pre><p><strong>2. Forgetting to close a paired element</strong></p><p>Incorrect:</p><pre>&lt;p&gt;Learning HTML</pre><p>Correct:</p><pre>&lt;p&gt;Learning HTML&lt;/p&gt;</pre><p><strong>3. Nesting elements incorrectly</strong></p><p>Incorrect:</p><pre>&lt;strong&gt;&lt;em&gt;Important text&lt;/strong&gt;&lt;/em&gt;</pre><p>Correct:</p><pre>&lt;strong&gt;&lt;em&gt;Important text&lt;/em&gt;&lt;/strong&gt;</pre><p><strong>4. Assuming that every element without visible text is unpaired</strong></p><p>Elements such as &lt;script&gt;, &lt;style&gt;, and &lt;textarea&gt; generally have opening and closing tags, even when they contain no ordinary visible text.</p><p><strong>5. Confusing tags with elements</strong></p><p>A tag is the markup notation, such as &lt;p&gt; or &lt;/p&gt;. An element is the complete HTML structure, including its tags and content where applicable.</p><h3>Best Practices for Writing HTML</h3><ul><li>Learn the standard void elements and never add closing tags to them.</li><li>Close paired elements correctly and maintain valid nesting.</li><li>Use indentation to make nested markup readable.</li><li>Add meaningful alt text to images.</li><li>Use semantic elements such as &lt;main&gt;, &lt;nav&gt;, &lt;article&gt;, and &lt;section&gt; when appropriate.</li><li>Use an HTML validator to identify markup errors.</li><li>Prefer consistent, readable markup instead of relying on optional closing tags.</li></ul><h3>Conclusion</h3><p>Understanding paired and unpaired tags is an essential step in learning HTML.</p><p><strong>Remember:</strong></p><ul><li><strong>Paired tags</strong> generally have an opening tag and a closing tag, such as &lt;p&gt;Content&lt;/p&gt;.</li><li><strong>Unpaired tags</strong>, more precisely called void elements, have no closing tags and cannot contain child content, such as &lt;img&gt; and &lt;br&gt;.</li></ul><p>Once you understand this difference, you can write better-structured HTML and build a strong foundation for learning CSS, JavaScript, and modern frontend development.</p><p>Keep learning, keep practicing, and keep building! 🚀</p><p>#HTML #WebDevelopment #FrontendDevelopment #Programming #LearnToCode</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=219e126d8f27" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the HTML <span> Tag: A Complete Beginner’s Guide]]></title>
            <link>https://medium.com/@amolpawar.me/understanding-the-html-span-tag-a-complete-beginners-guide-1e9a8d0042c1?source=rss-18c7290112c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e9a8d0042c1</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Amol Pawar]]></dc:creator>
            <pubDate>Mon, 12 Oct 2026 13:27:53 GMT</pubDate>
            <atom:updated>2026-10-12T13:27:53.747Z</atom:updated>
            <content:encoded><![CDATA[<p>HTML provides many elements for structuring and organizing webpage content. Some elements define headings and paragraphs, while others help developers target specific portions of content for styling and interaction.</p><p>One such element is the <strong>&lt;span&gt; tag</strong>.</p><p>The &lt;span&gt; tag is a generic inline container that allows developers to select, style, or manipulate a specific part of text without creating a separate block of content.</p><p>In this article, we’ll explore the &lt;span&gt; tag, its syntax, practical examples, CSS styling, JavaScript usage, and the differences between &lt;span&gt; and &lt;div&gt;.</p><h3>1. What Is the HTML &lt;span&gt; Tag?</h3><p>The HTML &lt;span&gt; tag is an inline element used to group a small section of text or other phrasing content.</p><p>By itself, it does not represent any special meaning. Its primary purpose is to provide a target for CSS styling or JavaScript manipulation.</p><p>For example:</p><pre>&lt;p&gt;<br>    I am learning &lt;span&gt;HTML&lt;/span&gt; and CSS.<br>&lt;/p&gt;</pre><p>Here, the word HTML is wrapped inside a &lt;span&gt; element. By default, it looks the same as the surrounding text.</p><p>However, we can use CSS to change its appearance.</p><h3>2. Syntax of the &lt;span&gt; Tag</h3><p>The basic syntax is:</p><pre>&lt;span&gt;Content goes here&lt;/span&gt;</pre><p>The element contains three parts:</p><ul><li><strong>Opening tag:</strong> &lt;span&gt; starts the inline container.</li><li><strong>Content:</strong> The text or other permitted inline content.</li><li><strong>Closing tag:</strong> &lt;/span&gt; ends the container.</li></ul><p>The &lt;span&gt; tag is a paired element because it normally requires both opening and closing tags.</p><h3>3. Complete HTML Example</h3><p>Let’s see how the &lt;span&gt; tag works inside a complete HTML document.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;HTML Span Tag&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h1&gt;Learning HTML&lt;/h1&gt;</pre><pre>    &lt;p&gt;<br>        HTML structures content, while<br>        &lt;span&gt;CSS&lt;/span&gt; styles it.<br>    &lt;/p&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>In this example, the &lt;span&gt; element wraps the word CSS without creating a new line or changing the paragraph&#39;s structure.</p><h3>4. Styling the &lt;span&gt; Tag with CSS</h3><p>One of the most common uses of &lt;span&gt; is styling a specific word or phrase within a sentence.</p><h3>Example: Changing Text Color</h3><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;Span Styling&lt;/title&gt;</pre><pre>    &lt;style&gt;<br>        .highlight {<br>            color: orange;<br>            font-weight: bold;<br>        }<br>    &lt;/style&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;p&gt;<br>        Welcome to &lt;span class=&quot;highlight&quot;&gt;Amol Codes&lt;/span&gt;!<br>    &lt;/p&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>What happens here?</strong></p><ul><li>The &lt;span&gt; element wraps the text Amol Codes.</li><li>The class attribute connects the element to the .highlight CSS rule.</li><li>The color property changes the text to orange.</li><li>The font-weight property makes the text bold.</li></ul><p>The rest of the paragraph remains unaffected by these styles.</p><h3>Common CSS Properties Used with &lt;span&gt;</h3><p>CSS PropertyPurposecolorChanges the text color.background-colorChanges the background color.font-sizeControls the text size.font-weightControls the thickness of the text.font-styleApplies styles such as italic.text-decorationAdds or removes text decoration.borderAdds a border around the element.paddingAdds space inside the element&#39;s box.</p><h3>5. Using &lt;span&gt; with Classes and IDs</h3><p>The class and id attributes allow developers to identify and target specific HTML elements.</p><h3>Using a Class</h3><p>Classes are useful when the same styling needs to be applied to multiple elements.</p><pre>&lt;style&gt;<br>    .highlight {<br>        color: blue;<br>        font-weight: bold;<br>    }<br>&lt;/style&gt;</pre><pre>&lt;p&gt;Learn &lt;span class=&quot;highlight&quot;&gt;HTML&lt;/span&gt;.&lt;/p&gt;<br>&lt;p&gt;Practice &lt;span class=&quot;highlight&quot;&gt;CSS&lt;/span&gt;.&lt;/p&gt;</pre><p>Both highlighted words receive the same styling.</p><h3>Using an ID</h3><p>An ID is used to identify a specific element within a document.</p><pre>&lt;style&gt;<br>    #important {<br>        color: red;<br>        font-weight: bold;<br>    }<br>&lt;/style&gt;</pre><pre>&lt;p&gt;<br>    Please read this<br>    &lt;span id=&quot;important&quot;&gt;important message&lt;/span&gt;.<br>&lt;/p&gt;</pre><p>Use classes for reusable styling and IDs when a unique identifier is appropriate.</p><h3>6. Using &lt;span&gt; with JavaScript</h3><p>The &lt;span&gt; tag is also useful when JavaScript needs to update a small portion of a webpage.</p><p>Consider this example:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;Span with JavaScript&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;p&gt;<br>        Current status: &lt;span id=&quot;status&quot;&gt;Pending&lt;/span&gt;<br>    &lt;/p&gt;</pre><pre>    &lt;button onclick=&quot;updateStatus()&quot;&gt;Update Status&lt;/button&gt;</pre><pre>    &lt;script&gt;<br>        function updateStatus() {<br>            document.getElementById(&quot;status&quot;).textContent = &quot;Completed&quot;;<br>        }<br>    &lt;/script&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>When the button is clicked, JavaScript changes the status from Pending to Completed.</p><p>The &lt;span&gt; element provides a convenient target, allowing JavaScript to update only the required text without replacing the entire paragraph.</p><h3>7. Difference Between &lt;span&gt; and &lt;div&gt;</h3><p>Both &lt;span&gt; and &lt;div&gt; are generic container elements, but their default display behaviors are different.</p><p>&lt;span&gt;&lt;div&gt;Inline element by default.Block-level element by default.Does not normally start a new line.Normally starts on a new line.Suitable for targeting a small part of text.Suitable for grouping larger sections of content.Flows alongside surrounding text.Normally occupies the available width of its parent.Used within phrasing content.Used to group flow content.</p><h3>Example</h3><pre>&lt;p&gt;<br>    This is &lt;span style=&quot;color: red;&quot;&gt;inline text&lt;/span&gt;<br>    inside a paragraph.<br>&lt;/p&gt;</pre><pre>&lt;div style=&quot;background-color: lightblue;&quot;&gt;<br>    This is a div container.<br>&lt;/div&gt;</pre><p>The &lt;span&gt; remains within the sentence, while the &lt;div&gt; creates a separate block.</p><p><strong>Remember:</strong> CSS can change the display behavior of either element, but their typical use cases remain different.</p><h3>8. Does the &lt;span&gt; Tag Have Default Styling?</h3><p>The &lt;span&gt; element has no special visual styling by default.</p><p>For example:</p><pre>&lt;p&gt;<br>    This is a &lt;span&gt;normal word&lt;/span&gt; in a sentence.<br>&lt;/p&gt;</pre><p>The word inside &lt;span&gt; generally looks the same as the surrounding text.</p><p>Its important default behavior is that it is an inline element, meaning it participates in the surrounding text flow instead of starting a new line.</p><h3>9. Where Can We Use the &lt;span&gt; Tag?</h3><p>The &lt;span&gt; tag can be used inside paragraphs, headings, links, list items, and other elements that allow phrasing content.</p><p>For example:</p><pre>&lt;h1&gt;<br>    Welcome to &lt;span style=&quot;color: purple;&quot;&gt;HTML&lt;/span&gt;<br>&lt;/h1&gt;</pre><pre>&lt;p&gt;<br>    Keep learning and<br>    &lt;span style=&quot;font-weight: bold;&quot;&gt;practicing every day&lt;/span&gt;.<br>&lt;/p&gt;</pre><pre>&lt;a href=&quot;https://example.com&quot;&gt;<br>    Visit &lt;span&gt;our website&lt;/span&gt;<br>&lt;/a&gt;</pre><p>These examples demonstrate how &lt;span&gt; can target individual words without changing the overall content structure.</p><p>However, &lt;span&gt; does not make otherwise invalid HTML nesting valid. Always follow the content rules of the surrounding element.</p><h3>10. Common Mistakes to Avoid</h3><h3>Mistake 1: Expecting &lt;span&gt; to Create a New Line</h3><pre>&lt;p&gt;Hello &lt;span&gt;World&lt;/span&gt;&lt;/p&gt;</pre><p>The text normally appears on the same line because &lt;span&gt; is inline by default.</p><p>If you need a separate block, consider using a &lt;div&gt; or another suitable HTML element.</p><h3>Mistake 2: Using Too Many Unnecessary &lt;span&gt; Elements</h3><pre>&lt;p&gt;<br>    &lt;span&gt;This is&lt;/span&gt;<br>    &lt;span&gt;a simple&lt;/span&gt;<br>    &lt;span&gt;paragraph.&lt;/span&gt;<br>&lt;/p&gt;</pre><p>If you do not need to style or manipulate those individual sections, using a normal paragraph is simpler and easier to maintain.</p><h3>Mistake 3: Using &lt;span&gt; Instead of Semantic Elements</h3><p>If a phrase conveys importance or emphasis, consider using &lt;strong&gt; or &lt;em&gt; instead of a generic &lt;span&gt;.</p><pre>&lt;p&gt;<br>    &lt;strong&gt;Warning:&lt;/strong&gt; Save your changes.<br>&lt;/p&gt;</pre><p>Semantic HTML communicates meaning more clearly to browsers, developers, and assistive technologies.</p><h3>11. Best Practices for Using the &lt;span&gt; Tag</h3><ul><li>Use &lt;span&gt; to target specific portions of inline content.</li><li>Use CSS classes for reusable styling.</li><li>Use IDs for unique element identification.</li><li>Use JavaScript when you need to update targeted content dynamically.</li><li>Avoid adding unnecessary &lt;span&gt; elements.</li><li>Prefer semantic HTML elements when they better describe the content.</li><li>Remember that &lt;span&gt; is inline by default, although CSS can change its display behavior.</li></ul><h3>Conclusion</h3><p>The HTML &lt;span&gt; tag is a simple but powerful tool for working with specific portions of text. Although it has no special semantic meaning or default visual styling, it provides a convenient way to apply CSS styles and interact with content using JavaScript.</p><p>Understanding when to use &lt;span&gt; and how it differs from &lt;div&gt; will help you write cleaner, more flexible HTML.</p><p>As I continue documenting my web development journey, I am revisiting fundamental concepts, practicing with examples, and building a strong foundation for frontend development.</p><p><strong>Keep learning. Keep building. Keep growing.</strong></p><p>#HTML #WebDevelopment #FrontendDevelopment #HTMLTutorial #AmolCodes</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e9a8d0042c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>