HTML – Attributes

  • HTML attributes provide additional information about an element.
  • Attributes are always placed in the start tag of an element.
  • Each attribute consists of a name and a value, defining specific properties.
HTML Code

🚀 Try it yourself! Click the button below to run the code and see the output in action.

HTML Code

Output

Some Core HTML Attributes

  • id – Unique identifier for an HTML element.
  • title – Specifies a title or tooltip for an HTML element.
  • href – Specifies the URL of the page the link
  • class – Specifies one or more class names for an HTML element.
  • style – Specifies inline CSS styles for an HTML element.
  • lang – Specifies the language of the content inside an HTML
  • height – Used to set the height
  • width – Use to set the width
  • alt – Used to set the alternative text of the image

Understanding Core HTML Attributes with Fun! 😃

Think of HTML attributes as the secret ingredients that add extra flavor to your webpage! 🍕 Just like a pizza needs toppings to be delicious, HTML elements need attributes to be more useful. Let’s explore them in a fun way!

  • The id attribute is like your name – it’s unique and helps identify you in a crowd. Similarly, id=”section” helps select a specific element in CSS or JavaScript.
  • The title attribute is like a whispered secret – when you hover over an element, it tells you more information in a little tooltip!
  • The href attribute acts like Google Maps – it helps links take you to different places on the internet.
  • The class attribute is like a team jersey! –Players wearing the same jersey belong to the same team. Likewise, elements with the same class share the same styles!
  • The alt attribute is your backup plan – if an image doesn’t load, the alt text describes it for users (or screen readers for accessibility).

Important Note: Want to download the full course as a PDF? Click here to save it locally!

2 thoughts on “Attributes”

Leave a Comment