What's the difference between element value and data attribute ? Last Updated : 01 Jun, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The element value attribute specifies the default value of the HTML element whereas the data attribute allows you to store extra data to tags in HTML when no other HTML attribute can do so. Element value: The HTML element is the collection of start and end tags with the content inserted in between them. Example: In this example, we will use element value. HTML <!DOCTYPE html> <html> <body> <label>Website: </label> <input type=“text” value="GeeksForGeeks"/> </body> </html> Output: Element value Data Attribute: Data Attributes allow you to add your own information to tags in HTML. Even though the name suggests otherwise, these are not specific to HTML5 Example: In this example, we will use data attributes. HTML <!DOCTYPE html> <html> <head> <script> function showDetails(vehicle) { let vehiclePrice = vehicle.getAttribute("data-vehicle-price"); alert(vehicle.innerHTML + " is of cost " + vehiclePrice + "."); } </script> <style> h1 { color: green; } li { margin-top: 5px; cursor: pointer; } </style> </head> <body> <h1>Vehicle</h1> <p>Click on a vehicle to see how much it Cost:</p> <ul> <li onclick="showDetails(this)" id="Bike" data-vehicle-price="Rs. 80,000"> Bike </li> <li onclick="showDetails(this)" id="Car" data-vehicle-price="Rs. 7,00,000 "> Car </li> <li onclick="showDetails(this)" id="Truck" data-vehicle-price="Rs. 3,00,000 "> Truck </li> </ul> </body> </html> Output: Element ValueData Attribute The element value can be implemented using HTML elements <input>, <button>,<meter>,<li>,<option>,<progress>and <param> elements only. The data attribute can be used with all HTML elements. It is used differently for different elements. For example, the <button>,<input> elements values specifies the initial value of the element. For <param> elements, the value attribute specifies the value of the parameter. It is used to define custom data attributes and to store custom data, private to the page or application.For element value, we don't need to give any name to it. The value must be a string.The attribute name cannot have any uppercase letters, and must be at least one character long and the prefix with 'data-'. Comment More infoAdvertise with us Next Article Difference between Data and Metadata A archnabhardwaj Follow Improve Article Tags : Web Technologies HTML HTML-Tags HTML-Attributes HTML-Questions +1 More Similar Reads What is the difference between properties and attributes in HTML? HTML is the standard language for creating documents that are intended to be displayed on web browsers. It is very usual to get confused with attributes and properties while performing DOM object manipulation in JavaScript. Before learning about the differences, let us first define the Document Obje 4 min read Difference between Data and Metadata The term 'data' may also refer to various forms such i.e. numbers, text, images, or audio that provide information concerning facts, phenomena, or even concepts. In other words, it is the basic information that is subjected to processing or interpretation to find meaning or generate products. Metada 6 min read What is the difference between DOM and BOM ? In this article, we will know about the Document Object Model (DOM) & Browser Object Model (BOM), along with understanding their basic implementation through the examples & the differences between them. Document Object Model (DOM) is a programming interface for HTML and XML documents, that a 5 min read Difference between id and class Attributes in HTML The id and class attributes in HTML are used for element identification and styling. The id attribute uniquely identifies a single element, while the class attribute can be applied to multiple elements. Both are essential for CSS styling and JavaScript manipulationâaround 90% of modern web pages rel 3 min read What is the difference between ng-app and data-ng-app in AngularJS ? In web application development, AngularJS is one of the most favorite dynamic JavaScript frameworks that has HTML through script tags, enabling us to augment the HTML attributes using the directives and facilitating the data binding through the expressions.In this article, we will see the concepts o 5 min read What's the difference between meta name and meta property? Meta Data: The metadata means information about data. So basically Meta tag provides you the information on the HTML document. So basically this tag is an empty tag which means it only has an opening tag and no closing tag. The number of meta tags in an HTML document depends upon the HTML document a 2 min read Like