HTML Attributes
What Is It?
An attribute adds information to an HTML tag. Write it inside the opening tag.
What the Tags Mean
href: a link’s destination.id: a unique name for an element.title: extra information, often shown on hover.
Example 1
Save each example as index.html and open it in your browser. Each code block is a complete page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Attributes</title>
</head>
<body>
<a href="#contact">Contact details</a>
<h2 id="contact">Contact us</h2>
</body>
</html>Browser preview
What you see: Clicking Contact details jumps to the heading with id="contact".
Example 2: Another Use
Use attributes to give an input a starting value.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Attributes</title>
</head>
<body>
<label for="name">Name</label>
<input id="name" value="Asha">
</body>
</html>Browser preview
Simple Tip
Quote attribute values, for example value="Asha".
Try It Yourself
Change the starting name in the input.