The Wayback Machine - https://web.archive.org/web/20240814152440/https://www.geeksforgeeks.org/describe-the-void-elements-in-html/
Open In App

Describe the void elements in HTML

Last Updated : 15 May, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Most of the HTML elements are surrounded by start and end tags to specify the starting and end of the element.

There is a special group of elements that only have start tags and does not contain any content within it, these elements are called void elements. Void elements doesn’t have ending tags and can only have attributes but do not contain any kind of content. These elements can have backslash before ending of start tag but that is completely optional. Example of such elements are <br>, <hr>, <img>, <input>, <link>, <base>, <meta>, <param>, <area>, <embed>, <col>, <track>, <source> etc.

Characteristics:

  • Void elements do not have end tags.
  • Void elements cannot have content inside it.
  • Void elements have attributes.
  • Void elements cannot be nested.

The following are some of the void elements.

HTML <br> tag: This tag is used to insert line breaks in text in HTML. It accepts clear attribute that indicates where to start the next line.

Example 1: In this example, we will use of the <br> tag.

HTML




<!DOCTYPE html>
<html>
  
<body>
    <h2 style="color:green">GeeksforGeeks</h2>    
    <p>Hi Geeks! <br>Welcome to GeeksforGeeks</p>
  
</body>
</html>


Output:

HTML <hr> Tag: This tag is used to insert a horizontal rule in HTML documents to separate different document sections. It can have attributes like Align, no shade, width, size.

Example 2: In this example, we will see the use of the <hr> tag.

HTML




<!DOCTYPE html>
<html>
<body>       
    <p>Welcome to GeeksforGeeks</p>
    <hr>        
    <p>A computer science portal for geeks</p>
  
</body>    
</html>                    


Output:

<hr> tag

HTML <img> Tag: This tag is used to add images to HTML web pages. It can have attributes like src, alt, height, width, ismap, loading, etc.

Example 3: In this example, we will see the use of the <img> tag.

HTML




<!DOCTYPE html>
  
<html>
<body>        
    <h2 style="color:green">GeeksforGeeks</h2>
    <img src= 
         width="320" height="100" alt="Geeksforgeeks.org" >
</body>    
</html>                    


Output:

HTML <input> Tag: This tag is used to insert an input field that can accept different types of inputs based on the value of the type attribute. It can also have attributes like name, alt, placeholder, etc.

Example 4: In this example, we will see the use of the <input> tag.

HTML




<!DOCTYPE html>
<html>
  
<body>
  <h2 style="color:green">GeeksforGeeks</h2>
  <input type="text" placeholder="Enter name...">    
</body>
</html>


Output:

HTML <link> Tag: This tag is used to define a link between an HTML document and an external resource. It can have attributes like rel, charset, disabled, href, etc.

Example 5: In this example, we will see the use of the <link> tag.

HTML




<!DOCTYPE html>
<html>
  
<head>
   <link rel="stylesheet" 
         type="text/css"
         href="style.css">
</head>
  
<body>
   <h2>GeeksforGeeks</h2>
</body>
</html>


CSS




h2
{
    color: green;
}


Output:

HTML <base> Tag: This tag is used to specify a base URL (that will be added at the start) for all the links present on that page. There can only be 1 base URL on a single page.

Example 6: In this example, we will see the use of the <base> tag.

HTML




<!DOCTYPE html>
<html>
<head>
    <base href=
          target="_blank"/>
  
</head>
  
<body>
    <img src="G-100x34.PNG" 
         width="150px" 
         height="150px">
</body>
</html>


Output:

<base> tag

HTML <meta> Tag: This is used to specify information about HTML web pages that are used by search engines. It can have attributes like name, content, charset, etc.

Example 7: In this example, we will see the use of the <meta> tag.

HTML




<!DOCTYPE html>
<html>
<head>
    <meta name="description" content=
      "A Computer Science portal for geeks. 
       It contains well written, well thought 
       and well explained computer science and 
       programming articles, quizzes and practice/competitive
       programming/company interview Questions.">
</head>
  
<body>
    <h2 style="color:green">GeeksforGeeks</h2>
    <p>A computer science portal for geeks</p>
  
</body>
</html>


Output:



Similar Reads

What is void and when to use void type in JavaScript ?
In this article, we will know what is void operator in Javascript, along with discussing the particular condition where void operator can be used &amp; understanding their implementation through the examples. The void keyword in JavaScript, is used to evaluate an expression which does not return any value. The void operator is an unary operator tha
5 min read
Describe the purpose of using alt attribute in &lt;img&gt; tag in HTML
The &lt;img&gt; alt attribute is used to specify the alternate text for an image. It is useful when the image is not displayed. It is used to give alternative information for an image. It is also very much helpful in the Google ranking of your page. In this article, we will discuss the alt attribute in the &lt;img&gt; tag. Syntax: &lt;img alt="text
1 min read
Explain the concept of URL Encoding & Describe the need for encoding in HTML
The URL (Uniform Resource Locator) is used to identify an internet resource on the WWW (World Wide Web). The below example demonstrates a URL. https://www.en.com:443/path/filename?r=1#fragment This URL contains: A protocol or scheme (https://)A domain prefix(sub-domain) (www.)A domain (en)A top-level domain (.com)A port (:443)A filepath (/path)A fi
3 min read
ES6 Void Keyword
The void keyword in JavaScript ES6 is used to evaluate an expression and it does not return any value. It is a unary operator and takes a single operand. We commonly use it in hyperlinks. Sometimes, we may need to call some JavaScript from a link. When we click on a link, the browser loads a new page or refreshes the same page. But we don't want th
2 min read
Which href value should we use for JavaScript links, "#" or "javascript:void(0)" ?
In this article, we will know which "href" should be used for JavaScript when we can use "#" or "javascript:void(0)". Let us understand it. Using the '#' value: The # is a fragment identifier used to refer to a specific section of the same document. When a user clicks a link with a # href, the browser will scroll to that section of the page specifi
3 min read
What is the use of the Void Operator in JavaScript ?
The void operator in JavaScript is like a special command that tells the computer to do something but not worry about what comes back. It's often used when you want to make a clickable link on a website that doesn't take you to a new page. Instead of saying "go nowhere," you use 'void(0)' in the link, and it makes sure nothing happens, keeping thin
1 min read
What does javascript:void(0) mean?
In JavaScript, javascript:void(0) is a pseudo-URL that does nothing when clicked. It's commonly used as a placeholder in href attributes to prevent the browser from navigating to a new page while still executing JavaScript code. Using "#" in an anchor tagWhen writing the following code in the editor, the web page is refreshed after the alert messag
1 min read
TypeScript Return type void
The void type in TypeScript represents the absence of a return value for functions. It indicates that a function does not return any value, ensuring that the function's purpose is solely to act without returning data. Syntaxfunction functionName(parameters: ParameterType): void { // Function body // No return statement or return type annotation is
3 min read
TypeScript void Function
Void functions in TypeScript are functions that do not return a value. They perform actions or computations without producing a result that needs to be captured. Commonly used for side effects like logging, modifying external state, or triggering asynchronous operations, they enhance code clarity. Syntax: function functionName(parameters: Parameter
3 min read
Describe PHP Include and Require
In this article, we will see what include() &amp; the require() functions is, also will know how these functions affect the execution of the code, their differences &amp; usage in PHP, along with understanding their implementation through the examples. As we know PHP allows us to create various functions and various elements that are used multiple
3 min read
three90RightbarBannerImg