A Beginner's Guide: Learning HTML Tags for Aspiring Frontend Developers - Part 3

Welcome to the world of frontend development, where we're about to unravel the magic of HTML – the language that gives structure to every webpage. Don't worry if coding seems like a foreign language; this guide is crafted especially for those starting with a clean slate. Let's embark on this journey of understanding HTML tags, the building blocks that bring content to life on the web.

Understanding HTML

HTML, or HyperText Markup Language, is like the scaffolding that holds up a building. It uses tags to create the structure of a webpage, instructing browsers on how to present content. Think of HTML tags as simple instructions that tell the browser how to display different parts of your page.

Getting Started

1. HTML Document Structure

Imagine your HTML document as a storybook with a cover, chapters, and content. The code below is like the first page of your book, setting the stage for everything that follows.

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Your Page Title</title>
</head>

<body>
    <!-- Your content goes here -->
</body>

</html>
  • <!DOCTYPE html>: A declaration that says, "Hey browser, we're using the latest version of HTML!"

  • <html>: The main container for your entire webpage.

  • lang="en": Specifies that the language of your webpage is English.

  • <head>: This is like the backstage area. It holds important information about your webpage.

  • <body>: The main content of your webpage goes here.

2. Headings

Headings give your content structure, just like the headings in a book. <h1> is the biggest, and <h6> is the smallest.

<h1>This is a Heading 1</h1>
<h2>This is a Heading 2</h2>
<!-- ... -->
<h6>This is a Heading 6</h6>

Think of these as chapter titles. The bigger the number, the smaller and less important the heading.

Image description

3. Paragraphs

In HTML, a paragraph is like a block of text.

<p>This is a simple paragraph.</p>

This tag tells the browser that this group of words forms a distinct paragraph.

Image description

4. Lists

HTML supports two types of lists: ordered and unordered.

Unordered List (<ul> and <li>)

<ul>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
</ul>

Image description

This creates a bulleted list. <ul> stands for unordered list, and <li> represents each list item.

Ordered List (<ol> and <li>)

<ol>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
</ol>

Image description

This creates a numbered list. <ol> stands for ordered list, and <li> still represents each list item.

Links in HTML are like portals to other webpages.

<a href="https://www.example.com">Visit Example.com</a>

Here, <a> stands for anchor, and the href attribute is the address of the webpage you want to link to.

6. Images

Images can be displayed using the <img> tag.

<img src="image.jpg" alt="Description of the image">

<img> brings visuals into your webpage. src is the image source, and alt is a description in case the image doesn't load.

7. Divs: Division Containers

Think of <div> as a container that wraps around groups of content. It's like a box that helps organize and structure different parts of your webpage.

<div>
    <h2>Main Content</h2>
    <p>This is the main content of my webpage.</p>
</div>

<div>
    <h2>Side Content</h2>
    <p>This is some additional content on the side.</p>
</div>

In this example, we have two <div> containers, each holding a heading and a paragraph. Divs are often used to create distinct sections on a webpage.

8. Spans: Inline Containers

On the other hand, <span> is like a container for smaller, inline elements. It's used to apply styles or manipulate specific parts of text within a line.

<p>This is a <span style="color: blue;">blue</span> word in a sentence.</p>

Here, we've used a span to make the word "blue" appear in blue color. Spans are handy when you want to style or apply changes to a specific part of text.

9. Forms

Forms are like interactive sections where users can input information.

<form>
    <label for="username">Username:</label>
    <input type="text" id="username" name="username">

    <label for="password">Password:</label>
    <input type="password" id="password" name="password">

    <input type="submit" value="Submit">
</form>

Image description

In this snippet, users can enter a username and password, and when they click "Submit," the form does its magic.

10. Additional Form Input Types

In addition to text and password inputs, HTML supports various input types to handle different kinds of user input.

Checkboxes (<input type="checkbox">)

Checkboxes allow users to select multiple options.

<form>
    <label>
        <input type="checkbox" name="fruit" value="apple"> Apple
    </label>
    <label>
        <input type="checkbox" name="fruit" value="orange"> Orange
    </label>
    <label>
        <input type="checkbox" name="fruit" value="banana"> Banana
    </label>

    <input type="submit" value="Submit">
