1.

What are semantic elements in HTML?

Answer»

Semantic elements are the TAGS which have both meaning to the browser and developer. In other words, semantic elements are the tags in plain English which says what it does.

EXAMPLE CONSIDER <div> and <span> which says nothing about what they do or what they are to a normal person. They are non-semantic elements.

On the other hand, elements like <form> and <table> tells what they are and do exactly the same thing. They are semantic elements.

Some of the Semantic elements with their brief descriptions are -

  • <article>- It specifies some content on the website. Used to wrap an article like a blog post on the SITE.
  • <section>- It specifies some section in article. An article can have many paragraphs and they should be wrapped in section tag.
  • <header>- It specifies the header section in the website. It is use to wrap the content, which will form the header for the site.
  • <footer>- It specifies the footer section of the website. Generally contains the contact us, copyright information.
  • <nav>- It is used to wrap all Navigation part of your website. All the navigation links should be put here.
  • <aside>- It is used to wrap all the content of the website, which will be in the sidebar. In most websites sidebar contains advertisements and aside can be used to wrap them.
  • <main>- It specifies the main content of the website. It will wrap all your articles and other section.
  • <figure>- It is used to wrap an image tag and convey the message that the following contains images. It is generally used with fig caption tag.
  • <figcaption>- It is used inside a figure tag along with image tag and is used to specify the caption.

Below is an example of a website created using semantic elements.

<!DOCTYPE html> <html> <style> nav{    background: yellow;    padding: 2%;    font-size:1.2rem; } footer{    background: yellow;    padding: 1%;    font-size:1rem; } main, header{ text-align: center; } </style> <body>    <nav>        <a href="https://en.wikipedia.org/wiki/Google_Chrome">Chrome</a> |        <a href="https://en.wikipedia.org/wiki/Firefox">Firefox</a> |        <a href="https://en.wikipedia.org/wiki/Safari_(web_browser)">Safari</a> |        <a href="https://en.wikipedia.org/wiki/Internet_Explorer">Internet Explorer</a>    </nav>    <header>        <h1>Web Browsers</h1>        <p>Google Chrome and Firefox are the most used browsers today.</p>        <hr>    </header>    <main>        <article>            <section>                <h1>Google Chrome</h1>                <p>Google Chrome is a free, open-source web browser developed by Google, released in 2008.</p>                <figure>                    <img src="https://source.unsplash.com/900x600/?nature" width="100%" alt="Nature">                    <figcaption>Random Nature image</figcaption>                </figure>            </section>            <section>                <h2>More Information</h2>                <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.                    Unde consequatur doloremque reiciendis saepe! Iure dicta                    harum molestias laborum accusantium reprehenderit                    SUNT, repudiandae eos aut itaque dolores et repellendus.                    Dignissimos, voluptate.                </p>                <hr>            </section>        </article>        <article>            <section>                <h1>Mozilla Firefox</h1>                <p>Firefox is a free, open-source web browser from Mozilla, released in 2004.</p>                <figure>                    <img src="https://source.unsplash.com/900x600/?water" width="100%" alt="Water">                    <figcaption>Random Water image.</figcaption>                </figure>            </section>            <section>                <h2>More Information</h2>                <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.                    Unde consequatur doloremque reiciendis saepe! Iure dicta                    harum molestias laborum accusantium reprehenderit                    sunt, repudiandae eos aut itaque dolores et repellendus.                    Dignissimos, voluptate.                </p>            </section>        </article>    </main>    <footer>        <p>Posted by: Sam Paul</p>        <p>Contact information: <a href="mailto:someone@example.com">                someone@example.com</a>.</p>    </footer> </body> </html>

Save the above code as demo.html and open in any browser.



Discussion

No Comment Found