HTML Elements - Deep Dive

In this section, we will dive into the details of some of the most used html tags.

1. <!DOCTYPE html>

The <!DOCTYPE html> declaration is an important element at the beginning of an HTML document, and it is used to specify the document type and version of HTML being used. This declaration helps the browser understand how to interpret and render the HTML content that follows.

In the case of <!DOCTYPE html>, it indicates that the document is written in HTML5, the latest version of the Hypertext Markup Language. HTML5 is the fifth revision of the HTML standard, and it introduces new features and improvements over its predecessors.

Including the <!DOCTYPE html> declaration at the beginning of an HTML document is considered good practice because it ensures that browsers interpret the document in standards mode, providing a consistent rendering of the content across different browsers.

Here's a breakdown of the declaration:

  • <!DOCTYPE>: This is an SGML (Standard Generalized Markup Language) and XML (eXtensible Markup Language) declaration that signals the document type and version.

  • html: This specifies the root element of the document.

By including <!DOCTYPE html>, you're essentially telling the browser to expect HTML5 markup in the document. It helps ensure that the document is processed and rendered correctly by modern web browsers.

<!DOCTYPE html>

2. <html>

The <html> element is a fundamental building block of an HTML document. It serves as the root element and encapsulates the entire HTML content. All other HTML elements are nested within the <html> element. This is like telling the computer, "Hey, everything inside these tags is going to be part of my awesome website."

Here's a basic structure of an HTML document:

<!DOCTYPE html>
<html>
<head>
    <title>Your Page Title</title>
</head>
<body>
    <!-- Your HTML content goes here -->
</body>
</html>

Let's break down the structure:

  • <!DOCTYPE html>: As mentioned earlier, this declaration specifies the document type and version (HTML5, in this case).

  • <html>: This element marks the beginning of the HTML document. All the content of the HTML document is contained within the opening <html> tag and the closing </html> tag.

  • <head>: This section contains meta-information about the HTML document, such as the title, character set, linked stylesheets, and other metadata. The <head> element is not displayed on the web page itself.

  • <title>: This element, nested within the <head> section, sets the title of the HTML document. The title is typically displayed in the browser's title bar or tab.

  • <body>: This section contains the main content of the HTML document. All visible elements, such as text, images, links, and more, are placed within the opening <body> tag and the closing </body> tag.

3. <head>

The <head> element is a crucial part of an HTML document, and it typically contains meta-information, links to external resources, and other elements that provide information about the document itself. The <head> section is not displayed on the web page but plays a vital role in providing information to browsers and search engines.

Here's a breakdown of commonly used elements within the <head> section:

  • <title>: Sets the title of the HTML document, which is displayed in the browser's title bar or tab. It is also used by search engines to identify the page.

    <head>
        <title>Your Page Title</title>
    </head>
  • <meta>: This element is used to provide metadata about the HTML document, such as the character set, viewport settings, description, and keywords for search engines.

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="A brief description of your page">
        <meta name="keywords" content="keywords, associated, with, your, page">
    </head>
  • <link>: This element is used to link external resources, such as stylesheets (CSS files), scripts (JavaScript files), and icons.

    <head>
        <link rel="stylesheet" type="text/css" href="styles.css">
        <link rel="icon" href="favicon.ico" type="image/x-icon">
        <!-- Other links to external resources -->
    </head>
  • <script>: This element is used to embed or reference JavaScript code within the HTML document.

    <head>
        <script src="script.js"></script>
        <!-- Other script elements or inline scripts -->
    </head>

Don't forget also that the content of the <head> is meant for providing information about the document and optimizing its presentation and accessibility.

5. <body>

The <body> element in HTML contains the main content of a web page. Everything you see on a webpage, such as text, images, links, forms, and other visible elements, is placed within the <body> tags. Here's a basic structure of an HTML document with the <body> element:

<!DOCTYPE html>
<html>
<head>
    <title>Your Page Title</title>
</head>
<body>
    <!-- Your HTML content goes here -->

    <h1>This is a Heading</h1>
    <p>This is a paragraph of text.</p>
    <img src="example.jpg" alt="An example image">
    <a href="https://www.example.com">Visit Example.com</a>

    <!-- More HTML elements -->

</body>
</html>

