DEV Community

Lawrence malachi
Lawrence malachi

Posted on

HTML Attributes and their use/function

HTML attributes are extra bits of info you add inside an HTML tag to change how that element behaves or looks.

Think of a tag like noun, and attributes as the adjective

  • instructions for it.

The most used HTML attributes and what they do

  1. Core/Global attributes
    Work on almost every element
    A. id="uniqueName": Gives the element a unique name. Used for CSS, JS, and linking. id must be unique on the page
    B. class="name1 name2": Groups element for styling with CSS or selecting with JS
    C. lang="en": Declares the language of the content

  2. Link & Media attributes
    A. href="url": Where a link should go
    B. src="image.jpg": Source file for , , <iframe>,<video><br> C. target=&quot;_blank&quot;: Opens a link in a new tab </p></li> <li><p>Form attributes<br> Used on <input>, <form>, <button>, etc<br> A. type=&quot;text/email/password&quot;: What kind of input it is.<br> B. name=&quot;username&quot;: The key name sent to server when form submits<br> C. value=&quot;default&quot;: Default value inside the input.</p></li> <li><p>Layout &amp; Behavior attributes<br> A. width=&quot;300&quot; height=&quot;200&quot;: Size for <img>, <video>, etc<br> B. hidden: Hides the element completely.<br> C. contenteditable=&quot;true&quot;: Makes the text editable in the browser.</p></li> </ol>

Top comments (0)