HTML - <section> Tag



The HTML <section> tag is used to represent the generic standalone section for the HTML document. The sections should always have a heading, with very few exceptions.

As we mentioned above the section element is a general sectioning element, so it should only be used if there are no more specific elements present.

For example, a navigation menu should be wrapped in a <nav> tag, but a list of search results or a map display and its controls don't have any specific elements, and these all can be placed in a section.

Syntax

Following is the syntax of the <section> tag −

<section>.....</section>

Example

The following program shows the usage the HTML <section> tag.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML section tag</title>
</head>
<body>
   <p>Example of the HTML 'section' element</p>
   <!--create a section element-->
   <section>
      <h2>HTML</h2>
      <p>Hyper Text Markup Language</p>
   </section>
</body>
</html>

When we run the above code, it will generate an output consisting of the text displayed on the webpage.

Example

Consider the following example, where we are going to use the <section> tag and applying the CSS properties.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML section tag</title>
   <style>
      section {
         width: 300px;
         height: 100px;
         background-color: blueviolet;
         color: white;
         border-radius: 10px;
      }
      section>h2,
      p {
         margin: 20px 10px;
      }
   </style>
</head>
<body>
   <p>Example of the HTML 'section' element</p>
   <!--create a section element-->
   <section>
      <h2>HTML</h2>
      <p>The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser</p>
   </section>
</body>
</html>

On running the above code, the output window will pop up, consisting of the text along with a CSS applied to it is displayed on the webpage.

Example

Let's look into the another scenario, where we are going to create a multiple section.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML section tag</title>
   <style>
      section {
         width: 300px;
         height: 100px;
         background-color: rgb(94, 16, 168);
         color: white;
         border-radius: 10px;
      }

      section>h2,
      p {
         margin: 20px 10px;
      }
   </style>
</head>
<body>
   <p>Example of the HTML 'section' element</p>
   <!--create a section element-->
   <section>
      <h2>HTML(section1)</h2>
      <p>HyperText Markup Language.</p>
   </section>
   <section>
      <h2>CSS(section2)</h2>
      <p>Cascading Style Sheet</p>
   </section>
   <section>
      <h2>JS(section3)</h2>
      <p>JavaScript</p>
   </section>
</body>
</html>

When we run the above code, it will generate an output displaying the different sections text along with the CSS applied on the webpage.

Example

In the following example, we are going to use the section with the button and the anchor link.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML section tag</title>
   <style>
      section {
         width: 300px;
         height: 100px;
         background-color: rgb(6, 164, 30);
         color: white;
         border-radius: 10px;
      }
      section>h2,
      p {
         margin: 20px 10px;
      }
   </style>
</head>
<body>
   <!--create section element-->
   <section>
      <h1>Links section</h1>
      <a href="">Home</a>
      <a href="">About</a>
      <a href="">ContantUs</a>
   </section>
   <section>
      <h1>Buttons section</h1>
      <button>Create</button>
      <button>View</button>
      <button>Delete</button>
   </section>
</body>
</html>

When we run the above code, it will generate an output displaying the buttons and the links on the webpage.

html_tags_reference.htm
Advertisements