DEV Community

Ragul
Ragul

Posted on

HTML Attributes

HTML attributes are special features used to provide additional information about HTML elements. They modify the behavior of the element or define its characteristics.

Example
1.The src attribute specifies the source or location of the image. Similarly, the href attribute in the tag defines the destination of the link.

<img src="profile.jpg" alt="Profile">
Enter fullscreen mode Exit fullscreen mode
<a href="https://www.dev.to">Click here to visit Dev Community</a>
Enter fullscreen mode Exit fullscreen mode

2.The <input> tag, used for creating forms. Its type attribute defines what kind of input it is, like text, password, or checkbox. The placeholder attribute shows a hint inside the field before the user types anything.

<input type="text" placeholder="full name">

<input type="password" placeholder="password">

<input type="checkbox" id="terms">
<label for="terms">I agree to the terms and conditions</label>
Enter fullscreen mode Exit fullscreen mode

4.The <form> tag itself, used to collect user data. It has an action attribute that points to where the data should be sent, and a method attribute to decide how the data is sent, usually GET or POST.

<form action="/submit-login" method="POST">
  <input type="text" placeholder="Username">
  <input type="password" placeholder="Password">
  <button type="submit">Login</button>
</form>
Enter fullscreen mode Exit fullscreen mode

3.Global attributes like class and id can be added to almost any tag. class is used to style multiple elements with CSS, while id is used to uniquely identify a single element for scripting or linking.

<h1 id="main-title">Welcome to My Site</h1>

<p class="highlight-text">This is an important paragraph.</p>
<p class="highlight-text">This is another important paragraph.</p>

<div id="sidebar" class="layout-box highlight-text">
  Sidebar content goes here.
</div>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)