In this example:

  • <body>: This is the opening tag of the body element, and it indicates the beginning of the main content of the HTML document.

  • <h1>: This is a heading element, and it represents the highest level of heading. Headings are used to structure the content of the page.

  • <p>: This is a paragraph element, and it is used to define paragraphs of text.

  • <img>: This is an image element, and it is used to embed images in the document.

  • <a>: This is an anchor (link) element, and it is used to create hyperlinks to other pages or resources on the web.

6. <h1> to <h6>

In HTML, the <h1> to <h6> elements are used to define headings with varying levels of importance and hierarchy. The <h1> element represents the highest level of heading, and <h6> represents the lowest level. Here's a brief overview:

  • <h1>: This is the highest level heading. It is typically used for the main title or heading of the entire page.

    <h1>Main Heading</h1>
  • <h2>: This is a second-level heading. It is used for subheadings or sections within the page.

    <h2>Subheading</h2>
  • <h3> to <h6>: These are third to sixth-level headings, respectively. They are used for further subsections, with <h6> being the least important.

    <h3>Sub-subheading</h3>
    <h4>Another level down</h4>
    <h5>Yet another level</h5>
    <h6>The least important heading</h6>

Headings not only define the structure of the content but also play a role in accessibility and search engine optimization. Search engines use heading tags to understand the structure and hierarchy of content on a page, and screen readers use them to provide context for users with visual impairments.

NOTE: When creating an HTML document, it's generally a good practice to use heading tags in a hierarchical order (e.g., <h1> for the main title, followed by <h2>, <h3>, etc., for subsections) to create a logical and well-structured document.

7. <p>

The <p> element in HTML is used to define paragraphs of text. It is a block-level element, which means it typically starts on a new line and takes up the full width available. Here's an example of how you can use the <p> element:

<p>This is a paragraph of text. It can contain <strong>strong</strong>, <em>emphasized</em>, and other inline elements.</p>

<p>Another paragraph goes here. You can separate paragraphs to organize your content.</p>

In this example:

  • <p>: This is the opening tag of the paragraph element.

  • </p>: This is the closing tag of the paragraph element.

  • Content between the opening and closing tags: This is the actual text of the paragraph.

You can include various HTML elements inside a <p> element to structure and style your text. For instance, <strong> is used for strong emphasis (often displayed as bold), and <em> is used for emphasized text (often displayed as italics).

<p>This is a <strong>strong</strong> paragraph with some <em>emphasized</em> text.</p>

The <p> element is commonly used to organize and separate blocks of text, making the content more readable and structured. It's part of the essential elements for creating the content and layout of a web page.

8. <a>

The <a> (anchor) element in HTML is used to create hyperlinks, allowing users to navigate to other web pages or resources. Here's the basic structure of an <a> element:

<a href="https://www.example.com">Link Text</a>

Explanation of the components:

  • <a>: This is the opening tag of the anchor element.

  • href="https://www.example.com": This attribute specifies the URL (Uniform Resource Locator) to which the link points. In this example, it's set to "https://www.example.com". The href attribute is a required attribute for the <a> element.

  • Link Text: This is the text that will be displayed as the clickable link. Users can click on this text to navigate to the specified URL.

  • </a>: This is the closing tag of the anchor element.

Here's another example with a relative URL:

<a href="/page2.html">Go to Page 2</a>

In this case, the link points to a page named "page2.html" in the same directory as the current page.

You can also create links to different sections within the same page using anchor links and the id attribute:

<a href="#section2">Go to Section 2</a>

In this example, you would need an element with id="section2" elsewhere in your document for the link to work correctly.

Note: The <a> element is a versatile and important part of HTML, enabling the creation of navigation within a website and linking to external resources on the internet.

9. <img>

The <img> (image) element in HTML is used to embed images into a web page. It does not have a closing tag, and it's a self-closing tag. Here's the basic structure of an <img> element:

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

Explanation of the attributes:

  • <img>: This is the opening tag of the image element.

  • src="image.jpg": The src attribute specifies the source URL (Uniform Resource Locator) of the image. This URL can be an absolute path or a relative path to the image file.

  • alt="Description of the image": The alt attribute provides alternative text for the image. It is displayed if the image cannot be loaded or for accessibility purposes, where screen readers use it to describe the content of the image to users with visual impairments.

Here's an example with a relative path:

<img src="images/myimage.jpg" alt="A beautiful landscape">

And an example with an absolute path:

<img src="https://www.example.com/images/myimage.jpg" alt="A beautiful landscape">

