element.setAttribute(name, value) is the standard method to add or modify an attribute on an HTML element. It takes two parameters: the name of the attribute and its value. If the attribute already exists, setAttribute() updates its value; if it doesn't exist, it creates a new attribute. This method works with both standard HTML attributes and custom data attributes.