Common HTML Attributes List – id, class, style, href, src Explained with Examples



 

Definition

HTML Attributes are special properties added inside HTML tags to provide extra information about elements. Attributes help control the behavior, appearance, and functionality of HTML elements. They are always written inside the opening tag.

Syntax

<tagname attribute="value">Content</tagname>

Common HTML Attributes

AttributeDescriptionExample
idGives a unique identity to an element

     <p id="para1">
classAssigns a class name for CSS or JavaScript

     <divclass="box">
hrefSpecifies the URL of a link

<a  href="http.com">
srcDefines the source of an image or media file

<img src="image.jpg">
altProvides alternative text for images

<img alt="flower">
titleAdds extra information as a tooltip

<p title="info">
styleApplies inline CSS styling

<h1 style="color:red;">
widthSets the width of an element

<img width="300">
heightSets the height of an element

<img height="200">
targetDefines where to open the linked document<a target="_blank">

Post a Comment

0 Comments