The Wayback Machine - https://web.archive.org/web/20240917170304/https://www.geeksforgeeks.org/html-elements/
Open In App

HTML Elements

Last Updated : 22 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

An HTML Element is a collection of start and end tags with the content inserted between them. HTML elements are building blocks of web pages, representing different types of content such as headings, paragraphs, links, and images.

What Are HTML Elements?

HTML (Hypertext Markup Language) is the backbone of web development. It allows us to create structured and interactive web pages. In this article, we’ll learn about the important aspects of HTML elements, their syntax, and best practices.

Syntax:

<tagname > Contents... </tagname>

Some key points about HTML elements

1. Syntax:

  • An opening tag indicates where the content begins: <tagname>.
  • A closing tag indicates where the content ends: </tagname>.
  • The actual content resides between the opening and closing tags.

2. Case Sensitivity:

  • HTML tags are not case-sensitive. For example, <B> and <b> both represent bold text.
  • However, it’s a best practice to use lowercase tags for consistency.

HTML Element

Descriptions

Opening tag(<tagname > )

It is used to tell the browser where the content material starts.

Closing tag(</tagname>)

It is used to tell the browser where the content material ends.

Content

It is the actual content material inside the opening and closing tags.

Combining all these 3 parts results in an overall HTML Element.

Group-3-2

Example 1: In this example <p> is a starting tag, </p> is an ending tag and it contains some content between the tags, which form an element

HTML
<!-- HTML code to illustrate HTML elements -->
<!DOCTYPE html>
<html>

<head>
    <title>HTML Elements</title>
</head>

<body>
    <p>Welcome to GeeksforGeeks!</p>
</body>

</html>

Output:

Screenshot-2023-07-14-115553

Nested HTML Elements

  • When an HTML element is used inside another, it’s called a nested element.
  • For instance, the <html> tag contains the <head> and <body> tags, forming a nested structure.

Example: This example describes the use of Nested HTML elements. Here, the <html> tag contains the <head> and <body>. The <head> and <body> tag contain other elements so it is called a nested element.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>HTML Elements</title>
</head>

<body style="text-align: center">
    <h1>GeeksforGeeks</h1>
    <p>Computer science portal</p>

</body>

</html>

Output:

Nested HTML element

Necessary to add an end Tag

It is important to include the closing tag of an HTML element in order to ensure that the content is displayed correctly. While it is recommended to add closing tags to non-void HTML elements, modern browsers are becoming more forgiving and will not throw an error if you forget to include them. However, this can cause issues when you add additional HTML elements later on. Therefore, it is best practice to always include the closing tag for non-void HTML elements.

Example 1: In this example, we will see the implementation of above tag.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>HTML Elements</title>
</head>

<body>
    <h2>Welcome To GeeksforGeeks</h2>
    
    <p>Hi Geeks!

</body>

</html>

Output: This Image is showing the Browser’s Developer Tools and you can see that the missing closing tag of the paragraph element in the above-written code is automatically added by the browser without showing any error.

add

HTML Empty Element

HTML Elements without any content i.e., that do not print anything are called Empty elements. Empty HTML elements do not have an ending tag. For instance. <br>, <hr>, <link>, <input> etc are HTML elements.

Example 2: In this example <br> tag doesn’t print anything. It is used as a line break that breaks the line between <h2> and <p> tags.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>Empty HTML Elements</title>
</head>

<body>
    <h2>Welcome To GfG</h2>
    <br />
    <p>Hello Geeks.</p>

</body>

</html>

Output:

HTML empty element

Supported Browsers

  • Google Chrome: 1
  • Microsoft Edge: 12
  • Mozilla Firefox: 1
  • Opera: 2
  • Safari: 1

HTML Elements – FAQs

What is an HTML element?

An HTML element consists of a start tag, content, and an end tag. For example, <p>Hello World</p> is a paragraph element.

What are self-closing tags?

Self-closing tags, also known as void elements, do not have content or an end tag. Examples include <br>, <img>, and <input />.

What are inline elements?

Inline elements do not start on a new line and only take up as much width as necessary. Examples include <span>, <a>, and <img>.

What is an empty element?

An empty element is one that has no content between its tags. Self-closing tags are examples of empty elements.

What is the <body> element?

The <body> element contains the contents of an HTML document, such as text, images, links, and other media.



Previous Article
Next Article

Similar Reads

