Introduction
Attributes add extra information to HTML elements. Using them well helps your webpage work better and be easier to understand.
Attributes add extra information to HTML elements. Using them well helps your webpage work better and be easier to understand.
<element attribute="value">Content</element>
href attribute tells the link where to go.<a href="https://example.com">Visit site</a>
alt attribute describes the image for people who can't see it.<img src="photo.jpg" alt="A smiling person">
type attribute defines the button's behavior.<button type="submit">Send</button>
placeholder attribute shows a hint inside the input box.<input type="text" placeholder="Enter your name">
This webpage uses attributes to improve accessibility, usability, and structure. For example, alt describes the image, href sets the link, and aria-label helps screen readers.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Attribute Best Practices</title> </head> <body> <header> <h1 id="main-title">Welcome to My Website</h1> </header> <main> <section> <img src="https://via.placeholder.com/150" alt="Placeholder image" width="150" height="150"> <p>This is an example of using attributes properly.</p> <a href="https://example.com" target="_blank" rel="noopener noreferrer">Visit Example.com</a> </section> <form> <label for="name-input">Name:</label> <input type="text" id="name-input" name="name" placeholder="Enter your name" aria-label="Name input"> <button type="submit">Submit</button> </form> </main> <footer> <p>Ā© 2024 My Website</p> </footer> </body> </html>
Attributes add important details to HTML elements.
Use attributes to improve accessibility and user experience.
Always write attributes clearly and correctly with quotes and meaningful values.
<button disabled>Click me</button>
<a href=example.com target=_blank>Visit</a>
Pass the test and this pattern moves unknown