Thumbnail for HTML Elements and Tags episode.
4 minutes

Demystifying HTML Elements - Unveiling the Magic of Elements and Tags!

Welcome back, fellow web explorer! In this enchanting episode, we’re delving deeper into the whimsical world of HTML elements and tags. Buckle up because we’re about to unlock the secrets of the web’s building blocks with some magical code examples.

The Web’s Building Blocks: HTML Elements and Tags

Imagine HTML as the sorcerer’s spellbook for creating web pages. The spells are the HTML elements, and the enchanting words that cast them are the HTML tags. Elements tell the browser how to display different parts of your web page, and tags are the incantations that bring these elements to life.

  • Opening and Closing Tags: HTML tags come in pairs, like magic words in a spell. The opening tag (<tag>) marks the beginning, and the closing tag (</tag>) signals the end. For example, to create a paragraph, use <p> as the opening tag and </p> as the closing tag.
    <p>This is a magical paragraph!</p>
  • Using Attributes: Tags can have attributes, like wands with special powers. Attributes provide extra information about an element. For instance, **src** attribute in an image tag (<img>) accepts a path to the image you want to include and the alt attribute provides alternative text for the image. What is alternative text ? Well, it will appear on screen if the browser cannot find the image you want to import (meaning the link is broken). It is also needed for accessibility purposes, but that is a whole different topic.
    <img src="wizard.jpg" alt="A wise wizard casting a spell" />
    <!-- Other notation for "orphan" tags -->
    <img src="wizard.jpg" alt="A wise wizard casting a spell" />
    You might ask, “hey where is the closing tag?” and you would be right to ask that, or maybe this small detail just eluded you and that’s fine. In HTML, there are some “orphan” tags, don’t feel bad for them, they like being on their own 😉. It just means they can’t contain any content as they are themselves the content, meaning you cannot insert other tags inside.
  • Block-Level vs. Inline Elements: HTML elements are like characters in a story. Some are block-level, meaning they create a distinct “block” on the page. Others are inline, seamlessly woven into the text. Block-level elements start on a new line and take up the full width, while inline elements stay within the flow of the text.

Common HTML Elements in Action

Now, let’s have some fun with a few of the most common HTML elements:

  • Headings (<h1> to <h6>): These are like royal banners announcing different sections of your web page. The higher the number, the humbler the banner. <h1> is the grandest, and <h6> is the most modest. In the real world, you can compare them to Word headings, the first level is the most important and the sixth the least. Try and respect the heading’s hierarchy in your web pages as you would in a text document.
    <h1>The Grand Adventure Begins</h1>
    <h3>A Quest for Hidden Treasures</h3>
  • Paragraphs (<p>): Your storyteller on the web! Wrap your text in <p> tags to create neatly formatted paragraphs.
    <p>Once upon a time, in a land of magic and wonder...</p>
    <p>...they embarked on an epic journey.</p>
  • Lists (Ordered <ol> and Unordered <ul>): Lists are your organizers. <ol> makes numbered lists (like treasure maps), and <ul> creates bulleted lists (like bags of gold). Each item of your list uses an <li> tag.
    <h2>Treasure Hunt Steps</h2>
    <ol>
      <li>Find the treasure map</li>
      <li>Follow the path</li>
      <li>Dig carefully</li>
    </ol>
    <h2>Discoveries</h2>
    <ul>
      <li>Golden coins</li>
      <li>Mysterious potions</li>
      <li>Jeweled artifacts</li>
    </ul>

Embrace the Magic of HTML Elements!

With these HTML elements and tags under your wizard’s hat, you’re ready to cast your own web spells. The web is your magical canvas, and the elements are your tools for creating captivating web pages.

In our next mystical episode, we’ll explore more enchanting elements and delve deeper into the art of web wizardry. Stay tuned, and remember, the web is your enchanted forest, full of wonders to explore! 🧙‍♂️🪄

Photo of Mark Tegethoff from Unsplash