</form>

Image description

In this example, users can select multiple fruits.

Radio Buttons (<input type="radio">)

Radio buttons allow users to choose only one option from a set.

<form>
    <label>
        <input type="radio" name="gender" value="male"> Male
    </label>
    <label>
        <input type="radio" name="gender" value="female"> Female
    </label>
    <label>
        <input type="radio" name="gender" value="other"> Other
    </label>

    <input type="submit" value="Submit">
</form>

Here, users can choose their gender from the provided options.

Image description

Dropdown Menus (<select> and <option>)

Dropdown menus provide a list of options for users to choose from.

<form>
    <label for="country">Select your country:</label>
    <select id="country" name="country">
        <option value="usa">United States</option>
        <option value="canada">Canada</option>
        <option value="uk">United Kingdom</option>
        <!-- Add more options as needed -->
    </select>

    <input type="submit" value="Submit">
</form>

Image description

Users can pick their country from a dropdown list.

Text Areas (<textarea>)

Text areas allow users to input longer text, like comments or messages.

<form>
    <label for="message">Your message:</label>
    <textarea id="message" name="message" rows="4" cols="50" placeholder="Write your message here..."></textarea>

    <input type="submit" value="Submit">
</form>

Image description

This provides users with a larger space to write their messages.

These are just a few examples of the input types you can use in HTML forms. As you continue learning, you'll discover even more ways to collect and process user input on your webpages. Happy coding! 🚀

Putting It All Together

Now, let's modify our previous example to include div and span elements:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Your Page Title</title>
  </head>

  <body>
    <div>
      <h1>Welcome to My Webpage!</h1>
      <p>This is a simple webpage created with HTML.</p>
    </div>

    <div>
      <h2>Featured Section</h2>
      <img src="featured-image.jpg" alt="A beautiful featured image" />
      <p>Explore our amazing featured content!</p>
    </div>

    <div>
      <h2>Contact Us</h2>
      <p>
        Have questions? <a href="mailto:info@example.com">Email us</a> or use
        the form below:
      </p>
      <form>
        <label for="name">Name:</label>
        <input type="text" id="name" name="name" />

        <label for="email">Email:</label>
        <input type="email" id="email" name="email" />

        <label for="country">Select your country:</label>

        <select id="country" name="country">
          <option value="usa">United States</option>
          <option value="canada">Canada</option>
          <option value="uk">United Kingdom</option>
          <!-- Add more options as needed -->
        </select>

        <textarea
          id="message"
          name="message"
          placeholder="Your message"
        ></textarea>

        <input type="submit" value="Send Message" />
      </form>
    </div>

    <p>
      This webpage is brought to you by
      <span style="font-weight: bold">HTML</span>,
      <span style="font-style: italic">CSS</span>, and
      <span style="color: red">JavaScript</span>.
    </p>
  </body>
</html>

Image description

Tips for Effective Learning

  1. Hands-on Practice: Open a simple text editor and play around with these tags. See how changing things in the code affects the webpage.

  2. Online Resources: Explore beginner-friendly websites like MDN Web Docs or W3Schools for interactive lessons and examples.

  3. Join Communities: Platforms like Stack Overflow are great for asking questions and learning from experienced developers.

  4. Projects: Start small. Build a personal webpage or recreate a favorite webpage as a project.

  5. Stay Curious: Web development is a vast field. Don't be afraid to explore new tags and what they do.

Remember, the journey to becoming a frontend developer is an exciting one. HTML is just the beginning, and with each new tag you learn, you're adding a tool to your coding toolbox.

That's the scoop on HTML basics! In the next lesson, we'll spice things up with styling using CSS. Get ready to make your web pages look amazing! 🚀

Enjoy the process, and happy coding! 🚀

Stay Connected! For more insights into JavaScript and to join discussions with other developers, follow us on social media:

Twitter: @delia_code

Instagram: @delia.codes

Blog: https://delia.hashnode.dev/

Dev.to: https://dev.to/delia_code

Did you find this article valuable?

Support Delia's blog by becoming a sponsor. Any amount is appreciated!