Welcome to this tutorial! Our goal is to dive deeper into the basic building blocks of HTML: elements and attributes. By the end of this tutorial, you should be able to:
There are no specific prerequisites for this tutorial, although a basic understanding of HTML would be beneficial.
HTML elements are the building blocks of HTML pages. An HTML element usually consists of a start tag, some content, and an end tag.
<tagname>Content goes here...</tagname>
For example, an HTML paragraph is defined using the <p>
element:
<p>This is a paragraph.</p>
HTML attributes provide additional information about an HTML element. Attributes are always specified in the start tag.
<tagname attribute="value">Content goes here...</tagname>
For example, you can use the lang
attribute in the <html>
tag to declare the language of the web page:
<html lang="en-US">
Let's take a look at some practical examples:
Here's a simple HTML document with a header and a paragraph:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Here's an HTML document with a link. The href
attribute in the <a>
element defines the link's destination:
<!DOCTYPE html>
<html>
<body>
<a href="https://www.example.com">This is a link</a>
</body>
</html>
When you click on "This is a link", it will take you to "https://www.example.com".
In this tutorial, we've covered the basics of HTML elements and attributes. We've learned how to use these building blocks to create simple HTML documents. For further learning, you could explore more complex HTML elements and attributes, and how they can be used to create more sophisticated web pages.
To help solidify your understanding, try out these exercises:
style
attribute to change the color of the header and the background color of one paragraph.Here are the solutions:
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
<p>My second paragraph.</p>
<a href="https://www.example.com">This is a link</a>
</body>
</html>
style
attribute to change the color of the header and the background color of one paragraph:<!DOCTYPE html>
<html>
<body>
<h1 style="color:blue;">My First Heading</h1>
<p style="background-color:yellow;">My first paragraph.</p>
<p>My second paragraph.</p>
<a href="https://www.example.com">This is a link</a>
</body>
</html>
Keep practicing and exploring different HTML elements and attributes!