Attributes
HTML attributes are data that can be added to the opening tag of an HTML element. These attributes modify the default behavior of the element or provide additional information about it.
Attributes consist of a name and are usually set equal to a value. Values are enclosed in double or single quotation marks.
Syntax
The syntax for adding attributes to an HTML element is as follows:
<tagname attribute="value"></tagname>
Note: Attribute names are not case-sensitive, but it is good practice to write HTML markup in lowercase.
Examples
Image Attributes
Using an <img>
element, which is commonly used to display images, reveals several attributes, such as src
, width
, and height
. These attributes exert significant influence over the manner in which the image appears on the web page. The dimensions of the particular element, once specified, enable precise control over the end result.
<img src="source_of_image.png" width="500" height="600" />
disabled
Attribute
The disabled
attribute is applied to form elements like buttons and inputs to make them nonfunctional:
<button disabled>Submit</button>
This is the output of the above code snippet:
Attributes
- class
- An HTML attribute used to select one or more elements for the application of styling or logic.
- dir
- Sets the direction of the text of an HTML element.
- id
- Used to specify a unique id for an HTML element, which cannot be shared across multiple elements within the same HTML document.
- src
- Specifies the location of a digital source.
- style
- Specifies how an element will be rendered in a web browser.
- title
- Contains and can display the specified information about the element it belongs to.
All contributors
- christian.dinh2476 total contributions
- danieldo191 total contribution
- elliezub2 total contributions
- Anonymous contributorAnonymous contributor95 total contributions
- hughlilly3 total contributions
- Anonymous contributorAnonymous contributor3071 total contributions
- christian.dinh
- danieldo19
- elliezub
- Anonymous contributor
- hughlilly
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.