Difference Between Property and Attribute in HTML and CSS

By: Rajat Kumar | Last Updated: May 07, 2023


In this article we can learn about some basic concept of HTML and CSS with some difference attributes and properties. In HTML and CSS, a property is a specific aspect of an HTML element that you can change to alter its appearance or behavior, such as its color, font, width, height, etc. An attribute is a piece of information about an element, such as the src attribute of an image, the href attribute of a link, or the value attribute of a form input.

In HTML and CSS, the terms "property" and "attribute" are often used interchangeably to refer to the styles that are applied to HTML elements. However, there is a difference between the two terms in the context of HTML and CSS.


What is Attribute?

An attribute is a characteristic of an HTML element that is used to define its properties or functions. For example, the "class" and "id" attributes in HTML can be used to define styles in CSS.


The syntax for setting an attribute in CSS is:

selector[attribute="value"] {
 /* styles */


In HTML, you might write:

<img src="image.jpg" alt="A description of the image">

Here, src and alt are attributes.



What is Property?

A property is a stylistic aspect of an HTML element that can be controlled through CSS. For example, the "color" and "background-color" properties can be used to change the text and background colors of an HTML element, respectively.


The syntax for setting a property in CSS is:

selector {
 property: value;


For example, in CSS you might write:

p {
 color: blue;
 font-size: 14px;

Here, color and font-size are properties.



In summary, an attribute provides information about the HTML element, while a property controls the appearance of the element. In CSS, properties and attributes are two different things: Properties refer to the values that are used to define the visual style of an HTML element, such as its color, font-size, width, height, and so on. Attributes, on the other hand, are used to provide additional information about an HTML element, such as its ID, class, or data-* attributes.