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.Thesrcattribute specifies the source or location of the image. Similarly, thehrefattribute in the tag defines the destination of the link.
<img src="profile.jpg" alt="Profile">
<a href="https://www.dev.to">Click here to visit Dev Community</a>
2.The
<input>tag, used for creating forms. Itstypeattribute defines what kind of input it is, like text, password, or checkbox. Theplaceholderattribute 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>
4.The
<form>tag itself, used to collect user data. It has anactionattribute that points to where the data should be sent, and amethodattribute to decide how the data is sent, usuallyGETorPOST.
<form action="/submit-login" method="POST">
<input type="text" placeholder="Username">
<input type="password" placeholder="Password">
<button type="submit">Login</button>
</form>
3.Global attributes like
classandidcan be added to almost any tag.classis used to style multiple elements with CSS, whileidis 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>
Top comments (0)