HTML 002: Attributes

Neha
GigaGuardian
Published in
2 min readDec 22, 2022
ImageSource

Introduction

HTML attributes provide additional information about an HTML element. They are specified within the opening tag of an element, and are typically used to provide the element with specific characteristics or behavior.

For example, the `href` attribute is used to define the link destination for an anchor element (`<a>`), and the `src` attribute is used to define the source of an image for an image element (`<img>`).

Here are some examples of common HTML attributes and their code:

  • `href`: Specifies the URL or link destination for an anchor element (`<a>`).
<a href="http://www.example.com">This is a link</a>
  • `src`: Specifies the source of an image for an image element (`<img>`).
<img src="http://www.example.com/image.jpg" alt="This is an image">
  • `alt`: Specifies alternative text that describes the contents of an image, which can be used by screen readers or if the image is not able to be displayed.
<img src="http://www.example.com/image.jpg" alt="This is an image">
  • `id`: Specifies a unique identifier for an HTML element, which can be used to target the element with CSS or JavaScript.
<p id="unique-p">This paragraph has a unique id.</p>
  • `class`: Specifies one or more class names for an HTML element, which can be used to apply styles to the element using CSS.
<p class="special-p">This paragraph has a special class.</p>
  • `name`: Specifies the name of an input field in a form, which can be used to identify the element when the form is submitted.
  • `type`: Specifies the type of an input field in a form, such as a text field, radio button, or checkbox.
  • `value`: Specifies the default value of an input field in a form.
<form action="http://www.example.com/form-handler" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<input type="submit" value="Submit">
</form>

I hope you enjoyed this introduction to HTML Attributes!

Follow me: LinkedIn, Twitter

--

--