It's important to provide meaningful and descriptive alternative text using the alt attribute for accessibility and SEO (Search Engine Optimization) purposes. Additionally, you can use other attributes, such as width and height, to specify the dimensions of the image.

<img src="image.jpg" alt="Description of the image" width="300" height="200">

Including appropriate attributes ensures that your images are displayed correctly and that your web page is accessible to a wide range of users.


10. <ul>, <ol>, <li>

In HTML, the <ul>, <ol>, and <li> elements are used to create lists. Let's break down each of these elements:

  1. <ul> (Unordered List):

The <ul> element is used to create an unordered list, where the order of items doesn't matter. Typically, unordered lists are displayed with bullet points.

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

In this example, each <li> (list item) element represents an item in the unordered list.

  1. <ol> (Ordered List):

The <ol> element is used to create an ordered list, where the order of items is important. Ordered lists are displayed with numbers or other ordered markers.

<ol>
  <li>First item</li>
  <li>Second item</li>
  <li>Third item</li>
</ol>

Similar to <ul>, each <li> element represents an item in the ordered list.

  1. <li> (List Item):

The <li> element is used to define each item in a list, whether it's an unordered list (<ul>) or an ordered list (<ol>). It is a child element of both <ul> and <ol>.

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

<ol>
  <li>First item</li>
  <li>Second item</li>
  <li>Third item</li>
</ol>

In the examples above, <li> is used to define individual items in both the unordered and ordered lists.

These list elements (<ul>, <ol>, and <li>) are essential for structuring content on a webpage, especially when presenting information in a list format. They help improve readability and provide a clear structure to the content.

11. <div>

The <div> element in HTML is a generic container that is used to group together and apply styling or layout to a collection of other HTML elements. It stands for "division" or "divider" and is a block-level element. The <div> element itself does not have any specific visual representation; its purpose is to help organize and structure the content of a web page.

Here's an example of how the <div> element is commonly used:

<div>
  <h2>Section Title</h2>
  <p>This is some content within the section.</p>
  <ul>
    <li>Item 1</li>
    <li>Item 2</li>
  </ul>
</div>

<div>
  <h2>Another Section Title</h2>
  <p>More content in another section.</p>
  <ol>
    <li>First item</li>
    <li>Second item</li>
  </ol>
</div>

In this example, two <div> elements are used to group together and contain various other HTML elements, including headings (<h2>), paragraphs (<p>), unordered lists (<ul>), and ordered lists (<ol>). The use of <div> allows you to apply styling, such as CSS rules, to the grouped content or structure your page for layout purposes.

12. <span>

This is like a small container, unlike <div> which is big. It's used for styling a small piece of text or content.

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

13. <header>

This is like the heading of a page or a section. It often contains important information like the title of the website.

<header>
  <h1>Welcome to My Website</h1>
</header>

14. <nav>

This is like the navigation menu in a book. It's a place where you put links to help people move around your website easily.

<nav>
  <a href="#home">Home</a>
  <a href="#about">About</a>
  <a href="#contact">Contact</a>
</nav>

15. <main>

This is like the main part of your webpage. It holds the most important content.

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

16. <article>

This is like a story or a blog post. It's a container for a piece of content that could stand on its own.

<article>
  <h2>My Awesome Blog Post</h2>
  <p>This is the content of my blog post.</p>
</article>

17. <section>

This is like a big chapter in a book. It helps group related content together.

<section>
  <h2>Chapter One</h2>
  <p>This is the first part of my story.</p>
</section>

18. <aside>

This is like a sidebar in a newspaper. It contains content that is related to the main content but not the main focus.

<aside>
  <p>Check out these related links:</p>
  <a href="#link1">Link 1</a>
  <a href="#link2">Link 2</a>
</aside>

Certainly! Let's continue with the explanations for the next set of HTML elements:

This is like the end of a book where you find information about the author or some final thoughts. In a webpage, it's the bottom part with details or links.

<footer>
  <p>&copy; 2023 My Awesome Website</p>
</footer>

20. <br>

This is like hitting "Enter" on your keyboard. It creates a line break, so the text or content after it appears on a new line.

<p>This is some text.<br>And this is on a new line.</p>

21. <hr>

This is like drawing a horizontal line on your page. It's a visual break, like separating sections.

<p>This is one section of text.</p>
<hr>
<p>This is another section of text.</p>

22. <strong>

This is like making a word bold and strong. It emphasizes that the word is important.

