In this lesson, we will explore HTML attributes and learn how to use them to enhance the functionality and behavior of HTML elements.
HTML attributes provide additional information or instructions to HTML elements. They are added as part of the HTML tags and consist of two parts: the attribute name and the attribute value. Attributes can be used to specify the appearance, behavior, or functionality of elements.
Let's look at an example:
SNIPPET
1<!DOCTYPE html>
2<html>
3<head>
4 <title>HTML Attributes</title>
5</head>
6<body>
7 <h1>Welcome to AlgoDaily!</h1>
8 <p>This is an example of an HTML attribute.</p>
9</body>
10</html>
In the example above, we have an HTML document with an
element and a element. The element has the attributeclass
with the value welcome-heading
, and the element has no attributes. The class
attribute is used to assign a CSS class to the element, which can be used for styling or JavaScript manipulation.HTML attributes can also be used for many other purposes, such as specifying links, handling events, input validation, and more. We will explore different types of attributes and their usage in the upcoming lessons.
xxxxxxxxxx
12
// Let's start by adding a simple HTML element with an attribute
<!DOCTYPE html>
<html>
<head>
<title>HTML Attributes</title>
</head>
<body>
<h1>Welcome to AlgoDaily!</h1>
<p>This is an example of an HTML attribute.</p>
</body>
</html>
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment