Introduction
Attributes add extra information to HTML elements. They help control how elements behave or look.
Attributes add extra information to HTML elements. They help control how elements behave or look.
<element attribute="value">Content</element>
href attribute tells the link where to go.<a href="https://example.com">Visit site</a>
src attribute sets the image file, and alt describes it.<img src="photo.jpg" alt="A smiling dog">
type attribute defines the input field type, and placeholder shows a hint.<input type="text" placeholder="Enter your name">
This page uses attributes like id to name the heading, href and target to make the link open in a new tab, and src and alt for the image.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Attributes Example</title> </head> <body> <h1 id="main-title">Welcome!</h1> <a href="https://openai.com" target="_blank">Go to OpenAI</a> <br> <img src="https://via.placeholder.com/150" alt="Placeholder image"> </body> </html>
Always use quotes around attribute values.
Some attributes like disabled can work without a value.
Attributes help browsers and assistive tools understand your page better.
Attributes add details to HTML elements.
They are written inside the opening tag with a name and value.
Attributes control behavior, appearance, and accessibility.
<img src='flower.jpg' alt='A red flower'>
<a href='page.html' target='_blank>Visit page</a>
Pass the test and this pattern moves unknown