HTML | DOM HTML Object
The HTML Object property in HTML DOM is used to represent or access the HTML &lt;html&gt; element with in the object. The &lt;html&gt; element is used to return the HTML document as an Element Object. Syntax: It is used to access a &lt;html&gt; element.var x = document.getElementsByTagName("HTML")[0]; It can also be used to access a &lt;html&gt; el
3 min read
HTML | &lt;html&gt; xmlns Attribute
The HTML &lt;html&gt; xmlns Attribute is used to specify the xml namespace for a document. Important Note: This attribute is mainly required in XHTML, not valid in HTML 4.01, and optional in HTML 5. Syntax: &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; Attribute Values: https://www.geeksforgeeks.org/ It defines the namespace to use (for XHTML d
1 min read
Inline HTML Helper - HTML Helpers in ASP.NET MVC
HTML Helpers are methods that returns HTML strings. These are used in the view. In simple terms, these are C# methods that are used to return HTML. Using HTML helpers you can render a text box, an area, image tag, etc. In MVC we have many built-in HTML helpers and we can create custom helpers too. Using HTML helpers a view can show model properties
2 min read
How to return HTML or build HTML using JavaScript ?
JavaScript is very powerful and with it, we can build dynamic web content and add many features to a web application. With HTML, we create the structure of the web page and the same thing can also be done with JavaScript. There are a few JavaScript methods called as createElement(), appendChild() with which we can add nodes to the DOM tree on the f
2 min read
How to convert html.slim to html.erb ?
Introduction to slim and erb: Slim files and tools are used to make the code more light and will help to use it instead of the particular code. erb is also used to do the similar but if you want to make the changes in the code then the user should be familiar with slim/erb respectively. If you have to convert an HTML Document into html.slim file th
1 min read
How to include HTML code snippets in HTML ?
In this article, we will learn how to include HTML snippets in HTML code. We will include the HTML code snippet of "gfg.html" into "index.html". To achieve this task, we are going to write a JavaScript function in "index.html" which traverses the collection of all HTML elements in "gfg.html" and searches for elements with specific attributes. It cr
3 min read
How to display HTML tags as plain text in HTML ?
In this article, we will learn how to display HTML tags as plain text in HTML. We can replace the plain text by using &lt; with   &amp;lt; or &amp;60; and &gt;   with  &amp;gt; or &amp;62; on each HTML tag. HTML Entities:Sign DescriptionEntity nameEntity number&lt;Less than(start of HTML element)&amp;lt;&lt;&gt;Greater than(end of HTML element)
2 min read
HTML Complete Guide – A to Z HTML Concepts
What is HTML ? HTML stands for Hypertext Markup Language. It is a standard markup language used to design the documents displayed in the browsers as a web page. This language is used to annotate (make notes for the computer) text so that a machine can understand it and manipulate text accordingly. Most markup languages (e.g. HTML) are human-readabl
7 min read
HTML Course Basics of HTML
In this article, we will go through all the basic stuff required to write HTML. There are various tags that we must consider and know about while starting to code in HTML. These tags help in the organization and basic formatting of elements in our script or web pages. These step-by-step procedures will guide you through the process of writing HTML.
5 min read
HTML Course Structure of an HTML Document
HTML(Hypertext Markup Language), structures web pages. Unlike programming languages, it isn't compiled or interpreted. Browsers render HTML directly, displaying content without typical errors. It's a markup language, not a programming one, making execution smooth without encountering compilation or interpretation issues. Table of Content HTML Docum
3 min read
What is the difference between &lt;html lang="en'&gt; and &lt;html lang="en-US'&gt; ?
The lang attribute specifies which language is used to write the content of a web page. It is used to set the language for the whole text of the web page. The &lt;html lang="en"&gt; specifies the language of the document as English, while &lt;html lang="en-US"&gt; narrows it down to English as used in the United States. Table of Content The &lt; ht
2 min read
HTML Code to JSON Converter App Using HTML, CSS, and JavaScript
HTML tables are a common way to represent structured data on web pages, but transforming this data into a JSON format can be troublesome. JSON is a lightweight data-interchange format that is easy for humans to read and write and for machines to parse and generate. We will be creating the HTML Code for the JSON Converter tool. The converter is desi
3 min read
HTML &lt;html&gt; Tag
HTML is a language full of diverse elements, and one such element is the &lt;html&gt; tag. This tag, standing for ‘HyperText Markup Language’, is used to define the root of an HTML or XHTML document. It serves as the main container for all other HTML elements, excluding the &lt;!DOCTYPE&gt; declaration. Understanding the &lt;html&gt; TagThe &lt;htm
3 min read
How to select all visible or hidden elements in a HTML page using jQuery ?
In order to select all visible or hidden elements in a page using jQuery, we can use the following jQuery selectors: :visible Selector The visible Selector is used to select all the elements that are currently visible in the document. Syntax: $(":visible") :hidden Selector The hidden selector selects hidden elements to work upon. Syntax: $(":hidden
2 min read
Elements that are used in head section of HTML page
The &lt;head&gt; element is like a container for metadata i.e. data about data and it also lies between the &lt;html&gt; tag and the &lt;body&gt; tag. Metadata is the data about the HTML document and is not displayed on the webpage. It defines the document title, style, script, and other meta information. The HTML &lt;head&gt; element is a containe
3 min read
How to groups related elements in a form using HTML ?
The &lt;fieldset&gt; tag in HTML5 is used to make a group of related elements in the form and it creates the box over the elements. The &lt;fieldset&gt; tag is new in HTML5. Syntax: &lt;fieldset&gt; Contents... &lt;/fieldset&gt; Attribute: disabled: It specify that the group of related form elements should be disabled.form: It specifies that one or
1 min read
Most efficient way to create HTML elements using jQuery
In this article, we will look at 4 jQuery techniques that can be used to create an HTML element, and we will be testing out the code for the creation of an element by different methods. Approach: One of the easier ways is to just use $ ('&lt;div&gt;&lt;/div&gt;') which is great for readability but technically the piece of code will create an &lt;di
3 min read
How to specify that a group of related form elements should be disabled using HTML?
In this article, we will learn how to specify that a group of related form elements should be disabled using HTML. When the disabled attribute is present, it specifies that the input field is disabled. We can not write any content in a disabled input field. Approach: We will be using the disabled attribute with the &lt;fieldset&gt; element. The dis
1 min read
HTML Text Formatting Elements
As we know, HTML provides many predefined elements that are used to change the formatting of text. The formatting can be used to set the text styles (like - bold, italic, or emphasized, etc.), highlight the text, make text superscript and subscript, etc. Text Formatting Elements: &lt;b&gt; and &lt;strong&gt; Tags: Both tags are used to make text bo
3 min read
ReactJS Blueprint HTML Elements Component
BlueprintJS is a React-based UI toolkit for the web. This library is very optimized and popular for building interfaces that are complex data-dense for desktop applications. HTML Elements Component provides a way for users to use the general HTML elements like heading, paragraph, etc tags. We can use the following approach in ReactJS to use the Rea
2 min read
How to set HTML meta elements with knitr ?
Sometimes you might want to generate some R code, or any other code without wrapping it up in a &lt;code&gt; tag, or maybe you want to specify some elements without the specific elements. Well, the thing you need at the moment is setting up the meta elements using knitr. Metadata means information about data. The &lt;meta&gt; tag in HTML provides i
2 min read
HTML DOM Form elements Collection
The Form element collection in HTML DOM is used to set or return the collection of all &lt;input&gt; elements inside a form element. The &lt;input&gt; elements are sorted as they appear in the source code. Syntax: formObject.elements Properties: It returns a number of input elements inside the &lt;form&gt; element. Methods: The DOM form elements co
2 min read
Which inline attribute is used to specify the styling of specific elements in HTML ?
In this article, we will discuss the inline attribute used to specify the styling of specific elements in HTML. Styles in HTML are basically rules that describe how a document will be presented in a browser. Style information can be either attached as a separate document or embedded in the HTML document. Inline Style: In Inline styling, the CSS rul
1 min read
What is the way to keep list of elements straight in HTML file ?
In this article, we will discuss various methods to keep the list of elements straight in an HTML file. Generally, The proper indented content in the browser makes the content well-organized &amp; structured, enhancing the overall readability, along with increasing the interactivity of the website. This could be possible by using the HTML semantic
6 min read
Which tag can be used as a container for the HTML elements ?
There are lots of tags that can be used as a container in HTML. These tags are generally divided into three parts, i.e., the opening tag, the content (which will display in the browser), and the closing tag. The content part can contain some other tags. The opening and closing tags are used in pairs. If you forget to close the container tag, the br
2 min read
Describe the void elements in HTML
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
3 min read
What are various heading elements used to add heading in HTML ?
An HTML heading tag is used to define the headings of a page. There are six levels of headings defined by HTML. These 6 heading elements are H1, H2, H3, H4, H5, and H6; with H1 being the highest level and H6 the least. In this article, we will discuss various heading elements used to add a heading in HTML. Syntax: &lt;h1&gt; Contents... &lt;/h1&gt;
2 min read
What is significance of declaring attribute in HTML elements ?
In this article, we will know HTML Attributes' significance while declaring and their implementation through the examples. All HTML elements have attributes that will provide additional information about that particular element. It takes 2 parameters, ie, a name &amp; a value which define the properties of the element and are placed inside the elem
2 min read
Is HTML elements are same as tags or not ?
HTML elements and tags are a lot different. Let's see what HTML elements and Tags actually are and their differences. The below image tells about HTML Elements and HTML Tags. HTML Tags: The starting and ending point parts of an HTML document are HTML Tags, which start with &lt; (less than) and end with &gt;(greater than) angle bracket, and whatever
2 min read
How to number HTML elements using CSS without lists ?
Sometimes we have to number the Headings, Paragraphs, Section Titles, Buttons, Cards, and many other elements for which lists are not an appropriate element tag. In this scenario, we can take the help of CSS counters. It is not a way to replace ordered or unordered in any sense lists. It is just that sometimes the lists are not appropriate tags to
5 min read