Altcademy - a Forbes magazine logo Best Coding Bootcamp 2023

What are Tags in HTML?

Welcome to the world of programming! If you're just starting out, you might be feeling a bit overwhelmed with all the new terms and concepts. Don't worry! In this post, we're going to break down one of the foundational elements of web development: HTML tags. By the end of this article, you'll have a better understanding of what tags are, how they work, and how to use them to create a simple web page.

What is HTML?

Before we dive into tags, let's take a moment to understand what HTML is. HTML stands for HyperText Markup Language. It's a language used to structure and display content on the web. Think of it as the skeleton of a web page. Other languages, like CSS and JavaScript, add style and functionality to the page, but HTML is where it all begins.

What are Tags?

Now that we've got a basic understanding of HTML, let's talk about tags. Tags are the building blocks of HTML. They're used to define the structure and content of a web page.

Imagine you're writing a letter, and you want to label certain parts of the letter, like the date, the recipient, and the body of the letter. You might use brackets and labels to do this, like so:

[date]
[recipient]
[body]

HTML tags work in a similar way. They're used to label and organize the content of a web page. Tags are enclosed in angle brackets, like this: <tagname>. Most tags have an opening tag and a closing tag, with the content in between. The closing tag has a forward slash before the tag name, like this: </tagname>.

Here's an example of a simple HTML structure with tags:

<!DOCTYPE html>
<html>
  <head>
    <title>My First Web Page</title>
  </head>
  <body>
    <h1>Welcome to my website!</h1>
    <p>This is a paragraph of text.</p>
  </body>
</html>

In this example, you can see several different tags, such as <html>, <head>, <title>, <body>, <h1>, and <p>. Each of these tags serves a specific purpose in the structure of the web page.

Common HTML Tags

Let's take a closer look at some common HTML tags and what they're used for:

<!DOCTYPE html>: This isn't a tag, per se, but it's important to include at the very beginning of your HTML file. It tells the browser that the file is an HTML5 document.

<html>: This is the root element of an HTML page. All other tags should be nested within the opening and closing <html> tags.

<head>: This tag contains metadata about the document, such as the title of the page, character encoding, and links to stylesheets or scripts.

<title>: This tag sets the title of the web page, which is displayed in the browser's title bar or tab.

<body>: The <body> tag defines the main content of the web page. Everything that you want to display on the web page should be placed between the opening and closing <body> tags.

<h1> to <h6>: These tags represent headings, with <h1> being the largest and <h6> being the smallest. They're used to organize content and make it easier to read.

<p>: This tag is used for paragraphs of text.

<a>: The anchor tag is used to create links to other web pages or resources. The href attribute is used to specify the target of the link. For example: <a href="https://www.example.com">Visit Example.com</a>.

<img>: This tag is used to embed images on a web page. The src attribute is used to specify the source (URL) of the image file. For example: <img src="image.jpg" alt="A description of the image">.

<ul> and <ol>: These tags are used to create unordered (bulleted) and ordered (numbered) lists, respectively. The <li> tag is used to define each list item.

Here's an example of a web page that uses some of these common tags:

<!DOCTYPE html>
<html>
  <head>
    <title>My Favorite Foods</title>
  </head>
  <body>
    <h1>My Top 3 Favorite Foods</h1>
    <ol>
      <li>Pizza</li>
      <li>Tacos</li>
      <li>Ice Cream</li>
    </ol>
    <p>Click <a href="https://www.example.com">here</a> to learn more about my favorite foods!</p>
  </body>
</html>

In this example, we've used an ordered list (<ol>) with list items (<li>) to display our favorite foods. We've also included a paragraph (<p>) with a link (<a>).

Conclusion

HTML tags are the foundation of web development. By understanding how tags work and how to use them, you're well on your way to creating your own web pages. Remember, practice is key when it comes to learning any new skill, so keep experimenting with different tags and building upon your knowledge. Happy coding!