Basic structure and Semantic Elements of HTML with examples (2024)

The world of web development might seem intimidating, but fear not! We’ll start by understanding the fundamental structure of webpages, built with the versatile language: HTML (Hypertext Markup Language). Think of HTML as the skeleton of your webpage, providing the framework for all the visual elements and content.

The Big Three: The Core Elements of Every Webpage

Let’s meet the essential trio that forms the foundation of every webpage:

  1. <html>: This is the granddaddy of them all! The <html> tag acts as the root element, encompassing everything that makes up your webpage. It’s like the master container holding all the other elements within.
  2. <head>: This element is the brains behind the beauty. It holds crucial information about your webpage, but it’s not directly displayed for users. Here, you’ll find the document type declaration, title of the page, character encoding for proper display, and links to external resources like stylesheets. These stylesheets define the visual appearance of your webpage, like fonts and colors.
  3. <body>: Now, this is where the magic happens! The <body> element is the heart and soul of your webpage, containing everything users see in their browser window. This is where you place your content – headings, paragraphs, images, links, and more. It’s like the stage where all the visual storytelling unfolds.

Here’s an example of the basic structure of an HTML document, with explanations to avoid plagiarism from any other sources:

Basic structure of HTML examples:

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>My First Web Page</title>
</head>
<body>
  <h1>Welcome to my page!</h1>
  <p>This is my first attempt at creating a web page. It's exciting to learn how HTML works.</p>
</body>
</html>

Explanation:

  1. DOCTYPE declaration (<!DOCTYPE html>): This line tells the web browser what type of document it’s dealing with (in this case, HTML).
  2. HTML element (<html>...</html>): This is the root element of the document and contains everything else. It also optionally includes a lang attribute to specify the document’s language (here, “en” for English).
  3. Head element (<head>...</head>): This section contains meta information about the document, but it’s not directly displayed on the webpage.
    • Meta charset (<meta charset="UTF-8">): This specifies the character encoding used in the document, ensuring proper display of characters. UTF-8 is a common encoding that supports a wide range of languages.
    • Title element (<title>...</title>): This defines the title of the webpage, which appears in the browser’s title bar and search results.
  4. Body element (<body>...</body>): This section contains the content that will be displayed on the webpage. Here, we have:
    • Heading 1 (<h1>): This creates a large heading for the page. You can use <h2> to <h6> for smaller subheadings.
    • Paragraph (<p>...</p>): This defines a block of text on the webpage.

Remember:

  • Every opening tag (<tag>) must have a closing tag (</tag>) in the correct order to ensure proper document structure.
  • This is a basic example. HTML has many more tags for creating more complex and interactive webpages.

Semantic Elements of HTML for Better Structure and Accessibility

Beyond the core trio, HTML offers powerful tools called semantic elements. These elements go beyond just presentation and tell the browser (and assistive technologies like screen readers) the purpose of each section. This enhances organization, readability, and accessibility for everyone.

Here are some key semantic elements you’ll encounter:

  1. <header>: This element marks the introductory section of your webpage, typically containing the logo, navigation bar, and any introductory text.
  2. <nav>: Imagine a roadmap – the <nav> element defines a dedicated section specifically for navigational links. This is where you’ll build your main menu, guiding users through the different parts of your webpage.
  3. <main>: This holds the crown jewel of your content. The <main> element signifies the core content of your webpage, the information users are primarily seeking. There should only be one <main> element per page, ensuring a clear focus on the most important content.
  4. <footer>: Think of the <footer> element as the closing act of your webpage. It’s often used for copyright information, contact details, or other supplementary content that complements the main content.

Semantic Elements of HTML with examples

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>News Article</title>
</head>
<body>
  <header>
    <h1>Breaking News!</h1>
  </header>
  <nav>
    <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">World</a></li>
      <li><a href="#">Tech</a></li>
    </ul>
  </nav>
  <main>
    <article>
      <h2>Scientists Discover New Planet</h2>
      <p>A team of astronomers has discovered a new planet orbiting a distant star. The planet, which is roughly twice the size of Earth, is located in the habitable zone of its solar system, meaning it could potentially support liquid water on its surface.</p>
      <figure>
        <img src="planet.jpg" alt="Image of the newly discovered planet">
        <figcaption>An artist's impression of the new planet.</figcaption>
      </figure>
      <p>This discovery is significant because it increases the possibility of finding life outside of Earth. Scientists are eager to learn more about this new planet and its potential to harbor life.</p>
    </article>
  </main>
  <aside>
    <h2>Weather Forecast</h2>
    <p>Sunny skies with a high of 75 degrees Fahrenheit.</p>
  </aside>
  <footer>
    <p>&copy; 2024 My News Website</p>
  </footer>
</body>
</html>

Explanation:

  • header: This element identifies the top section of the webpage, typically containing the logo, title, or other introductory content.
  • nav: This element defines the main navigation section for the webpage, allowing users to easily jump to different parts of the site.
  • main: This element indicates the core content of the document, in this case, the news article.
  • article: This element represents a self-contained piece of content, like a news story, blog post, or forum topic.
  • figure: This element groups an image or other visual content with its caption (figcaption).
  • aside: This element defines content that is related to the main content but can be presented separately, like a sidebar containing weather information.
  • footer: This element specifies the footer section of the webpage, often containing copyright information or other secondary links.

By using semantic elements, we create a more meaningful structure for both humans and search engines. This makes the webpage easier to understand, navigate, and index.

Visit it for next step to learn 2024’s Beginner-Friendly Roadmap: 10 Key Areas in Mastering HTML.

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertisment

Latest posts

Unlocking the Power of AI Agents with Microsoft 365 Copilot

AI agents are rapidly becoming indispensable in enterprises. However, businesses today seek tools that deliver measurable results, align with specific use cases, and are...

WhatsApp Communities update Tab with Redesigned Interface for Easier Navigation

This WhatsApp Communities update tab offers a user-focused perspective on the recent improvements to the messaging app's navigation. The enhancements prioritize usability by allowing...

Google Brings AI-Generated Image generator to Google Docs

Google has introduced a powerful AI-driven image generator to Google Docs, powered by its advanced Gemini technology. This feature allows users to create high-quality...