<p>This is <strong>bold</strong> text.</p>

23. <em>

This is like making a word italic and a bit emphasized. It adds a touch of emphasis to the text.

<p>This is <em>italic</em> text.</p>

24. <blockquote>

Imagine this as a fancy way of quoting someone. It's used to highlight a longer piece of text as a quote.

<blockquote>
  <p>This is a quote from someone important.</p>
</blockquote>

25. <q>

Similar to <blockquote>, but for shorter quotes. It's like putting quotation marks around a small piece of text.

<p>Someone once said <q>HTML is fun!</q></p>

26. <cite>

This is like giving credit to someone. It's often used to mention the name of the person or book from where a quote comes.

<blockquote>
  <p>This is a quote.<cite>— Famous Person</cite></p>
</blockquote>

27. <abbr>

This is like a shortcut or an abbreviation. It helps explain the meaning of a shortened word when you hover over it.

<p>HTML stands for <abbr title="Hypertext Markup Language">HTML</abbr>.</p>

28. <address>

This is like telling people how to contact you. It's often used for putting contact information in the footer.

<address>
  Contact me at <a href="mailto:info@example.com">info@example.com</a>
</address>

29. <pre>

This is like writing code or text where spaces and line breaks matter. It preserves the formatting you put in.

<pre>
  This is some
  preformatted text.
</pre>

30. <code>

This is like highlighting a small piece of code. It's used to show that this is a piece of computer code.

<p>To make text bold, use <code>&lt;strong&gt;</code>.</p>

31. <table>

This is like creating a table, just like you have in your notebook. It helps organize information in rows and columns.

<table>
  <tr>
    <td>Row 1, Cell 1</td>
    <td>Row 1, Cell 2</td>
  </tr>
</table>

32. <tr>

This is like a row in a table. It holds different pieces of information side by side.

<tr>
  <td>Row 1, Cell 1</td>
  <td>Row 1, Cell 2</td>
</tr>

33. <td>

This is like a cell in a table. It's where you put specific information.

<tr>
  <td>Row 1, Cell 1</td>
  <td>Row 1, Cell 2</td>
</tr>

35. <th>

This is like a special cell in a table that usually holds the header, like the title of a column.

<table>
  <tr>
    <th>Header 1</th>
    <th>Header 2</th>
  </tr>
  <tr>
    <td>Row 1, Cell 1</td>
    <td>Row 1, Cell 2</td>
  </tr>
</table>

36. <thead>

This is like the top part of a table that usually contains the headers.

<thead>
  <tr>
    <th>Header 1</th>
    <th>Header 2</th>
  </tr>
</thead>

37. <tbody>

This is like the main part of a table, where the regular rows go.

<tbody>
  <tr>
    <td>Row 1, Cell 1</td>
    <

Certainly! Let's continue explaining the next set of HTML elements:

This is like the end of your webpage, just like the end of a book where you find information about the author or more links.

<footer>
  <p>&copy; 2023 My Awesome Website</p>
</footer>

39. <br>

This is like pressing "Enter" on your keyboard. It creates a line break, moving the next content to a new line.

<p>This is some text.<br>And this is on a new line.</p>

40. <hr>

This is like drawing a horizontal line on your page. It's a way to separate content.

<p>This is some text.</p>
<hr>
<p>This is more text, separated by a line.</p>

41. <strong>

This is like making text bold, emphasizing its importance.

<p>This is <strong>important</strong> information.</p>

42. <em>

This is like making text italic, adding emphasis or a different tone.

<p>This is <em>special</em> information.</p>

43. <q>

This is like quoting someone too, but for shorter quotes.

<p><q>This is a short quote.</q></p>

44. <cite>

This is like giving credit. It's used to show the name of the person or work you're quoting.

<p><cite>John Doe</cite> said something wise.</p>

45. <abbr>

This is like shortening a word, and you can hover over it to see the full word.

<p><abbr title="World Health Organization">WHO</abbr> is important.</p>

46. <address>

This is like giving the address, often used for contact information.

<address>
  Contact us at: <a href="mailto:info@example.com">info@example.com</a>
</address>

47. <pre>

This is like a space where text keeps its formatting, good for showing code.

<pre>
  This   is   some
  preformatted   text.
</pre>

48. <form>

This is like a container for things like text boxes and buttons. It's used to collect information from people.

<form action="/submit" method="post">
  <!-- Your form elements go here -->
