HTML Attributes

When you’re learning HTML, tags like <p> or <a> are your starting point—they tell the browser what to display. But what if you want to add more details, like where a link goes or how an image looks? That’s where HTML attributes come in. Think of them as extra instructions you give to your tags.

An attribute is always written inside the opening tag, and it follows a simple pattern: name="value". The name tells the tag what to do, and the value tells it how.

For example, in <a href="https://www.meripariksha.com">Click me</a>, href is the attribute name, and https://example.com is the value—it’s telling the link where to take you.

Here are some common attributes every beginner should know:

  1. href: Used with <a> tags to set the link destination.
  2. src: Tells <img> tags where to find the image file (e.g., <img src="photo.jpg">).
  3. alt: Adds a text description to images (great for accessibility).
  4. id: Gives a tag a unique name, like <div id="header">.
  5. class: Groups tags for styling, like <p class="intro">.

Let’s try a quick example:

<img src="dog.jpg" alt="A cute puppy" width="200">

Here, src loads the image, alt describes it, and width sets its size. Simple, right? Attributes don’t stand alone—they always pair with a tag to make it smarter.

As you practice, you’ll see attributes everywhere in HTML. They’re how you customize your code and make webpages do more than just sit there. Next time you’re building something, try tweaking a tag with an attribute and watch the magic happen!

How-To Guides for HTML

No How-To Guide is available right now.

Keep Learning & Level Up!

Enhance your HTML skills with our in-depth tutorials and interactive quizzes.

Explore HTML Quiz