[properties] What is the difference between attribute and property?

These seem to mean the same thing. But what term is more appropriate in what context?

This question is related to properties modeling

The answer is


Delphi used properties and they have found their way into .NET (because it has the same architect).

In Delphi they are often used in combination with runtime type information such that the integrated property editor can be used to set the property in designtime.

Properties are not always related to fields. They can be functions that possible have side effects (but of course that is very bad design).


<property attribute="attributeValue">proopertyValue</property>

would be one way to look at it.

In C#

[Attribute]
public class Entity
{
    private int Property{get; set;};

What is the difference between Attribute and Property?
What is the difference between Feature and Function? What is the difference between Characteristic and Character? What is the difference between Act and Behavior?

Its just a change in context.

Object,Product,Personality,Person

A Person Acts in a Behavior. A Personality has Characteristics of a given Character. A Product has Feature that derive Functionality. An Object had Attributes that give it Properties.


The precise meaning of these terms is going to depend a lot on what language/system/universe you are talking about.

In HTML/XML, an attribute is the part of a tag with an equals sign and a value, and property doesn't mean anything, for example.

So we need more information about what domain you're discussing.


These words existed way before Computer Science came around.

  1. Attribute is a quality or object that we attribute to someone or something. For example, the scepter is an attribute of power and statehood.

  2. Property is a quality that exists without any attribution. For example, clay has adhesive qualities; i.e, a property of clay is its adhesive quality. Another example: one of the properties of metals is electrical conductivity. Properties demonstrate themselves through physical phenomena without the need to attribute them to someone or something. By the same token, saying that someone has masculine attributes is self-evident. In effect, you could say that a property is owned by someone or something.

To be fair though, in Computer Science these two words, at least for the most part, can be used interchangeably - but then again programmers usually don't hold degrees in English Literature and do not write or care much about grammar books :).


In general terms (and in normal English usage) the terms mean the same thing.

In the specific context of HTML / Javascript the terms get confused because the HTML representation of a DOM element has attributes (that being the term used in XML for the key/value pairs contained within a tag) but when represented as a JavaScript object those attributes appear as object properties.

To further confuse things, changes to the properties will typically update the attributes.

For example, changing the element.href property will update the href attribute on the element, and that'll be reflected in a call to element.getAttribute('href').

However if you subsequently read that property, it will have been normalised to an absolute URL, even though the attribute might be a relative URL!


An attribute is the actual thing that you use within your HTML tag like

<input type="checkbox" checked="checked" />

In this instance type and checked are attributes. The property though is the value of these attributes, which the browser saves inside the DOM element. Often the value of the attributes and the properties are equal, that's what makes it so confusing.

In this example the DOM element input has the property type with the value "checkbox" and the property checked with the value true (notice how this value differs from the value inside the HTML attribute).

Using Firebug you can observe the behaviour of properties when clicking on an element and selecting the "DOM view".


The precise meaning of these terms is going to depend a lot on what language/system/universe you are talking about.

In HTML/XML, an attribute is the part of a tag with an equals sign and a value, and property doesn't mean anything, for example.

So we need more information about what domain you're discussing.


In HTML it seems attributes are specific to the DOM tree while properties are used to describe the characteristics of DOM elements


<property attribute="attributeValue">proopertyValue</property>

would be one way to look at it.

In C#

[Attribute]
public class Entity
{
    private int Property{get; set;};

Delphi used properties and they have found their way into .NET (because it has the same architect).

In Delphi they are often used in combination with runtime type information such that the integrated property editor can be used to set the property in designtime.

Properties are not always related to fields. They can be functions that possible have side effects (but of course that is very bad design).


In Python...

class X( object ):
    def __init__( self ):
        self.attribute
    def getAttr( self ):
        return self.attribute
    def setAttr( self, value ):
        self.attribute= value
    property_name= property( getAttr, setAttr )

A property is a single attribute-like name that wraps a collection of setter, getter (and deleter) functions.

An attribute is usually a single object within another object.

Having said that, however, Python gives you methods like __getattr__ which allow you extend the definition of "attribute".

Bottom Line - they're almost synonymous. Python makes a technical distinction in how they're implemented.


These words existed way before Computer Science came around.

  1. Attribute is a quality or object that we attribute to someone or something. For example, the scepter is an attribute of power and statehood.

