DEV Community

Cover image for what is HTML element with example..
Ravi  kumar
Ravi kumar

Posted on • Edited on

what is HTML element with example..

HTML elements are the building blocks of HTML documents. They are used to structure the content of a webpage and to add meaning and semantics to the content.

An HTML element is represented by a pair of tags, an opening tag and a closing tag, with the content of the element appearing between the two tags. For example:

<p>This is a paragraph.</p>

Enter fullscreen mode Exit fullscreen mode

In this example, the p element represents a paragraph and the content of the paragraph, "This is a paragraph," appears between the opening

tag and the closing

tag.

There are many different types of HTML elements, including elements for headings, paragraphs, lists, links, images, and more.

Here is an example of an HTML document with a variety of different elements:

<!DOCTYPE html>
<html>
<head>
  <title>My Website</title>
</head>
<body>
  <h1>Welcome to My Website</h1>
  <p>This is my personal website where I share my interests and hobbies.</p>
  <h2>About Me</h2>
  <p>I am a programmer and avid reader. I enjoy hiking and spending time with my family.</p>
  <h2>My Hobbies</h2>
  <ul>
    <li>Reading</li>
    <li>Hiking</li>
    <li>Programming</li>
  </ul>
  <h2>Contact Me</h2>
  <p>You can reach me at <a href="mailto:me@example.com">me@example.com</a>.</p>
</body>
</html>

Enter fullscreen mode Exit fullscreen mode

In this example, the html, head, title, body, h1, p, h2, ul, and li elements are all used to structure the content and add meaning to the webpage. The a element is used to create a hyperlink.

Top comments (0)