</form>

49. <input>

This is like a text box or a button in a form. People can type into it or click it.

<input type="text" placeholder="Type something">
<input type="submit" value

="Click me">

50. <label>

This is like a label for a form element. It helps people understand what they should do.

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

51. <textarea>

This is like a bigger text box for longer messages.

<textarea rows="4" cols="50">Write your message here.</textarea>

52. <button>

This is like a clickable button. You can use it to submit a form or trigger some action.

<button type="button">Click me</button>

53. <select>

This is like a dropdown menu. You can pick from a list.

<select>
  <option value="option1">Option 1</option>
  <option value="option2">Option 2</option>
</select>

54. <option>

This is like an option in a dropdown menu.

<select>
  <option value="option1">Option 1</option>
  <option value="option2">Option 2</option>
</select>

55. <optgroup>

This is like grouping options in a dropdown menu.

<select>
  <optgroup label="Group 1">
    <option value="option1">Option 1</option>
    <option value="option2">Option 2</option>
  </optgroup>
</select>

56. <fieldset>

This is like a container for a group of related form elements.

<fieldset>
  <legend>Personal Information</legend>
  <!-- Your form elements go here -->
</fieldset>

57. <legend>

This is like the title for a group of related form elements.

<fieldset>
  <legend>Personal Information</legend>
  <!-- Your form elements go here -->
</fieldset>

58. <datalist>

This is like a list of options for a text box. It helps people by suggesting possible values.

<input list="browsers" name="browser" id="browser">
<datalist id="browsers">
  <option value="Chrome">
  <option value="Firefox">
  <option value="Safari">
</datalist>

59. <progress>

This is like a progress bar. It shows how far along a process is.

<progress value="50" max="100"></progress>

60. <details>

This is like a container that can be opened to show more information.

<details>
  <summary>Click to see more</summary>
  <p>This is extra information.</p>
</details>

61. <summary>

This is like the title for the content inside a <details> element.

<details>
  <summary>Click to see more</summary>
  <p>This is extra information.</p>
</details>

62. <dialog>

This is like a popup box. It shows important information or asks for confirmation.

<dialog open>
  <p>This is a popup box.</p>
  <button>Close</button>
</dialog>

63. <script>

This is like giving your webpage special powers. It lets you add interactivity or make things happen.

<script>
  alert('Hello, World!');
</script>

64. <noscript>

This is like a backup plan for when the special powers in <script> can't be used. It shows something else.

<noscript>
  <p>Sorry, but you need to enable JavaScript to use this website.</p>
</noscript>

65. <style>

This is like telling your webpage how to look. It's for adding styles or making things pretty.

<style>
  body {
    background-color: lightblue;
  }
</style>

66. <meta>

This is like telling the computer more information about your webpage, like the character set or keywords.

<meta charset="UTF-8">
<meta name="keywords" content="HTML, CSS, JavaScript">

67. <bdo>

This is like flipping or changing the direction of text.

<bdo dir="rtl">This text is right-to-left.</bdo>

68. <del>

This is like showing that some text has been deleted or removed.

<p>This is <del>old</del> text.</p>

69. <ins>

This is like showing that some text has been added or inserted.

<p>This is <ins>new</ins> text.</p>

70. <object>

This is like embedding another document or media into your webpage.

<object data="document.pdf" type="application/pdf">
  <p>Download the PDF <a href="document.pdf">here</a>.</p>
</object>

71. <param>

This is like providing parameters or settings for an embedded object.

<object>
  <param name="autoplay" value="true">
  <param name="loop" value="true">
</object>

72.<video>

Imagine the <video> tag as a magical window on your webpage that can show moving pictures and sound. It's like having a little TV screen right on your website where you can play videos.

<video width="400" height="300" controls>
  <source src="movie.mp4" type="video/mp4">
  Your browser does not support the video tag.
</video>

Explanation:

  • <video>: This is the tag that says, "Hey, I'm going to show a video here!"

  • width and height: These make the video window a specific size.

  • controls: This adds play, pause, and volume controls so visitors can interact with the video.

  • <source>: This is like telling the browser where to find the video file.

  • src: This is the actual video file, like "movie.mp4."

  • type: This tells the browser what type of video file it is (in this case, MP4).

  • The text inside the <video> tag ("Your browser does not support the video tag.") is a message that shows up if the browser can't play the video.

Last updated