  2. Property is a quality that exists without any attribution. For example, clay has adhesive qualities; i.e, a property of clay is its adhesive quality. Another example: one of the properties of metals is electrical conductivity. Properties demonstrate themselves through physical phenomena without the need to attribute them to someone or something. By the same token, saying that someone has masculine attributes is self-evident. In effect, you could say that a property is owned by someone or something.

To be fair though, in Computer Science these two words, at least for the most part, can be used interchangeably - but then again programmers usually don't hold degrees in English Literature and do not write or care much about grammar books :).


The precise meaning of these terms is going to depend a lot on what language/system/universe you are talking about.

In HTML/XML, an attribute is the part of a tag with an equals sign and a value, and property doesn't mean anything, for example.

So we need more information about what domain you're discussing.


In Python...

class X( object ):
    def __init__( self ):
        self.attribute
    def getAttr( self ):
        return self.attribute
    def setAttr( self, value ):
        self.attribute= value
    property_name= property( getAttr, setAttr )

A property is a single attribute-like name that wraps a collection of setter, getter (and deleter) functions.

An attribute is usually a single object within another object.

Having said that, however, Python gives you methods like __getattr__ which allow you extend the definition of "attribute".

Bottom Line - they're almost synonymous. Python makes a technical distinction in how they're implemented.


In Java (or other languages), using Property/Attribute depends on usage:

  • Property used when value doesn't change very often (usually used at startup or for environment variable)

  • Attributes is a value (object child) of an Element (object) which can change very often/all the time and be or not persistent


Often an attribute is used to describe the mechanism or real-world thing.

A property is used to describe the model.

For instance, a document (sitting on your desk) may have the attribute that it is a draft.

The class that models documents has a property to indicate whether or not it's a draft. In this case the property captures the state.


What is the difference between Attribute and Property?
What is the difference between Feature and Function? What is the difference between Characteristic and Character? What is the difference between Act and Behavior?

Its just a change in context.

Object,Product,Personality,Person

A Person Acts in a Behavior. A Personality has Characteristics of a given Character. A Product has Feature that derive Functionality. An Object had Attributes that give it Properties.


In Python...

class X( object ):
    def __init__( self ):
        self.attribute
    def getAttr( self ):
        return self.attribute
    def setAttr( self, value ):
        self.attribute= value
    property_name= property( getAttr, setAttr )

A property is a single attribute-like name that wraps a collection of setter, getter (and deleter) functions.

An attribute is usually a single object within another object.

Having said that, however, Python gives you methods like __getattr__ which allow you extend the definition of "attribute".

Bottom Line - they're almost synonymous. Python makes a technical distinction in how they're implemented.


An attribute is the actual thing that you use within your HTML tag like

<input type="checkbox" checked="checked" />

In this instance type and checked are attributes. The property though is the value of these attributes, which the browser saves inside the DOM element. Often the value of the attributes and the properties are equal, that's what makes it so confusing.

In this example the DOM element input has the property type with the value "checkbox" and the property checked with the value true (notice how this value differs from the value inside the HTML attribute).

Using Firebug you can observe the behaviour of properties when clicking on an element and selecting the "DOM view".


Often an attribute is used to describe the mechanism or real-world thing.

A property is used to describe the model.

For instance, a document (sitting on your desk) may have the attribute that it is a draft.

The class that models documents has a property to indicate whether or not it's a draft. In this case the property captures the state.


<property attribute="attributeValue">proopertyValue</property>

would be one way to look at it.

In C#

[Attribute]
public class Entity
{
    private int Property{get; set;};

The precise meaning of these terms is going to depend a lot on what language/system/universe you are talking about.

In HTML/XML, an attribute is the part of a tag with an equals sign and a value, and property doesn't mean anything, for example.

So we need more information about what domain you're discussing.


Delphi used properties and they have found their way into .NET (because it has the same architect).

In Delphi they are often used in combination with runtime type information such that the integrated property editor can be used to set the property in designtime.

Properties are not always related to fields. They can be functions that possible have side effects (but of course that is very bad design).


<property attribute="attributeValue">proopertyValue</property>

would be one way to look at it.

In C#

[Attribute]
public class Entity
{
    private int Property{get; set;};

In HTML it seems attributes are specific to the DOM tree while properties are used to describe the characteristics of DOM elements


In Python...

class X( object ):
    def __init__( self ):
        self.attribute
    def getAttr( self ):
        return self.attribute
    def setAttr( self, value ):
        self.attribute= value
    property_name= property( getAttr, setAttr )

A property is a single attribute-like name that wraps a collection of setter, getter (and deleter) functions.

An attribute is usually a single object within another object.

Having said that, however, Python gives you methods like __getattr__ which allow you extend the definition of "attribute".

Bottom Line - they're almost synonymous. Python makes a technical distinction in how they're implemented.


In Java (or other languages), using Property/Attribute depends on usage:

  • Property used when value doesn't change very often (usually used at startup or for environment variable)

  • Attributes is a value (object child) of an Element (object) which can change very often/all the time and be or not persistent