Table of contents | |
Introduction | |
What are HTML Tags? | |
Anatomy of an HTML Tag | |
HTML Tag Examples | |
Nesting Tags | |
Sample Problems and Solutions |
HTML (Hypertext Markup Language) is the backbone of web development. It provides a way to structure and format content on the web. One of the fundamental elements of HTML is tags. Tags are used to define the structure and semantics of a web page. In this article, we'll explore tags in HTML, their usage, and provide simple code examples to help beginners understand their significance.
HTML tags are elements used to mark up the content within an HTML document. Tags provide structure and meaning to the content and tell web browsers how to display and interpret the information. Each HTML tag is surrounded by angle brackets (<>) and comes in pairs: an opening tag and a closing tag.
An HTML tag consists of the following components:
Let's explore some commonly used HTML tags with their code examples, output, and explanations:
Heading tags ('<h1>' to '<h6>') are used to define headings and subheadings on a webpage. The number represents the importance and hierarchy of the heading, with <h1> being the highest and <h6> being the lowest.
<h1>This is a Heading</h1>
Output:
This is a Heading
Paragraph tags ('<p>') are used to define paragraphs of text on a webpage.
<p>This is a paragraph.</p>
Output:
This is a paragraph.
Link tags ('<a>') are used to create hyperlinks that navigate to another webpage or a specific location within the same page.
<a href="https://www.example.com">Visit Example Website</a>
Output:
Visit Example Website
Image tags ('<img>') are used to insert images into a webpage.
<img src="https://edurev.gumlet.io/mage.jpg" alt="Description of the image">
Output:
(The actual image will be displayed in the webpage)
HTML tags can be nested within each other to create more complex structures. It's important to ensure proper opening and closing tag pairs to maintain the integrity of the HTML structure.
<div>
<h2>Welcome to My Website</h2>
<p>This is a paragraph with a <a href="https://www.example.com">link</a>.</p>
</div>
Output:
Welcome to My Website
This is a paragraph with a link.
Problem 1: Create a webpage with two headings and a paragraph.
<!DOCTYPE html>
<html>
<head>
<title>Sample Webpage</title>
</head>
<body>
<h1>Welcome</h1>
<h2>About Us</h2>
<p>This is a sample paragraph about our company.</p>
</body>
</html>
Problem 2: Create a webpage with an image and a link to another webpage.
<!DOCTYPE html>
<html>
<head>
<title>Sample Webpage</title>
</head>
<body>
<img src="https://edurev.gumlet.io/mage.jpg" alt="Image Description">
<a href="https://www.example.com">Visit Example Website</a>
</body>
</html>
HTML tags are the building blocks of web development. By understanding their purpose and usage, you can create well-structured and visually appealing webpages. In this article, we covered the basics of HTML tags, including their anatomy, examples, and nesting. As you continue your journey in web development, keep exploring different HTML tags and their applications to enhance your webpages.
20 videos|15 docs|2 tests
|
|
Explore Courses for Software Development exam
|